Bug 17174 - Wishlist: 'vapply' could support long vectors
Summary: Wishlist: 'vapply' could support long vectors
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Wishlist (show other bugs)
Version: R 3.3.0
Hardware: Other Linux-Debian
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-10-30 03:05 UTC by Suharto Anggono
Modified: 2016-11-01 08:32 UTC (History)
1 user (show)

See Also:


Attachments
apply.c: do_vapply: for 'ind', make 'allocVector' like in 'do_lapply' (670 bytes, patch)
2016-10-30 03:05 UTC, Suharto Anggono
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Suharto Anggono 2016-10-30 03:05:16 UTC
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> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux stretch/sid

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] SparkR_1.6.1

loaded via a namespace (and not attached):
[1] tools_3.3.1


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)[0] = (double)(i + 1);

The attached patch modifies 'allocVector' for 'ind' in function 'do_vapply' to be like the corresponding part in function 'do_lapply'.
Comment 1 Martin Maechler 2016-10-31 09:20:49 UTC
Thank you, Suharto for checking these things and for the patch.
Comment 2 Martin Maechler 2016-11-01 08:32:29 UTC
I've committed the patch .. and tested it (needs ~ 20 min!) to R-devel  
and will port to R-patched.