[R] passing parameters to an R script
Gabor Grothendieck
ggrothendieck at gmail.com
Sun Jan 4 14:32:42 CET 2009
On Sat, Jan 3, 2009 at 1:32 PM, <mauede at alice.it> wrote:
> I knowf R functions ca be called passing some parameters.
> My first question is: how are parameters passed to R functions ?
> Browsing through R archives I found an answer confirming taht parameters can
> be passed to the called function by value. I wonder whether passing the parameter
> address is possible somehow to allow the function to actually change its value.
Normally this is done by passing back the modified variable as
the return value:
> a <- 0
> fn <- function(x) x+1
> a <- fn(a)
> a
[1] 1
Another possibility is to use environments. In the following function fn
increments component x of environment e:
> e <- new.env()
> e$x <- 0
> fn <- function(e) e$x <- e$x + 1
> fn(e)
> e$x
[1] 1
You can use parent.frame() to refer to
the calling environment. ?parent.frame
It may be that e above is really best viewed
as an object in object oriented programming.
In that case the proto package implements
such a model in R and R.oo implements a
different oo model.
>
> My second question is about running R scripts with parameters. Something similar to the
> s/w device (argc, argv) which is used to run a C program with initial parameters.
> Is this possible at all ?
>
?commandArgs
> Thank you very much.
> Maura
>
>
>
> tutti i telefonini TIM!
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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