Skip to content
Prev 34705 / 63424 Next

sapply improvements

William Dunlap wrote:
...
I'd say that it should probably die on downwards coercion. Getting a 
double when an integer is expected, or complex instead of double as you 
indicate, is a likely user error. If not, then the user can always 
coerce explicitly inside FUN.

Another issue is whether one would want to go beyond the base classes of 
  S (logical, integer, double, complex, character). For other classes, 
there may be no notion of "up" and "down" in coercion. Then again, 
sapply was always limited to what unlist() will handle, so e.g.

 > sapply(1:10,FUN=function(i)Sys.Date())
  [1] 14553 14553 14553 14553 14553 14553 14553 14553 14553 14553

as opposed to

 > structure(rep(14553,10), class="Date")
  [1] "2009-11-05" "2009-11-05" "2009-11-05" "2009-11-05" "2009-11-05"
  [6] "2009-11-05" "2009-11-05" "2009-11-05" "2009-11-05" "2009-11-05"