简体   繁体   中英

Calling a python function from R with passing the arguments

Is there any package for calling a python function from R by passing the function arguments through R? Now i have directly called the python file using system in R.

a<-system('/home/anaconda3/bin/python  /home/Desktop/myfile.py' ,intern = TRUE)

But this myfile.py file is having a function with paramenter. How to specify the parameter in R?

I have tried system('/home/anaconda3/bin/python /home/Desktop/myfile.py argument',wait=FALSE,intern = TRUE) .But it returns 0.

please look at reticulate

library(reticulate)
os <- import("os")
os$listdir(".")

for example I want to pass the number of core that my python script can use:

system(paste('/home/anaconda3/bin/python','home/Desktop/myfile.py',NCORE))

Then in Python Script before launch the function I can read my parameter in this way:

n_core = int(sys.argv[1])

sys.argv is a list in Python, which contains the command-line arguments passed to the script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM