i think this question was already answered but just to elaborate,
pass by value means that a copy of the argument is passed to the
function so if the argument is changed in the function its not changed
in the caller.  Pass by reference means its changed in the caller too.
R passes by value although there are workarounds to pass by
reference.  In the following f uses pass by value and g pass by
reference.

> y <- 1
> f <- function(x) x<-x+1
> f(y)
> y
[1] 1

> g <- function(x) eval.parent(substitute(x <- x+1))
> g(y)
> y
[1] 2


On 11/6/05, Adaikalavan Ramasamy <[EMAIL PROTECTED]> wrote:
> I do not understand what your question is. Can you clarify with an
> example or analogies to other programming language.
>
>  my.fun <- function(x, y=1){ x^y }
>
>  my.fun(5)        # returns 5
>  my.fun(5, 2)     # returns 25
>  my.fun(y=2, x=5) # returns 25
>
> Regards, Adai
>
>
> On Sun, 2005-11-06 at 03:28 +0000, Xiaofan Li wrote:
> > Hello guys,
> >
> > I am wondering the default way of transferring arguments in R. Is it by
> > value or by ref in default case, or could that be changed explicitly?
> >
> > Cheers,
> > Xiaofan
> >
> > ---
> > Xiaofan Li
> > Department of Applied Mathematics and Theoretical Physics
> > University of Cambridge
> >
> > ______________________________________________
> > [email protected] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide! 
> > http://www.R-project.org/posting-guide.html
> >
> --
> Adaikalavan Ramasamy                    [EMAIL PROTECTED]
> Centre for Statistics in Medicine       http://www.ihs.ox.ac.uk/csm/
> Wolfson College Annexe                  Tel : 01865 284 408
> Linton Road, Oxford OX2 6UD             Fax : 01865 284 424
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to