Created attachment 2177 [details]
apply.c: do_vapply: for 'ind', make 'allocVector' like in 'do_lapply'
In RStudio in Data Scientist Workbench:
R> res <- vapply(raw(2^31), function(x) x, raw(1))
Error in X[[i]] :
attempt to select less than one element in integerOneIndex
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux stretch/sid
 LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
 LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
 LC_PAPER=en_US.UTF-8 LC_NAME=C
 LC_ADDRESS=C LC_TELEPHONE=C
 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
 stats graphics grDevices utils datasets methods base
other attached packages:
loaded via a namespace (and not attached):
For completeness, it is nice if 'vapply' works on long vectors.
Looking at the code that implements 'vapply', function 'do_vapply' in apply.c, supporting long vectors for vector results (value of length 1) seems to be intended.
For the example above, the culprit is likely that the object stored in variable 'ind' in C, that is linked to symbol 'i' in R side, is treated by R as a vector of storage mode "integer" because it is made by allocVector(INTSXP, 1), but assignment of value is done by
REAL(ind) = (double)(i + 1);
The attached patch modifies 'allocVector' for 'ind' in function 'do_vapply' to be like the corresponding part in function 'do_lapply'.
Thank you, Suharto for checking these things and for the patch.
I've committed the patch .. and tested it (needs ~ 20 min!) to R-devel
and will port to R-patched.