HenrikBengtsson / startup

:wrench: R package: startup - Friendly R Startup Configuration
https://henrikbengtsson.github.io/startup/
160 stars 5 forks source link

How to detect Rscript? #97

Open HenrikBengtsson opened 3 years ago

HenrikBengtsson commented 3 years ago

Is it possible to infer whether R was launched via Rscript?

commandArgs()[1] does not convey this information. On Linux:

$ Rscript --vanilla -e "commandArgs()"
[1] "/home/hb/shared/software/CBI/R-4.0.4/lib/R/bin/exec/R"
[2] "--no-echo"                                            
[3] "--no-restore"                                         
[4] "--vanilla"                                            
[5] "-e"                                                   
[6] "commandArgs()"

On MS Windows:

C:\Users\hb>Rscript --vanilla -e "commandArgs()"
[1] "C:\\Program Files\\R\\R-4.0.3\\bin\\x64\\Rterm.exe"
[2] "--no-echo"
[3] "--no-restore"
[4] "--vanilla"
[5] "-e"
[6] "commandArgs()"