[R] reserved words documentation
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Wed Mar 5 23:32:55 CET 2003
Robin Hankin <r.hankin at auckland.ac.nz> writes:
> Come to think of it, the only place I could find
> documentation for "..." was in Notes on R.
>
> Where is the best place to look for docs on "..1" ?
In the source code, I suppose. It's extremely obscure and all you
really need to know is that the ..n names are to be avoided.
If you insist, consider this
> g <- function(...) cat(..1,"/",..10,"\n")
> g(4)
Error in cat(..1, "/", ..10, "\n") : The ... list does not contain 10
> elements
> g(1,2,3,4,5,6,7,8,9,0)
1 / 0
I've only seen uses for this while debugging some really weird
constructions which I have long since forgotten.
One strange aspect is that these really are reserved words, not just
identifiers; you can't do stuff like this:
> g <- function(...) for (i in seq(length=nargs()))
cat(get(paste("..",i,sep="")),"/")
> g(1,2,3,4,5,6,7,8,9,x)
Error in get(x, envir, mode, inherits) : variable "..1" was not found
But you can do that anyway, and neater, with
g <- function(...) for (i in seq(length=nargs())) cat(list(...)[[i]],"/"),x)
(The obscure bug seems to have been #813 which I recall trying to fix
an evening during DSC 2001... That particular behaviour has been
stamped out, but I suppose a sufficiently weird combination of
match.call(), substitute(), multiple levels of "..." matching, and
eval() could still cause "..1" to appear in an expression)
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list