[R] Passing aruments with source

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Sep 8 12:00:59 CEST 2010


On Wed, Sep 8, 2010 at 10:11 AM, Joel <joda2457 at student.uu.se> wrote:
>
> Hi.
>
> Im writing a small test program just to see how passing arguments work with
> R.
> >From the command line everything works as expected but from inside R using
> source("test.R") i dont know where and how to send in the arguments did try
> source("test.R --test") but it just says that it cant find or open the file.
> (without the argument part it can).
>
> Anyone know how to make it work?

 source() runs the file in the context of the caller, so if you have
an 'x' in the caller then the file sourced will see it. So here, where
s.R is just:

print(x)

 you can do:

> x=12
> source("s.R")
[1] 12
> x=99
> source("s.R")
[1] 99

Barry



More information about the R-help mailing list