lapply-ing with the "$" function
Solution 1:
This is documented in ?lapply
, in the "Note" section (emphasis mine):
For historical reasons, the calls created by
lapply
are unevaluated, and code has been written (e.g.bquote
) that relies on this. This means that the recorded call is always of the formFUN(X[[0L]], ...)
, with0L
replaced by the current integer index. This is not normally a problem, but it can be ifFUN
usessys.call
ormatch.call
or if it is a primitive function that makes use of the call. This means that it is often safer to call primitive functions with a wrapper, so that e.g.lapply(ll, function(x) is.numeric(x))
is required in R 2.7.1 to ensure that method dispatch foris.numeric
occurs correctly.