Member-only story
Run Rscript from terminal
Usually when programming in R I use Rstudio as IDE.
But if you want to run an R script directly from the terminal because you need it for your workflow you can keep reading.
To run a MacOS terminal script you need to add it in your .zshrc this line
export PATH="/Library/Frameworks/R.framework/Versions/Current/Resources:$PATH"
First, check that the path is also correct for your computer and that the Rscript file is there.
After verifying and adding the correct path in the .zshrc file do:
source .zshrc
Now, if you write Rscript followed by the name of the R script it will be executed in the terminal.
For example, if you want to run an R script from a Python script, you can do this:
subprocess.run('source ~/.zshrc; Rscript --vanilla ../Bayesian/script_for_gui.r query_row.csv result.csv', shell=True)
If you have any problems or if you have solved them in any other way do not hesitate to write them in the comments!
To get access to unlimited stories, you can also consider signing up to become a Medium member for just $5. If you sign up using my link, I’ll receive a small commission.