Re: [R] How to start R with a file loaded?

From: Oleg Sklyar <magepost_at_googlemail.com>
Date: Wed 25 Oct 2006 - 12:34:41 GMT

Assume you want to execute code in 'mycode.R', the easiest way is:

echo "source('mycode.R')" | R --vanilla --quiet

If you do it in a shell script, you can also pass variables to your code like this (list of shell script):

#!/bin/sh
echo "var1=${1};var2=${2};source('mycode.R')" | R --vanilla -- quiet

Good luck,
Oleg

On 24/10/06, Grateful Frog <gratefulfrog@gmail.com> wrote:
>
> Hi!
>
> I've made great progress in my R programming, but I am again stuck on a
> beginner's problem.
>
> I would like to start R with a command line that loads a file, and if
> possible, executes a function.
>
> Can anyone give me an example of how to do this?
>
> For example, in lisp, I would say:
>
> $ lisp -load toto.lisp -eval '(do-something $PORT)'
>
> to load the file "toto.lisp", then evaluate the expression with the shell
> envt variable bound properly.
>
> I'd like to do this in R, but can't figure it out!
>
> Thanks,
> GF.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch 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. Received on Wed Oct 25 22:41:21 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 25 Oct 2006 - 13:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.