Create and run an R script just like perl -e to script R in a shell such as bash?

I use perl -e to add Perl scripts to a shell script, such as bash, without creating a Perl script file.

perl -e ' while (<>) { print; }' < file 

Is there a similar way to do this for R? I want to write R scripts in a bash script, but without creating an R script file.

One way is to use

 R --vanilla <<RSCRIPT a <- "hello\n" cat(a) RSCRIPT 

Unlike perl -e, when using $, you must specify a backslash when referring to a table column. In perl -e, we do not need to use \ $ to refer to a perl variable.

+4
source share
1 answer

Yes there is. You can use Rscript :

 Rscript -e 'print("hello world")' 
+6
source

All Articles