Skip to content
Prev 367169 / 398506 Next

Is a list an atomic object? (or is there an issue with the help page of ?tapply ?)

On 02/14/2017 06:39 PM, Bert Gunter wrote:
Maybe this kind of details belong to the description of the FUN
argument. However please note that the man page for lapply() or the
other *apply() functions don't emphasize the fact that the supplied
FUN must be a function that accepts the things it applies to either,
and nobody seems to make a big deal of it. Maybe because it's obvious?
Well, it's the same error. Maybe what's not obvious is that in both
cases the error is coming from sum(), not from tapply() itself.
sum() is complaining that it receives something that it doesn't
know how to handle. The clue is in how the error message starts:

   Error in FUN(X[[i]], ...):

Maybe one could argue this is a little bit cryptic. Note the difference
when the error is coming from tapply() itself:

   > X <- letters[1:9]
   > INDEX <- c(rep(1,5),rep(2,5))
   > tapply(X, INDEX, FUN=identity)
   Error in tapply(X, INDEX, FUN = identity) :
     arguments must have same length

H.