Rpy2 import external R file

2019-05-18 17:00发布

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!

标签: python r rpy2
2条回答
贪生不怕死
2楼-- · 2019-05-18 17:28

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")
查看更多
爷、活的狠高调
3楼-- · 2019-05-18 17:45

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.

查看更多
登录 后发表回答