My question seems very basic but I don't find an answer even on rpy2 documentation. I have *.R script that accept one argument as "file.txt" (I need to pass the argument not from the command line). I want to call the R script inside a python script . My questions is: How to pass and recuperate the arguments to the R script ? My solution is : suppose that the R script is start by this line:
df <- read.table(args[1], header=FALSE)
"
here args[1] should be the file which is not passed from the command line
"
....
Now I write a function in my python script:
from rpy2 import robjects as ro
def run_R(file):
r = ro.r
r.source("myR_script.R")
# how to pass the file argument to
# the R script and how to
# recuperate this argument in the R code?