使用正确的序列化器很重要:
# If the URL gets called the browser will automatically download the file.
#' @serializer contentType list(type="application/octet-stream")
#' @get /rds
rest_rds = function() {
tfile = tempfile()
saveRDS(iris, file = tfile)
readBin(tfile, "raw", n = file.info(tfile)$size)
}
Run Code Online (Sandbox Code Playgroud)
提供此管道工脚本后,您可以下载此对象并将其导入到单独的 R 会话中,如下所示:
tfile = tempfile()
download.file("http://127.0.0.1:7983/rds", destfile = tfile)
d_iris = readRDS(tfile)
Run Code Online (Sandbox Code Playgroud)