Re: [Rd] Curious behavior of $ and lapply

2014-06-24 Thread Σταῦρος Μακράκης
Kevin, Thanks for the explanation. Based on your analysis, I tried to reproduce the problem without lapply, and sure enough: (function(x,y) "$"(x,y)) (list(a=2),"a") => NULL (function(x,...) "$"(x,...)) (list(a=2),"a") => NULL although "$"(list(a=2),"a") => 2 Looking for even simpler example

Re: [Rd] Curious behavior of $ and lapply

2014-06-23 Thread Kevin Ushey
`lapply` basically takes its call and massages into calls of the following form: FUN(X[[1L]], ...) FUN(X[[2L]], ...) ... that get evaluated in the appropriate environment. For `lapply(list(list(a=3,b=4)),"$","b")`, you can imagine that a function `FUN` of the form: FUN <- funct

[Rd] Curious behavior of $ and lapply

2014-06-23 Thread Σταῦρος Μακράκης
There seems to be a funny interaction between lapply and "$" -- also, "$" doesn't signal an error in some cases where "[[" does. The $ operator accepts a string second argument in functional form: > `$`(list(a=3,b=4),"b") [1] 4 lapply(list(list(a=3,b=4)),function(x) `$`(x,"b")) [[1]] [1] 4 ...