2017-11-03 62 views
0

我尝试使用水管工包进行发布请求。水管工R pakcage - 发布请求不起作用

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

然后我写

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

但随后的错误出现:

警告消息:在readlines方法(文件):不完全的最后行 “C发现:/.../ post.R'

回答

0

这只是一个警告,说你的post.R文件中没有尾随换行符。您可以忽略它或在文件末尾添加一个空行以使其消失。

实际的问题是,你没有运行API,只能定义它。

# 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)