[R] Use of argument '...'
Peter Dalgaard
P.Dalgaard at biostat.ku.dk
Tue Apr 17 11:38:17 CEST 2007
Juan Lewinger wrote:
> Dear R list,
>
> I've read the function writing sections on both "An introduction to R" and "R language Definition" manuals but still don't understand why the following gives an error message:
>
> fun <- function(x, ...) x + y
> fun(1, y=2)
>
> I get:
>
> Error in fun(1, y = 2) : object "y" not found
>
> I'd appreciate any help in understanding this.
>
Putting it a bit sharply: The triple-dot mechanism is not a carte
blanche to introduce arbitrary variables into a function body. If it
did, then you could (intentionally or not) modify the behaviour of
functions in weird and mysterious ways.
As "y" is not among the formal argument names for "fun", it will not be
found inside "...", to find it in there, you need to be more explicit,
as in x+list(...)$y.
> R version 2.4.1 (2006-12-18)
> i386-pc-mingw32
> ...
>
> Juan Pablo Lewinger
> Department of Preventive Medicine
> Keck School of Medicine
> University of Southern California
> 1540 Alcazar Street, CHP-220
> Los Angeles, CA 90089-9011, USA
>
> ______________________________________________
> R-help at 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.
>
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list