Jakub Štěch
Jakub Štěch

Reputation: 25

Plumber R package - post request not working

I try to make post request with plumber package.

library(jsonlite)
#* @post /sum
addTwo <- function(a, b){
  x <- as.numeric(a) + as.numeric(b)
  return(x)
}

And then I write

library("plumber") r <- plumb("C:/.../post.R")

but then the error comes up:

Warning message: In readLines(file) : incomplete final line found on 'C:/.../post.R'

Upvotes: 2

Views: 903

Answers (1)

Jeff Allen
Jeff Allen

Reputation: 17517

That's just a warning that says that you don't have a trailing newline in your post.R file. You can ignore it or add an empty line at the end of the file to make it go away.

The actual problem is that you're not ever running the API, only defining it.

# Load Plumber
library("plumber") 

# define the plumber router in the variable r
r <- plumb("C:/.../post.R")

# Run r on port 8000
r$run(port=8000)

Upvotes: 1

Related Questions