This seems like a bug to me. Can someone verify this? First we define a function f that returns its second argument and lapply it to 1:2 using 9 as the second argument and all seems well. Note that "{" as a function does the same thing as f, as illustrated with f(1,9) and "{"(1,9); however, when we attempt to use "{" in the very same way we used f in lapply, we get an error message about ... being used in an incorrect context, as shown. I am using R on windows with the version shown at the end. R> f <- function(x,y)y R> f(1,9) [1] 9 R> lapply(1:2, f, 9) [[1]] [1] 9 [[2]] [1] 9 R> "{"(1,9) [1] 9 R> lapply(1:2, "{", 9) Error in lapply(1:2, "{", 9) : ... used in an incorrect context R> R.version.string [1] "R version 1.9.1, 2004-08-03"
Hi, > "{" <- function(x,y)y > "{"(1,9) [1] 9 > lapply(1:2, "{", 9) [[1]] [1] 9 [[2]] [1] 9 > R.version.string [1] "R version 2.0.0, 2004-09-20" /E Gabor Grothendieck wrote:>This seems like a bug to me. Can someone verify this? > >First we define a function f that returns its second argument and >lapply it to 1:2 using 9 as the second argument and all seems well. > >Note that "{" as a function does the same thing as f, as illustrated >with f(1,9) and "{"(1,9); however, when we attempt to use "{" in the >very same way we used f in lapply, we get an error message about ... >being used in an incorrect context, as shown. > >I am using R on windows with the version shown at the end. > > >R> f <- function(x,y)y >R> f(1,9) >[1] 9 >R> lapply(1:2, f, 9) >[[1]] >[1] 9 > >[[2]] >[1] 9 > >R> "{"(1,9) >[1] 9 >R> lapply(1:2, "{", 9) >Error in lapply(1:2, "{", 9) : ... used in an incorrect context > >R> R.version.string >[1] "R version 1.9.1, 2004-08-03" > >______________________________________________ >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 > > >-- Dipl. bio-chem. Witold Eryk Wolski MPI-Moleculare Genetic Ihnestrasse 63-73 14195 Berlin _ tel: 0049-30-83875219 'v' http://www.molgen.mpg.de/~wolski / \ mail: witek96 at users.sourceforge.net ---W-W---- wolski at molgen.mpg.de
Thanks for pointing out that this is already fixed in the upcoming version of R. Witold Eryk Wolski <wolski <at> molgen.mpg.de> writes: : : Hi, : : > "{" <- function(x,y)y : > "{"(1,9) : [1] 9 : > lapply(1:2, "{", 9) : [[1]] : [1] 9 : : [[2]] : [1] 9 : : > R.version.string : [1] "R version 2.0.0, 2004-09-20" : : /E : : Gabor Grothendieck wrote: : : >This seems like a bug to me. Can someone verify this? : > : >First we define a function f that returns its second argument and : >lapply it to 1:2 using 9 as the second argument and all seems well. : > : >Note that "{" as a function does the same thing as f, as illustrated : >with f(1,9) and "{"(1,9); however, when we attempt to use "{" in the : >very same way we used f in lapply, we get an error message about ... : >being used in an incorrect context, as shown. : > : >I am using R on windows with the version shown at the end. : > : > : >R> f <- function(x,y)y : >R> f(1,9) : >[1] 9 : >R> lapply(1:2, f, 9) : >[[1]] : >[1] 9 : > : >[[2]] : >[1] 9 : > : >R> "{"(1,9) : >[1] 9 : >R> lapply(1:2, "{", 9) : >Error in lapply(1:2, "{", 9) : ... used in an incorrect context : > : >R> R.version.string : >[1] "R version 1.9.1, 2004-08-03" : > : >______________________________________________ : >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 : > : > : > :
But (it seems like) "{" as a primitive function can take arbitrary number of argument, and return the last argument. So Gabor's usage seems right, yet somehow within lapply() "{" doesn't like the way it's being called. Also, be very careful:> "{" <- function(x, y) y > f <- function(a, b) { exp(a+b); a+b; a-b } > f(1, 2)Error in { : unused argument(s) ( ...)> f <- function(a, b) { exp(a+b); a+b } > f(1, 2)[1] 3> f <- function(a, b) { exp(a+b) } > f(1, 2)Error in { : Argument "y" is missing, with no default Andy> From: Witold > > Hi, > > > "{" <- function(x,y)y > > "{"(1,9) > [1] 9 > > lapply(1:2, "{", 9) > [[1]] > [1] 9 > > [[2]] > [1] 9 > > > R.version.string > [1] "R version 2.0.0, 2004-09-20" > > > /E > > Gabor Grothendieck wrote: > > >This seems like a bug to me. Can someone verify this? > > > >First we define a function f that returns its second argument and > >lapply it to 1:2 using 9 as the second argument and all seems well. > > > >Note that "{" as a function does the same thing as f, as illustrated > >with f(1,9) and "{"(1,9); however, when we attempt to use "{" in the > >very same way we used f in lapply, we get an error message about ... > >being used in an incorrect context, as shown. > > > >I am using R on windows with the version shown at the end. > > > > > >R> f <- function(x,y)y > >R> f(1,9) > >[1] 9 > >R> lapply(1:2, f, 9) > >[[1]] > >[1] 9 > > > >[[2]] > >[1] 9 > > > >R> "{"(1,9) > >[1] 9 > >R> lapply(1:2, "{", 9) > >Error in lapply(1:2, "{", 9) : ... used in an incorrect context > > > >R> R.version.string > >[1] "R version 1.9.1, 2004-08-03" > > > >______________________________________________ > >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 > > > > > > > > > -- > > Dipl. bio-chem. Witold Eryk Wolski > MPI-Moleculare Genetic > Ihnestrasse 63-73 14195 Berlin _ > tel: 0049-30-83875219 'v' > http://www.molgen.mpg.de/~wolski / \ > mail: witek96 at users.sourceforge.net ---W-W---- > wolski at molgen.mpg.de > > ______________________________________________ > 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 > >
> From: Gabor Grothendieck > > Thanks for pointing out that this is already fixed in the upcoming > version of R.It's not. I was using R-2.0.0beta from 2004-09-24, and it's still that way. Andy> Witold Eryk Wolski <wolski <at> molgen.mpg.de> writes: > > : > : Hi, > : > : > "{" <- function(x,y)y > : > "{"(1,9) > : [1] 9 > : > lapply(1:2, "{", 9) > : [[1]] > : [1] 9 > : > : [[2]] > : [1] 9 > : > : > R.version.string > : [1] "R version 2.0.0, 2004-09-20" > : > : /E > : > : Gabor Grothendieck wrote: > : > : >This seems like a bug to me. Can someone verify this? > : > > : >First we define a function f that returns its second argument and > : >lapply it to 1:2 using 9 as the second argument and all seems well. > : > > : >Note that "{" as a function does the same thing as f, as > illustrated > : >with f(1,9) and "{"(1,9); however, when we attempt to use > "{" in the > : >very same way we used f in lapply, we get an error message > about ... > : >being used in an incorrect context, as shown. > : > > : >I am using R on windows with the version shown at the end. > : > > : > > : >R> f <- function(x,y)y > : >R> f(1,9) > : >[1] 9 > : >R> lapply(1:2, f, 9) > : >[[1]] > : >[1] 9 > : > > : >[[2]] > : >[1] 9 > : > > : >R> "{"(1,9) > : >[1] 9 > : >R> lapply(1:2, "{", 9) > : >Error in lapply(1:2, "{", 9) : ... used in an incorrect context > : > > : >R> R.version.string > : >[1] "R version 1.9.1, 2004-08-03" > : > > : >______________________________________________ > : >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 > : > > : > > : > > : > > ______________________________________________ > 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 > >
Martin Maechler
2004-Sep-29 07:16 UTC
[R] R-devel not R-help (was "Bug? using { as a function ...")
>>>>> "Gabor" == Gabor Grothendieck <ggrothendieck at myway.com> >>>>> on Tue, 28 Sep 2004 20:02:01 +0000 (UTC) writes:Gabor> This seems like a bug to me. Can someone verify Gabor> this? By the way, Gabor (and everyone else) : This has been a typical topic *not* fitting well into R-help (because it's quite technical and not about solving a real problem with R, etc,etc) -- pretty much those things belonging to R-devel as explained in the posting guide. Martin Maechler < ........ >