Calling R Script from python in AWS lambda

只谈情不闲聊 提交于 2019-11-28 13:01:15

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]

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)

Cheers

There are a lot more steps to running R in Lambda compared to just using rpy2 locally, namely that you need to load all the C libraries R requires before trying to import rpy2. This article http://jaehyeon-kim.github.io/2017/04/Serverless-Data-Product-POC-Backend-Part-I.html does a great job of walking you through all the steps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!