在AWS Lambda中从python调用R脚本 [英] Calling R Script from python in AWS lambda

查看:108
本文介绍了在AWS Lambda中从python调用R脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道python中有一个名为rpy2的软件包,用于集成R和python.

I know there is a package called rpy2 in python in order to integrate R and python.

使用rpy2从python调用R脚本,在此链接中他们描述过正常.

Calling R script from python using rpy2, in this link they have described to do normally.

但是,为了在AWS Lambda中执行相同的操作,在此链接中,我们应该提供的路径应该是文件夹"而不是名称.

But in order do the same in AWS lambda, what should be the path that we can give instead of the name "folder" in this link.

推荐答案

我使用非常简单的方法通过rpy2在python和R之间进行交换,这是一个示例,其中我将R脚本编写为字符串,然后使用rpy2进行翻译R并返回,

I am using very simple methode for interachanging between python and R by using rpy2, here is one example where I write R script as string and then use rpy2 to translate it for R and return it back,

   path="H:/projects/somepackage/CODE"
   from rpy2.robjects.packages import SignatureTranslatedAnonymousPackage
   string = """
   setwd <- function(x) {
   setwd("%s")
   return (getwd())}
   """ % (path)
   print (string)
   powerpack = SignatureTranslatedAnonymousPackage(string, "powerpack")
   #The R functions setwd can be  called with powerpack.setwd () as
   powerpack.setwd()[0]

我不确定它是否对您有用,但是如果您设法将代码传输到AWS,则肯定会得到结果……您也可以尝试将字符串另存为文件,然后询问Python将其编译为外部函数(我以前没有rpy2曾经这样做)

I am not sure if it might be useful in your case but if you somehow manage to transfer your code to AWS you will definitely get the results... You can also try to save the string as a file, then ask Python to compile it as external function(I used to do so in the past without rpy2)

欢呼

这篇关于在AWS Lambda中从python调用R脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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