[R] Command line arguments with source() - Windows OS

Gavin Simpson gavin.simpson at ucl.ac.uk
Mon Nov 17 17:31:37 CET 2008


On Mon, 2008-11-17 at 15:12 +0100, Wacek Kusnierczyk wrote:
> Duncan Murdoch wrote:
> >
> > paramValue <- 15
> > source("myRfile.R")
> >
> > The quotes are necessary, because source(myRfile.R) would go looking
> > for a variable named myRfile.R, rather than using "myRfile.R" as the
> > filename.
> 
> why?

Because that is how it is written and how R functions in general work;
they evaluate their arguments in the relevant environment. Are you
trying to be obtuse?

source(foo)

is useful as you might have stored the name of the file to source in foo
or built it up from other components via paste() and stored that in foo
to keep the call to source clean. source() accommodates that usage.

[gavin at prometheus ~]$ touch tmp.R
[gavin at prometheus ~]$ echo "bar <- rnorm(100)" > tmp.R
[gavin at prometheus ~]$ cat tmp.R
bar <- rnorm(100)
[gavin at prometheus ~]$ R

R version 2.7.1 RC (2008-06-16 r45948)
....
Type 'q()' to quit R.

> foo <- "tmp.R"
> source(foo)
> ls()
[1] "bar" "foo"

If you have something useful to say about source() and how it implements
it's behaviour then how about coming up with something constructive then
post it on R-Devel; the appropriate place for discussions about
developing R.

Or are you just trolling?

G

> 
> vQ
> 
> ______________________________________________
> 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.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list