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?
I think what you're looking for is batch mode. You can do that, like this:
You can read more about batch mode here.
This works for me in Cygwin on Windows:
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
or use
for littler -- I have multiple cron jobs doing just that.
This obviously assumes that you'd have
Rscript
orr
in/usr/bin
as you would e.g. on a regular Debian or Ubuntu box.Start R with the command
R
and then just add youre code