如何将大量数据传递给 R 中的 Plumber
How to pass a lot of data to Plumber in R
我想通过制作一个需要 14 天的历史数据和 returns 指数平滑预测的应用来使用 plumber
库。
问题是我不太熟悉将大量数据(具有多个值的参数)传递给 API。我的问题可以总结如下:
我应该如何准备 R 中的数据以传递给 API?
plumber
中的API应该如何准备接收时序数据?
下面是一些示例数据和一个函数,可以在 R 中实现我想要的功能。
library(tidyverse)
# data to be passed to API
head(forecast::wineind,14)
#> Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov
#> 1980 15136 16733 20016 17708 18019 19227 22893 23739 21133 22591 26786
#> 1981 15028 17977
#> Dec
#> 1980 29740
#> 1981
#* Return Forecast Data
#* @list a The first number
#* @get /simple_fcast
function(){
ts() %>%
forecast::ets() %>%
forecast::forecast()
}
#> function(){
#> ts() %>%
#> forecast::ets() %>%
#> forecast::forecast()
#> }
由 reprex package (v0.2.1)
创建于 2018-11-14
答案是根据此处的文档使用 "message body" https://www.rplumber.io/docs/routing-and-input.html#
#' @post /user
function(req, id, name){
list(
id = id,
name = name,
raw = req$postBody
)
}
运行 curl --data "id=123&name=Jennifer" "http://localhost:8000/user"
将 return:
{
"id": [123],
"name": ["Jennifer"],
"raw": ["id=123&name=Jennifer"]
}
我发现数组也可以传递给函数。
我想通过制作一个需要 14 天的历史数据和 returns 指数平滑预测的应用来使用 plumber
库。
问题是我不太熟悉将大量数据(具有多个值的参数)传递给 API。我的问题可以总结如下:
我应该如何准备 R 中的数据以传递给 API?
plumber
中的API应该如何准备接收时序数据?
下面是一些示例数据和一个函数,可以在 R 中实现我想要的功能。
library(tidyverse)
# data to be passed to API
head(forecast::wineind,14)
#> Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov
#> 1980 15136 16733 20016 17708 18019 19227 22893 23739 21133 22591 26786
#> 1981 15028 17977
#> Dec
#> 1980 29740
#> 1981
#* Return Forecast Data
#* @list a The first number
#* @get /simple_fcast
function(){
ts() %>%
forecast::ets() %>%
forecast::forecast()
}
#> function(){
#> ts() %>%
#> forecast::ets() %>%
#> forecast::forecast()
#> }
由 reprex package (v0.2.1)
创建于 2018-11-14答案是根据此处的文档使用 "message body" https://www.rplumber.io/docs/routing-and-input.html#
#' @post /user
function(req, id, name){
list(
id = id,
name = name,
raw = req$postBody
)
}
运行 curl --data "id=123&name=Jennifer" "http://localhost:8000/user"
将 return:
{
"id": [123],
"name": ["Jennifer"],
"raw": ["id=123&name=Jennifer"]
}
我发现数组也可以传递给函数。