How to run R codes inside shell script?
r, sh, shell
Solution
The idea is to not write a shell but to write an R script. That is what `Rscript` is for, and our littler package offered `/usr/bin/r` even before that.
So just do
#!/usr/bin/Rscript
cat("Hello, world\n")
# rest of your code below
or use
#!/usr/bin/r
for littler -- I have multiple cron jobs doing just that.
This obviously assumes that you'd have `Rscript` or `r` in `/usr/bin` as you would e.g. on a regular Debian or Ubuntu box.
Problem
I have a R file ( myfile.R). I want to run it using a shell script. How Can I do that? I tried this: ``` #! /bin/bash Rscript myfile.R ``` but it gives me this error: Rscript: command not found I also tried this: ``` #! /bin/bash R --not-save-- < myfile.R ``` It also gives this error: R : command not found What is the best way to do that?