[Rd] Problem with {
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Jul 9 20:58:11 CEST 2007
Just one additional observation. { does work with mapply:
> f <- function(x, y) y
> mapply(f, letters, 1:26)
a b c d e f g h i j k l m n o p q r s t u v w x y z
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
> mapply("{", letters, 1:26) # same
a b c d e f g h i j k l m n o p q r s t u v w x y z
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
On 7/9/07, Peter Dalgaard <P.Dalgaard at biostat.ku.dk> wrote:
> Gabor Grothendieck wrote:
> > Why does the error get generated here? Is it a bug? It seems that
> > f and "{" are the same but when used in sapply f works but { does not.
> > Is its use in lapply really "an incorrect context"?
> >
> >
> >> f <- function(x, y) y
> >> f(1, 2)
> >>
> > [1] 2
> >
> >> "{"(1, 2)
> >>
> > [1] 2
> >
> >> lapply("y", function(x, y) y, 1:4) # ok
> >>
> > [[1]]
> > [1] 1 2 3 4
> >
> >> lapply("y", "{", 1:4) # error
> >>
> > Error in lapply("y", "{", 1:4) : '...' used in an incorrect context
> >
> lapply() is not really part of the problem:
>
> > (function(x,...) "{"(x,...))(1,2)
> Error in (function(x, ...) { : '...' used in an incorrect context
>
> Not sure exactly why this is so, but "{" has somewhat nonstandard
> evaluation semantics and you cannot do
> "{x, ...}" either, nor for that matter x <- function(...)...; x(2),
> which gives off a similar error.
>
>
> >> R.version.string # XP
> >>
> > [1] "R version 2.5.1 (2007-06-27)"
> >
> > See:
> >
> > https://www.stat.math.ethz.ch/pipermail/r-help/2007-July/135999.html
> >
> > for a variation of the lapply using sapply (which also has the same
> > problem if one uses { instead of f).
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
>
> --
> 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-devel
mailing list