Skip to content

thanks

6 messages · Cserháti Mátyás, Lefebure Tristan, Peter Dalgaard +2 more

#
Dear all,

Thanks to those 3 people who sent me answers to my question. Got 
the problem solved. Great!

Now, another question of mine is:

I would like to run an R script from the Linux prompt. Is there any way 
possible to do this? The reason is, the calculation that I'm doing takes a 
few hours, and I would like to automatize it.

Or does it mean that I have to run source within the R prompt?

Or is there a way to do the automatization within the R prompt?

Thanks, Matthew

u.i. K?szi, Zoli!
#
see man R

example from a shell:

echo -e "pdf(file=\"test.pdf\")\nplot(1:10,11:20)\ndev.off(dev.cur())\n">cmd.R
R -s <cmd.R

(write a file of command for R, and than feed R with it)
On Tuesday 11 January 2005 15:59, Cserh?ti M?ty?s wrote:

  
    
#
Cserh?ti M?ty?s <cs_matyi at freemail.hu> writes:
This could be what you are looking for:

R CMD BATCH myfile.R

or maybe

R --vanilla < myfile.R

both possibly followed by "&" to execute them in the background.
#
On Tue, Jan 11, 2005 at 03:59:58PM +0100, Cserh?ti M?ty?s wrote:

            
The standard way (well, my usual way, anyway) is to just use I/O
redirection:

    linux> R --vanilla < stuff.r

is, for the most part (see below), equivalent to

    linux> R
    > source("stuff.r");

The --vanilla option is necessary to suppress any interactive questions
concerning workspace saving (i.e. the "Save workspace image? [y/n/c]"
thing); differences between the automated and the interactive form may
be due to your script depending on some saved environment, or some
stuff in your init files.

I'd like to encourage you to automate your calculations, as this enhances
not only convenience but also reproducibility of your results.

Best regards, Jan
#
Cserh?ti M?ty?s wrote:

            
See
a) the manual "An Introduction to R", Appendix B
b) "inside" R type:  ?BATCH
c) "outside" R type: R CMD BATCH --help

Uwe Ligges
#
On Tue, Jan 11, 2005 at 04:24:11PM +0100, Lefebure Tristan wrote:

            
This may be on the verge of becoming offtopic, but let me remark
that the technique proposed here should be used for illustrative
purposes only. For real life, use pipes:

    echo 'print(mean(rnorm(10)));' | R --vanilla

This is equivalent to

    echo ''print(mean(rnorm(10)));' > cmd.R
    R --vanilla < cmd.R

*as long as only one shell is executing this sequence at any given time*.

The reason I mention this here is that I've seen it happen a few times
that this "temporary command file" approach has made it from examples
into shell scripts of which then, later on, multiple instances were
run at a time, resulting in very rare, very irreproducible, and most
inexplicable erroneous results.

Best regards, Jan