1

I want to launch Rcmdr as a command from bash (or any unix shell), perhaps as an alias. R accepts the CMD argument and I could also pipe a script in with <. I would like the R console to stay open, and an interactive RCommander session to be started (Rcmdr is a popular GUI for R, for any newbies reading along, and it seems that you start up R, type library(Rcmdr) and then Commander() to start it up).

I am aware of how to add Rcmdr to my profile, and it appears to always start up if I include library(Rcmdr) in my .Rprofile, on my Linux workstation.

If I pipe my input in with < then this script works up to the point where it says that Commander GUI is launched only in interactive sessions:

library(Rcmdr);
Commander();

However if I run R CMD BATCH ./rcommander.r it just starts up and shuts down immediately, probably giving me some warning about interactive sessions that I didn't see, because CMD BATCH puts R into non-interactive mode and is thus useless for the purpose of "injecting" Rcmdr into an interactive R session.

It appears impossible to "source a file on the command line but run interactively" in R. It also appears that there are command line options to ignore the global and the user profile, but not to specify a custom profile like R --profile-custom ./.Rprofile2

Either I would like to specify a profile that means "Right now I want to start up and use RCmdr" and still be able to run R without it sometimes.

Pere
  • 706
  • 1
  • 7
  • 21
Warren P
  • 65,725
  • 40
  • 181
  • 316
  • related: http://stackoverflow.com/questions/10602900/running-r-scripts-or-commands-with-interpretor-in-unix-for-unix-layman – Warren P Feb 02 '16 at 20:31
  • also related: http://stackoverflow.com/questions/8737046/switch-r-script-from-non-interactive-to-interactive – Warren P Feb 02 '16 at 20:34
  • I don't understand why the warning message is unclear. BATCH mode is not interactive. – IRTFM Feb 02 '16 at 20:49
  • R is bizarre. I don't want to use batch mode but it's the only way to specify an R command from the R command line, which is strange. – Warren P Feb 02 '16 at 20:50
  • Generally people write a small .R file and then launch it from a particular directory which then becomes the working directory. The system then takes care of launching an interactive R session with the included commands being executed after the .Rprofile and Rprofile.site get executed. See `?Startup`. – IRTFM Feb 02 '16 at 20:54
  • Oh I see. They use "workspaces" like java people do. – Warren P Feb 02 '16 at 21:02
  • http://www.statmethods.net/interface/customizing.html – Warren P Feb 02 '16 at 21:08

1 Answers1

1

Working on an Ubuntu machine here, I was able to use the advice provided by Dirk in this mailing list post:

nathan@nathan-laptop:~/tmp$ cat rcommander.r 
#!/bin/bash 
r -lRcmdr -e'while(TRUE) Commander();'  


nathan@nathan-laptop:~/tmp$ cat rcommander2.r 
#!/bin/bash 
Rscript --default-packages=Rcmdr -e 'while(TRUE) Commander();'

The first script uses Dirk's littler package, available on CRAN, and the second uses the standard Rscript executable. As noted, you can kill the process with ctrl + c from your terminal.

nrussell
  • 18,382
  • 4
  • 47
  • 60
  • If you run this with normal `R` like `R -e 'library("Rcmdr"); while(TRUE) Commander();'` it will spam infinitely new windows of R Commander ._. – Sigma Octantis Sep 29 '17 at 08:42