[R] Start R from bash/bat file and end in interactive mode

Frank Schwidom schwidom at gmx.net
Sun Apr 7 11:45:09 CEST 2013


one way could be:

$ cat rook.R | R --interactive

but with a little different console behaviour

the problem in your other examples is, that
R uses only the first appearing switch of:

--interactive, --f, -e, --vanilla, --no-save, ...

the switches cannot be combined

On Thu, Nov 01, 2012 at 09:14:09AM +0100, Jan van der Laan wrote:
> 
> I have a r-script (rook.R) that starts a Rook server. To present users  
> from having to start R and type in source("rook.R"), I want to create  
> a bash script and bat file that starts R and sources the script.  
> However, to keep the Rook server running R should not close after  
> running the script and stay in interactive mode. This proves more  
> difficult than expected.
> 
> I tried various combinations of commandline parameters and pipes, but  
> none of them seem to work:
> 
> $R -f rook.R --interactive
> Runs and quits
> 
> $ cat rook.R | R
> Fatal error: you must specify '--save', '--no-save' or '--vanilla'
> 
> $cat rook.R | R --no-save
> Runs and quits
> 
> $R --no-save < rook.R
> Runs and quits
> 
> $R --no-save --interactive < rook.R
> Runs and quits
> 
> I would have expected the --interactive parameter to do what I want,  
> but it doesn't seem to do anything.
> 
> What does work is to create a .Rprofile with sourc("rook.R") in it in  
> the directory and then start R (just plain R). However I don't find  
> this a very elegant solution. I could of create the .Rprofile file in  
> the bash script which is somewhat better, but still not very elegant.  
> I end up with the following bash script:
> 
> #!/bin/bash
> echo "source(\"rook.R\")" > .Rprofile
> R
> 
> Another, not very elegant, possible solution which I haven't tried is  
> to start a while loop at the end of the script with a sleep command in  
> it.
> 
> Does there exist a better solution?
> 
> Regards,
> 
> Jan
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list