我使用管道工作为一些 R 函数的简单 web-api 服务。
我想通过 R 函数提供一个文件“下载”(在客户端),非常像 flask is doing it in python through send_file and send_from_directory .
我试过
#* @get /datafile
get_file <- function(){
return(file('path-to-file.RData'))
}
但不幸的是它不起作用(因为返回值无法转换为 JSON)。我知道 static file server option in plubmer ,但我真的只想提供一个文件而不是目录。 (尽管通过
@assets
提供目录中的文件似乎是一个更安全的选择。)
最佳答案
抱歉,这没有更好的记录,但请在此处查看一些示例:https://github.com/trestletech/plumber/blob/master/tests/testthat/files/includes.R
我不记得我是否测试过二进制数据或者它如何处理 Rdata 内容类型,所以如果事情仍然很奇怪 please open a ticket .
关于r - 通过 API 调用获取文件(R & 管道工),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44185675/