Rpy2 import external R file

三世轮回 提交于 2019-12-07 10:54:06

问题


I have a R script in a .R file that I would like to execute. How can I load it?

I'd like to source("/path/to/file.R") within the python code, but with this name!


回答1:


Simply import R's source function like any other!

import rpy2.robjects as robjects
r_source = robjects.r['source']
r_source("path/to/file.R")



回答2:


I use a trick to have both R code and Python script in my editor, you can have a look at this example https://stackoverflow.com/a/55900840/5350311 , I hope it is useful for you.



来源:https://stackoverflow.com/questions/19567081/rpy2-import-external-r-file

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