【问题标题】:Plumber R package - post request not working水管工 R 包 - 发布请求不起作用
【发布时间】:2017-11-03 22:47:15
【问题描述】:

我尝试使用水管工包进行发布请求。

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

然后我写

library("plumber") r &lt;- plumb("C:/.../post.R")

但随后出现错误:

警告消息:在 readLines(file) 中:不完整的最后一行在 'C:/.../post.R'

【问题讨论】:

    标签: r post plumber


    【解决方案1】:

    这只是一个警告,表示您的 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 2019-01-27
      • 2017-01-28
      相关资源
      最近更新 更多