我可以将我的 R 输出 (.jpeg) 保存到 FTP 服务器吗? [英] Can I save my R output (.jpeg) to an FTP server?

查看:34
本文介绍了我可以将我的 R 输出 (.jpeg) 保存到 FTP 服务器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(可选阅读) 更大的目标:PowerBI Web

具体目标*:以下代码说明了一种在本地保存 R 输出 (.jpeg) 图像的简单方法.但是,如果我有用户名/密码等,有没有办法将图像直接保存到 FTP 服务器?(很遗憾,我无法分享服务器详细信息)

库(爆发)图书馆(发生)案例=子集(nipa​​h_malaysia,选择= c(霹雳州",negeri_sembilan",雪兰莪",新加坡"))i = as.incidence(案例,日期 = nipah_malaysia$date,间隔 = 7L)jpeg(文件=plot.jpeg")情节(一)dev.off()

我确实遇到过这个发布 使用 rcurl" 包中的 ftpUpload 函数.但是,要将其上传到 FTP,我可能仍需要将其保存在本地,这违背了我在此用例中的目的.

任何建议都会有所帮助.

解决方案

如果可以选择保存临时文件(如您在评论中建议的那样),那么您可以使用以下代码:

库(爆发)图书馆(发生)库(RCurl)案例=子集(nipa​​h_malaysia,选择= c(霹雳州",negeri_sembilan",雪兰莪",新加坡"))i = as.incidence(案例,日期 = nipah_malaysia$date,间隔 = 7L)jpeg(文件 = 文件名 <- tempfile())情节(一)dev.off()ftpUpload(文件名, "ftp://User:Password@FTPServer/destfile.jpeg")

(optional read) Greater Objective: PowerBI Web doesn't support a few R packages when published on the internet. It throws the below error ("Missing R Package"). Hence, I am working towards saving the output from R as an image (.jpeg) to a remote location (such as FTP) or cloud storage (secure and open source) and then import it to PowerBI. This workaround might resolve the package conflict (hoping).

Specific Objective*: The below code illustrates a trivial way of saving an R output(.jpeg) image locally. However, is there a way to save the image directly to the FTP server, provided I have the username/password etc? (unfortunately, I cannot share the server details)

library(outbreaks)
library(incidence)

cases = subset(nipah_malaysia, select = c("perak", "negeri_sembilan", "selangor",
                                           "singapore"))

i = as.incidence(cases, dates = nipah_malaysia$date, interval = 7L)
jpeg(file = "plot.jpeg")
plot(i)
dev.off()

I did come across this post on employing ftpUpload function from the "rcurl" package. However, to upload it to FTP, I might still need to save it locally which defeats my purpose in this use-case.

Any suggestions would be helpful.

解决方案

If saving a temporary file (as you suggested in a comment) is an option, then you can do that with the following code:

library(outbreaks)
library(incidence)
library(RCurl)

cases = subset(nipah_malaysia, select = c("perak", "negeri_sembilan", "selangor",
                                           "singapore"))

i = as.incidence(cases, dates = nipah_malaysia$date, interval = 7L)
jpeg(file = filename <- tempfile())
plot(i)
dev.off()
ftpUpload(filename, "ftp://User:Password@FTPServer/destfile.jpeg")

这篇关于我可以将我的 R 输出 (.jpeg) 保存到 FTP 服务器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆