# Rstan error: VECTOR\_ELT() can only be applied to a 'list', not a 'double'

**URL:** <https://discourse.mc-stan.org/t/rstan-error-vector-elt-can-only-be-applied-to-a-list-not-a-double/2093>\
**Category:** RStan\
**Created:** [October 2, 2017, 7:09pm UTC](https://discourse.mc-stan.org/t/rstan-error-vector-elt-can-only-be-applied-to-a-list-not-a-double/2093 "2017-10-02T19:09:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsilve24](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jsilve24/32/179_2.png) [@jsilve24](https://discourse.mc-stan.org/u/jsilve24)\
**Post date:** [October 2, 2017, 7:09pm UTC](https://discourse.mc-stan.org/t/rstan-error-vector-elt-can-only-be-applied-to-a-list-not-a-double/2093/1 "2017-10-02T19:09:27Z")

</div>

I am running into the following error

> VECTOR\_ELT() can only be applied to a ‘list’, not a ‘double’

A brief google search seems like the function expose\_stan\_functions may not behave so well with arrays. Not sure if this is my problem but it would make sense given the function I am trying to expose.

Data can be downloaded from here: [Dropbox - File Deleted - Simplify your life](https://www.dropbox.com/s/dp4t6dxe21pflqi/br_dat.RData?dl=0)

I have included a minimal reproducible example in the scripts below as well.

- I have already tried all the stupid things like updating my version of packages/R/Rstudio and restarting R.

Not exactly sure what is causing this issue but help would be most appreciated!

Thank you,  
Justin

[error\_reproduce.R](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/a/a8e5e98830a27ab612f09844f99478d616949e6a.R) (318 Bytes)  
[utils\_2.stan](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/b/bcc34f031abf48937287a7f469f706b1ef3ee823.stan) (580 Bytes)  
[tmp\_driver.stan](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/4/45e07f59afe5125d96831f2a3f2fd9be6829023a.stan) (38 Bytes)

Operating System: Mac OS X  
Interface Version: 2.16.2  
Output of writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”))):

```
CC=clang
CXX=clang++

CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function

CC=clang
CXX=clang++ -arch x86_64 -ftemplate-depth-256

CXXFLAGS += -Wno-ignored-attributes -Wno-deprecated-declarations

```

Output of devtools::session\_info("rstan”):

```
Session info -----------------------------------------
 setting value                       
 version R version 3.4.1 (2017-06-30)
 system x86_64, darwin15.6.0        
 ui RStudio (1.0.153)           
 language (EN)                        
 collate en_US.UTF-8                 
 tz America/New_York            
 date 2017-10-02                  

Packages ---------------------------------------------
 package * version date source        
 BH 1.65.0-1 2017-08-24 CRAN (R 3.4.1)
 colorspace 1.3-2 2016-12-14 CRAN (R 3.4.0)
 dichromat 2.0-0 2013-01-24 CRAN (R 3.4.0)
 digest 0.6.12 2017-01-27 CRAN (R 3.4.0)
 ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.4.0)
 graphics * 3.4.1 2017-07-07 local         
 grDevices * 3.4.1 2017-07-07 local         
 grid 3.4.1 2017-07-07 local         
 gridExtra 2.3 2017-09-09 CRAN (R 3.4.1)
 gtable 0.2.0 2016-02-26 CRAN (R 3.4.0)
 inline 0.3.14 2015-04-13 CRAN (R 3.4.0)
 labeling 0.3 2014-08-23 CRAN (R 3.4.0)
 lattice 0.20-35 2017-03-25 CRAN (R 3.4.1)
 lazyeval 0.2.0 2016-06-12 CRAN (R 3.4.0)
 magrittr 1.5 2014-11-22 CRAN (R 3.4.0)
 MASS 7.3-47 2017-02-26 CRAN (R 3.4.1)
 Matrix 1.2-11 2017-08-16 CRAN (R 3.4.1)
 methods * 3.4.1 2017-07-07 local         
 munsell 0.4.3 2016-02-13 CRAN (R 3.4.0)
 plyr 1.8.4 2016-06-08 CRAN (R 3.4.0)
 R6 2.2.2 2017-06-17 CRAN (R 3.4.0)
 RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.4.0)
 Rcpp 0.12.13 2017-09-28 CRAN (R 3.4.1)
 RcppEigen 0.3.3.3.0 2017-05-01 CRAN (R 3.4.0)
 reshape2 1.4.2 2016-10-22 CRAN (R 3.4.0)
 rlang 0.1.2 2017-08-09 CRAN (R 3.4.1)
 rstan * 2.16.2 2017-07-03 CRAN (R 3.4.1)
 scales 0.5.0 2017-08-24 CRAN (R 3.4.1)
 StanHeaders * 2.16.0-1 2017-07-03 CRAN (R 3.4.1)
 stats * 3.4.1 2017-07-07 local         
 stats4 3.4.1 2017-07-07 local         
 stringi 1.1.5 2017-04-07 CRAN (R 3.4.0)
 stringr 1.2.0 2017-02-18 CRAN (R 3.4.0)
 tibble 1.3.4 2017-08-22 CRAN (R 3.4.1)
 tools 3.4.1 2017-07-07 local         
 utils * 3.4.1 2017-07-07 local         
 viridisLite 0.2.0 2017-03-24 CRAN (R 3.4.0)

```

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [October 2, 2017, 7:48pm UTC](https://discourse.mc-stan.org/t/rstan-error-vector-elt-can-only-be-applied-to-a-list-not-a-double/2093/2 "2017-10-02T19:48:23Z")

</div>

The first argument has to be a list of 249 matrices that are 4x4 rather than a 249 x 4 x 4 array. You can accomplish this via

```
lapply(1:nrow(br_dat$GG, FUN = function(i) br_dat$GG[i,,])

```

---

<div class="post-metadata">

**Author:** ![jsilve24](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jsilve24/32/179_2.png) [@jsilve24](https://discourse.mc-stan.org/u/jsilve24)\
**Post date:** [October 3, 2017, 1:25pm UTC](https://discourse.mc-stan.org/t/rstan-error-vector-elt-can-only-be-applied-to-a-list-not-a-double/2093/3 "2017-10-03T13:25:38Z")

</div>

Thank you for your quick reply! Is this standard for all functions exposed through expose\_stan\_functions? i.e., if I have defined an array type in my stan code then I need to pass it to an exposed function as a list of whatever the base type is? This seems different than the data declarations where I have been able to pass such an array of matrices as a multidimensional array.

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [October 3, 2017, 2:32pm UTC](https://discourse.mc-stan.org/t/rstan-error-vector-elt-can-only-be-applied-to-a-list-not-a-double/2093/4 "2017-10-03T14:32:07Z")

</div>

Yes. This is an consequence that Rcpp deals with inputs differently than Stan. Stan can input multidimensional arrays, but I guess Rcpp wants lists of things.
