Problem with developing a package with rstan - no source files found

#1

I have a couple of issues when trying to create a package that uses RStan according to https://mc-stan.org/rstantools/articles/minimal-rstan-package.html.
The code is available on github.com/nikosbosse/mimdiff.

The issues are:

  1. the .stan - file in src/stan_files is ignored and is not compiled. Also the package will not compile if I don’t add at least one empty file test.cpp to the src/ folder, complaining ‘no source files found’ and halting execution as ‘shared object mimdiff.so was not found’. On Windows10, the package compiles even if there are no other .cpp files in src/, but still does not compile the contents of src/stan_files/.
    Of course, nothing is added to stanmodels, either.

  2. I added a second function, test(), to the lm_stan.R file proposed by the step-by-step tutorial. However, this function is not exported, i.e. I cannot call it with mimdiff::test(). This only works if I run roxygen2::roxygenise (but then literally every sub-function is exported). The behavior is the same on Windows10 and Linux. I assume this is not a problem specific to rstan, but I still don’t know how to solve it.

I do not normally have a file in ~/.R/Makevars. Adding the following file I found as a suggestion on the internet

CXX = g++
CXXSTD = -std=c++11
CXXFLAGS = -fsanitize=undefined,address -fno-omit-frame-pointer

CXX98 = g++
CXX98STD = -std=c++98

CXX11 = g++
CXX11STD = -std=c++11

CXX14 = g++
CXX14STD = -std=c++14

resulted in an error “__asan_version_mismatch_check_v8”

Alternatively, copying the Makevars file from the rstanarm package (https://github.com/stan-dev/rstanarm/blob/master/src/Makevars) to src/MAKEVARS did not make a difference. However I had not included the init.cpp file as well.

I have also tried compiling the package with r-devel, but the above problems persisted.

I installed rstantools via remotes::install_github(“stan-dev/rstantools”, ref = “c3c59fb1ef”), as the version from CRAN or the development version from Github resulted in an error ‘rstan_config not exported by namespace:rstantools’.

Any help would be greatly appreciated.
Thank you very much!

  • Operating System: Manjaro Linux
  • RStan Version: 2.18.2, rstantools Version 1.5.1.9000
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars"))): no such file or directory
  • Output of devtools::session_info("rstan"):

─ Session info ──────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 3.5.3 (2019-03-11)
os Manjaro Linux
system x86_64, linux-gnu
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Europe/Berlin
date 2019-03-24

─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.5.3)
backports 1.1.3 2018-12-14 [1] CRAN (R 3.5.1)
BH 1.69.0-1 2019-01-07 [1] CRAN (R 3.5.2)
callr 3.2.0 2019-03-15 [1] CRAN (R 3.5.3)
checkmate 1.9.1 2019-01-15 [1] CRAN (R 3.5.2)
cli 1.1.0 2019-03-19 [1] CRAN (R 3.5.3)
colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.5.3)
crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.1)
desc 1.2.0 2018-05-01 [1] CRAN (R 3.5.1)
digest 0.6.18 2018-10-10 [1] CRAN (R 3.5.1)
fansi 0.4.0 2018-10-05 [1] CRAN (R 3.5.1)
ggplot2 3.1.0 2018-10-25 [1] CRAN (R 3.5.1)
glue 1.3.1 2019-03-12 [1] CRAN (R 3.5.3)
gridExtra 2.3 2017-09-09 [1] CRAN (R 3.5.1)
gtable 0.2.0 2016-02-26 [1] CRAN (R 3.5.1)
inline 0.3.15 2018-05-18 [1] CRAN (R 3.5.1)
labeling 0.3 2014-08-23 [1] CRAN (R 3.5.1)
lattice 0.20-38 2018-11-04 [2] CRAN (R 3.5.3)
lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.5.3)
loo 2.1.0 2019-03-13 [1] CRAN (R 3.5.3)
magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.1)
MASS 7.3-51.1 2018-11-01 [2] CRAN (R 3.5.3)
Matrix 1.2-15 2018-11-01 [2] CRAN (R 3.5.3)
matrixStats 0.54.0 2018-07-23 [1] CRAN (R 3.5.1)
mgcv 1.8-27 2019-02-06 [2] CRAN (R 3.5.3)
munsell 0.5.0 2018-06-12 [1] CRAN (R 3.5.1)
nlme 3.1-137 2018-04-07 [2] CRAN (R 3.5.3)
pillar 1.3.1 2018-12-15 [1] CRAN (R 3.5.1)
pkgbuild * 1.0.3 2019-03-20 [1] CRAN (R 3.5.3)
pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.5.1)
plyr 1.8.4 2016-06-08 [1] CRAN (R 3.5.1)
prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.5.1)
processx 3.3.0 2019-03-10 [1] CRAN (R 3.5.3)
ps 1.3.0 2018-12-21 [1] CRAN (R 3.5.1)
R6 2.4.0 2019-02-14 [1] CRAN (R 3.5.2)
RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.5.1)
Rcpp 1.0.1 2019-03-17 [1] CRAN (R 3.5.3)
RcppEigen 0.3.3.5.0 2018-11-24 [1] CRAN (R 3.5.1)
reshape2 1.4.3 2017-12-11 [1] CRAN (R 3.5.1)
rlang 0.3.2 2019-03-21 [1] CRAN (R 3.5.3)
rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.5.1)
rstan 2.18.2 2018-11-07 [1] CRAN (R 3.5.1)
scales 1.0.0 2018-08-09 [1] CRAN (R 3.5.1)
StanHeaders 2.18.1 2019-01-28 [1] CRAN (R 3.5.2)
stringi 1.4.3 2019-03-12 [1] CRAN (R 3.5.3)
stringr 1.4.0 2019-02-10 [1] CRAN (R 3.5.2)
tibble 2.1.1 2019-03-16 [1] CRAN (R 3.5.3)
utf8 1.1.4 2018-05-24 [1] CRAN (R 3.5.1)
viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.5.1)
withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.1)

[1] /home/nikos/R/x86_64-pc-linux-gnu-library/3.5
[2] /usr/lib/R/library