Invoke Python command from R script with System()

682 views Asked by At

In my R script I have to execute an external Python script and I'd use the System() function.

system("python -m premailer -f daily-report.html -o
ready-weekly-report.html")

But after running this in the R console this is what I get

enter image description here

/usr/bin/python: No module named premailer

If I run the python command from the terminal everything works.

EDIT

1

There are 1 answers

0
leonardofed On BEST ANSWER

This is how I fixed this.

Adding the following line to the end of that file, showed me the correct path in Rstudio after restarting my R kernel:

.Internal(Sys.setenv("PATH", paste("/usr/local/bin", Sys.getenv("PATH"), sep=":")))