Giter Site home page Giter Site logo

stan-dev / rstantools Goto Github PK

View Code? Open in Web Editor NEW
50.0 13.0 21.0 903 KB

Tools for Developing R Packages Interfacing with Stan

Home Page: https://mc-stan.org/rstantools

License: GNU General Public License v3.0

R 77.34% Stan 0.89% Shell 0.07% C++ 21.70%
stan r-package developer-tools bayesian-data-analysis bayesian-statistics

rstantools's Introduction

rstantools

CRAN_Status_Badge RStudio_CRAN_mirror_downloads_badge R-CMD-check

Overview

The rstantools package provides tools for developing R packages interfacing with Stan. The package vignettes provide guidelines and recommendations for developers as well as a demonstration of creating a working R package with a pre-compiled Stan program.

Resources

Installation

  • Install from CRAN:
install.packages("rstantools")
  • Install latest development version from GitHub:
# install.packages("remotes")
remotes::install_github("stan-dev/rstantools")

This installation from GitHub will not build the vignettes, but we recommend viewing them online at mc-stan.org/rstantools/articles.

rstantools's People

Contributors

andrjohns avatar avehtari avatar bgoodri avatar ecmerkle avatar hsbadr avatar jeffeaton avatar jgabry avatar kleinschmidt avatar mansmeg avatar mcol avatar mikekaminsky avatar mlysy avatar ndunnewind avatar paul-buerkner avatar raerickson avatar sieste avatar teemusailynoja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rstantools's Issues

confusing message if directory already exists

Calling rstan_create_package with path pointing to an existing directory generates an error with a confusing message:

> dir.create("tmp")
> rstan_create_package("tmp")
Error: Directory '.' already exists.

Error Please install the 'usethis' package to use this function.

Hello,

I have this error when following the instructions (which I solved installing such package):

library("rstantools")
This is rstantools version 1.5.0
rstan_package_skeleton(path = 'TABI')
Error in rstan_package_skeleton(path = "TABI") :
Please install the 'usethis' package to use this function.

sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS release 6.4 (Final)

Matrix products: default
BLAS: /wehisan/general/system/bioinf-software/bioinfsoftware/R/R-3.4.3/lib64/R/lib/libRblas.so
LAPACK: /wehisan/general/system/bioinf-software/bioinfsoftware/R/R-3.4.3/lib64/R/lib/libRlapack.so

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C 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 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] rstantools_1.5.0 bindrcpp_0.2.2 tidybayes_0.12.0.000002 rstan_2.17.3
[5] StanHeaders_2.17.2 forcats_0.3.0 stringr_1.3.1 dplyr_0.7.5
[9] purrr_0.2.4 readr_1.1.1 tidyr_0.8.1 tibble_1.4.2
[13] ggplot2_2.2.1 tidyverse_1.2.1 foreach_1.4.4

loaded via a namespace (and not attached):
[1] Rcpp_0.12.17 lubridate_1.7.1 lattice_0.20-35 listenv_0.7.0
[5] assertthat_0.2.0 digest_0.6.15 psych_1.8.3.3 R6_2.2.2
[9] cellranger_1.1.0 plyr_1.8.4 ggridges_0.5.0 stats4_3.4.3
[13] ggstance_0.3 coda_0.19-1 httr_1.3.1 pillar_1.1.0
[17] rlang_0.2.0 lazyeval_0.2.1 readxl_1.0.0 rstudioapi_0.7
[21] simplexRegression_0.1.0 labeling_0.3 foreign_0.8-69 munsell_0.4.3
[25] ARMET_1.0 broom_0.4.3 compiler_3.4.3 modelr_0.1.1
[29] pkgconfig_2.0.1 mnormt_1.5-5 globals_0.11.0 tidyselect_0.2.4
[33] gridExtra_2.3 arrayhelpers_1.0-20160527 codetools_0.2-15 doFuture_0.6.0
[37] future_1.8.0 crayon_1.3.4 MASS_7.3-49 grid_3.4.3
[41] nlme_3.1-137 jsonlite_1.5 gtable_0.2.0 magrittr_1.5
[45] scales_0.5.0 KernSmooth_2.23-15 cli_1.0.0 stringi_1.2.2
[49] LaplacesDemon_16.1.0 reshape2_1.4.3 xml2_1.2.0 iterators_1.0.9
[53] tools_3.4.3 svUnit_0.7-12 glue_1.2.0 hms_0.4.2
[57] parallel_3.4.3 yaml_2.1.19 inline_0.3.14 colorspace_1.3-2
[61] rvest_0.3.2 knitr_1.20 bindr_0.1.1 haven_1.1.1

Licence question

Using rstan_package_skeleton will create, among other things, the files R/stanmodels.R and tools/make_cc.R. The contain GPL3 Licence headers. In the first one the package name is the name of my package in the second one it is rstanarm. Is this thay way it is supposed to be?
Is it still possible to publish a package that was created using rstan_package_skeleton under a non-GLP compatible licence (in my case: MIT)?

rstan_package_skeleton: multiple translation units

I am using rstantools::rstan_package_skeleton to implement a dozen stan models in an R package. While tools/make_cpp.R creates multiple .cc files in src, the cleanup file has the lines

cat src/*.cc > src/Modules.cpp
rm src/*.cc

effectively leading to one translation unit. This means when I modify any of the stan models they all need to be recompiled, which makes development burdensome.

Unfortunately, removing the lines above (i.e., multiple translation units) leads to "duplicate symbols" linker errors. To my understanding, this is because stan declares + defines functions inside namespaces inside header files only, for which header guarding + inline keyword does not seem to prevent symbol duplication.

I'd like to fix this issue and can think of two ways of going about it:

  1. Modify the stan library so as to somehow nest the stan namespace within each model. I'm reluctant to do this, and have tried many many ways around this, including:
    • creating separate src/include/models.hpp files for each model. Didn't work, as stan/model/model.hpp goes into each .o which all get linked into one .so.
    • something like
      namespace myModel {
        #include "src/include/models.hpp"
        // ...
      }
      
      I.e., I'm trying to nest the stan namespace into the namespace for each model. Unfortunately this doesn't work either because within the stan namespace there are using declarations which no longer refer to the right things when you nest them.
  2. A different approach is to build the stan models when the package is installed, and then save them as .RData files in the data folder. Then later when the installed package gets loaded, the models aren't rebuilt.

Perhaps I should point out that I implemented approach 2 long before rstantools was released. It worked perfectly until I had to install on a multi-architecture Windows platform. There the models only got built on one platform, and of course R crashed when I tried to load them from the other.

I thought about this some more and I believe the problem can be resolved by building architecture-dependent .RData files at install time, and sealing the objects into the package namespace at load time. However, I don't want to veer off from the stan-supported way of doing things, so I'm asking for advice/feedback on how to proceed.

package skeleton travis.yml disallows llvm-toolchain-precise-5.0

When I use the current github version of rstantools to created a skeleton, I get the following error on travis:

Disallowing sources: llvm-toolchain-precise-5.0
To add unlisted APT sources, follow instructions in https://docs.travis-ci.com/user/installing-dependencies#Installing-Packages-with-the-APT-Addon

Link to travis docs

Link to build

I tried to understand the cited reference, but failed to get the syntax right.

Build of rstanarm fails too for the same reason

https://travis-ci.org/stan-dev/rstanarm

warning in `rstan_package_skeleton`: 'No such file or directory'

Testing the new step-by-step vignette, the rstan_package_skeleton function throws a warning

rstan_package_skeleton(name='rstanlm')
# [output omitted]
Warning message:
In file.remove(DATA) :
  cannot remove file './rstanlm/data', reason 'No such file or directory'

The reason is that the condition in

if (!length(list.files(DATA))) {

is satisfied if the data directory saved in variable DATA doesn't exist.

rstan_package_skeleton: Error - Path does not appear to be inside a project or package

> library(rstantools)
This is rstantools version 1.5.1.9000
> rstan_package_skeleton('ICCier')
Creating package skeleton for package: ICCier
Running usethis::create_package ...
✔ Creating 'ICCier/'
✔ Setting active project to '/home/srmart/ICCier'
✔ Creating 'R/'
✔ Writing 'DESCRIPTION'
Package: ICCier
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R (parsed):
    * First Last <[email protected]> [aut, cre] (<https://orcid.org/YOUR-ORCID-ID>)
Description: What the package does (one paragraph).
License: What license it uses
Depends:
    methods,
    R (>= 3.4.0),
    Rcpp (>= 1.0.1)
Imports:
    rstan (>= 2.18.2),
    rstantools (>= 1.5.1)
LinkingTo:
    BH (>= 1.69.0-1),
    Rcpp (>= 1.0.1),
    RcppEigen (>= 0.3.3.5.0),
    rstan (>= 2.18.2),
    StanHeaders (>= 2.18.1)
Encoding: UTF-8
LazyData: true
NeedsCompilation: yes
SystemRequirements: GNU make
✔ Writing 'NAMESPACE'
✔ Writing 'ICCier.Rproj'
✔ Adding '.Rproj.user' to '.gitignore'
✔ Adding '^ICCier\\.Rproj$', '^\\.Rproj\\.user$' to '.Rbuildignore'
✔ Setting active project to '<no active project>'
Error: Path '/home/srmart/' does not appear to be inside a project or package.

See code and error above.

I also simply ran the function contents manually, line by line to diagnose the problem. I have to run the code until it breaks. Then I open the newly create project, create the variables again, change directory to one above the ICCier project directory, then finish running the code.
Even then, I hit snags - I get the roxygen2 DLL error and 'object m not found' error.

The step-by-step guide does not appear to work.
I tried running this in rstudio server, rstudio desktop, and in R via terminal, with and without rstudio=TRUE, open=TRUE.

RStudio version: 1.2.907
R version: 3.5.3
rstantools: Tried both latest CRAN release and github release
Latest CRAN versions of usethis and rstudioapi as well.

rstan_package_skeleton() gives object 'm' not found

I follow these instructions: https://cran.r-project.org/web/packages/rstantools/vignettes/minimal-rstan-package.html (2018-08-20) but get the error in the issue title. From googling about this error crops up when installing/loading packages that depend on rstan but I didn't see much about it when running rstan_package_skeleton. Presumably my installation is corrupt somehow but I can't see how (session information is below).

> library("rstantools")
This is rstantools version 1.5.1
> rstan_package_skeleton(path = 'rstanlm')
Creating package skeleton for package: rstanlm
Running usethis::create_package ...
✔ Setting active project to '/home/john/tmp/rstanlm'
✔ Creating 'R/'
✔ Creating 'man/'
✔ Writing 'DESCRIPTION'
✔ Writing 'NAMESPACE'
✔ Creating 'tools/'
✔ Creating 'src/'
✔ Creating 'src/stan_files/'
✔ Creating 'src/stan_files/chunks/'
✔ Creating 'inst/'
✔ Creating 'inst/include/'
Updating R directory ...
Adding .travis.yml file ...
Updating DESCRIPTION with necessary dependencies ...
Updating NAMESPACE ...
Writing NAMESPACE
Running /usr/lib/R/bin/R CMD INSTALL /home/john/tmp/rstanlm \
  --library=/tmp/RtmpS520NG/devtools_install_37f42e569b2e' --no-R --no-data --no-help \
  --no-demo --no-inst --no-docs --no-exec --no-multiarch --no-test-load --preclean
* installing *source* package ‘rstanlm’ ...
** libs
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I"../inst/include" -I"`"/usr/lib/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"'" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error -I"/home/john/lib/R/library/BH/include" -I"/home/john/lib/R/library/Rcpp/include" -I"/home/john/lib/R/library/RcppEigen/include" -I"/home/john/lib/R/library/rstan/include" -I"/home/john/lib/R/library/StanHeaders/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c init.cpp -o init.o
g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o rstanlm.so init.o -L/usr/lib/R/lib -lR
installing to /tmp/RtmpS520NG/devtools_install_37f42e569b2e/rstanlm/libs
* DONE (rstanlm)
Error in is(module, "character") : object 'm' not found
>
> devtools::session_info()
Session info -----------------------------------------------------------------------------------
 setting  value
 version  R version 3.5.1 (2018-07-02)
 system   x86_64, linux-gnu
 ui       X11
 language en_GB:en
 collate  en_GB.UTF-8
 tz       Europe/London
 date     2018-10-16

Packages ---------------------------------------------------------------------------------------
 package     * version    date       source
 assertthat    0.2.0      2017-04-11 CRAN (R 3.5.1)
 backports     1.1.2      2017-12-13 CRAN (R 3.5.1)
 base        * 3.5.1      2018-07-03 local
 base64enc     0.1-3      2015-07-28 CRAN (R 3.5.1)
 BH            1.66.0-1   2018-02-13 CRAN (R 3.5.1)
 bindr         0.1.1      2018-03-13 CRAN (R 3.5.1)
 bindrcpp      0.2.2      2018-03-29 CRAN (R 3.5.1)
 callr         3.0.0      2018-08-24 CRAN (R 3.5.1)
 clisymbols    1.2.0      2017-05-21 CRAN (R 3.5.1)
 colorout    * 1.2-0      2018-09-27 local
 colorspace    1.3-2      2016-12-14 CRAN (R 3.5.1)
 commonmark    1.6        2018-09-30 CRAN (R 3.5.1)
 compiler      3.5.1      2018-07-03 local
 crayon        1.3.4      2017-09-16 CRAN (R 3.5.1)
 datasets    * 3.5.1      2018-07-03 local
 debugme       1.1.0      2017-10-22 CRAN (R 3.5.1)
 desc          1.2.0      2018-05-01 CRAN (R 3.5.1)
 devtools    * 1.13.6     2018-06-27 CRAN (R 3.5.1)
 digest        0.6.18     2018-10-10 CRAN (R 3.5.1)
 dplyr         0.7.6      2018-06-29 CRAN (R 3.5.1)
 fs            1.2.6      2018-08-23 CRAN (R 3.5.1)
 ggplot2       3.0.0      2018-07-03 CRAN (R 3.5.1)
 glue          1.3.0      2018-07-17 CRAN (R 3.5.1)
 graphics    * 3.5.1      2018-07-03 local
 grDevices   * 3.5.1      2018-07-03 local
 grid          3.5.1      2018-07-03 local
 gridExtra     2.3        2017-09-09 CRAN (R 3.5.1)
 gtable        0.2.0      2016-02-26 CRAN (R 3.5.1)
 inline        0.3.15     2018-05-18 CRAN (R 3.5.1)
 lattice       0.20-35    2017-03-25 CRAN (R 3.5.1)
 lazyeval      0.2.1      2017-10-29 CRAN (R 3.5.1)
 loo           2.0.0      2018-04-11 CRAN (R 3.5.1)
 magrittr      1.5        2014-11-22 CRAN (R 3.5.1)
 Matrix        1.2-14     2018-04-09 CRAN (R 3.5.1)
 matrixStats   0.54.0     2018-07-23 CRAN (R 3.5.1)
 memoise       1.1.0      2017-04-21 CRAN (R 3.5.1)
 methods     * 3.5.1      2018-07-03 local
 munsell       0.5.0      2018-06-12 CRAN (R 3.5.1)
 parallel      3.5.1      2018-07-03 local
 pillar        1.3.0      2018-07-14 CRAN (R 3.5.1)
 pkgbuild      1.0.1      2018-09-18 CRAN (R 3.5.1)
 pkgconfig     2.0.2      2018-08-16 CRAN (R 3.5.1)
 pkgload       1.0.1      2018-10-11 CRAN (R 3.5.1)
 plyr          1.8.4      2016-06-08 CRAN (R 3.5.1)
 processx      3.2.0      2018-08-16 CRAN (R 3.5.1)
 ps            1.1.0      2018-08-10 CRAN (R 3.5.1)
 purrr         0.2.5      2018-05-29 CRAN (R 3.5.1)
 R6            2.3.0      2018-10-04 CRAN (R 3.5.1)
 Rcpp        * 0.12.19    2018-10-01 CRAN (R 3.5.1)
 RcppEigen     0.3.3.4.0  2018-02-07 CRAN (R 3.5.1)
 rlang         0.2.2      2018-08-16 CRAN (R 3.5.1)
 roxygen2      6.1.0      2018-07-27 CRAN (R 3.5.1)
 rprojroot     1.3-2      2018-01-03 CRAN (R 3.5.1)
 rstan         2.18.1     2018-10-16 CRAN (R 3.5.1)
 rstanlm       0.0.0.9000 <NA>       local
 rstantools  * 1.5.1      2018-08-22 CRAN (R 3.5.1)
 rstudioapi    0.8        2018-10-02 CRAN (R 3.5.1)
 scales        1.0.0      2018-08-09 CRAN (R 3.5.1)
 setwidth    * 1.0-4      2015-07-07 Github (cran/setwidth@42b61c4)
 StanHeaders   2.18.0     2018-10-07 CRAN (R 3.5.1)
 stats       * 3.5.1      2018-07-03 local
 stats4        3.5.1      2018-07-03 local
 stringi       1.2.4      2018-07-20 CRAN (R 3.5.1)
 stringr       1.3.1      2018-05-10 CRAN (R 3.5.1)
 testthat      2.0.1      2018-10-13 CRAN (R 3.5.1)
 tibble        1.4.2      2018-01-22 CRAN (R 3.5.1)
 tidyselect    0.2.5      2018-10-11 CRAN (R 3.5.1)
 tools         3.5.1      2018-07-03 local
 usethis       1.4.0      2018-08-14 CRAN (R 3.5.1)
 utils       * 3.5.1      2018-07-03 local
 whisker       0.3-2      2013-04-28 CRAN (R 3.5.1)
 withr         2.1.2      2018-03-15 CRAN (R 3.5.1)
 xml2          1.2.0      2018-01-24 CRAN (R 3.5.1)
>

Next release checklist

  • Update rstan_package_skeleton, making sure to also address the concerns in #19

  • Add vignette walking through the steps to create a functioning package. There's an open PR for this already #15

loo_R2 gives different diagnostic than loo()

Expected behavior would be to get no warnings from loo_R2() if there are no warnings from loo(), or at least there should be way to diagnose loo_R2() result as now it returns only the draws representing LOO R^2 uncertainty.

> (loo1 <- loo(fit1))

Computed from 4000 by 343 log-likelihood matrix

         Estimate   SE
elpd_loo   -864.4 12.6
p_loo        26.3  2.0
looic      1728.8 25.1
------
Monte Carlo SE of elpd_loo is 0.1.

All Pareto k estimates are good (k < 0.5).
See help('pareto-k-diagnostic') for details.
> round(median(loo_R2(fit1)), 2)
[1] 0.17
Warning message:
Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.

CXX14 Not Defined by R on Windows (3.5.1 and Rtools 3.4)

Hi -

I upgraded to the new rstantools and I ran into a confusing issue. The Makevars.win sets CXX_STD as CXX14 , but CXX14 is not defined in the current version of R (3.5.1) with Windows (see https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Using-C_002b_002b14-code). It is possible to set up environmental variables in ~/.R/Makevars.win to define CXX14, but this was rather a pain.

Is there any reason that CXX14 needs to be used in this file? All of my Stan code on Windows compiles fine with CXX_STD set as CXX11.

must specify DLL via a “DLLInfo” object. See getLoadedDLLs()

I tried creating a basic skeleton, but the package failed.

Related: https://discourse.mc-stan.org/t/rstantools-rstan-package-skeleton-failing-with-error-in-getdllregisteredroutines-dllinfo/6848

> devtools::install_github("stan-dev/rstantools")
Downloading GitHub repo stan-dev/rstantools@master
   checking for file ‘/private/var/folders/x7/bwlcxr3n6jn95jz3bsh_p92w0000gn/T/R✔  checking for file ‘/private/var/folders/x7/bwlcxr3n6jn95jz3bsh_p92w0000gn/T/RtmpNQphAe/remotes707a3854b51d/stan-dev-rstantools-612d8bf/DESCRIPTION’
─  preparing ‘rstantools’:
✔  checking DESCRIPTION meta-information ...
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘rstantools_1.5.1.tar.gz’
   
* installing *source* package ‘rstantools’ ...
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (rstantools)
> rstan_package_skeleton(path = 'rstanlm')
Error in rstan_package_skeleton(path = "rstanlm") : 
  could not find function "rstan_package_skeleton"
> library(rstantools
+ )
This is rstantools version 1.5.1
> rstan_package_skeleton(path = 'rstanlm')
Creating package skeleton for package: rstanlm
Running usethis::create_package ...
✔ Setting active project to '/Users/ianfellows/tmp/rstanlm'
✔ Creating 'R/'
✔ Creating 'man/'
✔ Writing 'DESCRIPTION'
✔ Writing 'NAMESPACE'
✔ Creating 'tools/'
✔ Creating 'src/'
✔ Creating 'src/stan_files/'
✔ Creating 'src/stan_files/chunks/'
✔ Creating 'inst/'
✔ Creating 'inst/include/'
Updating R directory ...
Adding .travis.yml file ...
Updating DESCRIPTION with necessary dependencies ...
Updating NAMESPACE ...
Writing NAMESPACE
Error in getDLLRegisteredRoutines.DLLInfo(dll, addNames = FALSE) : 
  must specify DLL via a “DLLInfo” object. See getLoadedDLLs()
> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.2

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] Rcpp_1.0.0       rstantools_1.5.1

loaded via a namespace (and not attached):
 [1] rstan_2.18.2         clisymbols_1.2.0     tidyselect_0.2.5    
 [4] remotes_2.0.2        purrr_0.2.5          colorspace_1.3-2    
 [7] testthat_2.0.1       usethis_1.4.0        stats4_3.5.2        
[10] loo_2.0.0            rlang_0.3.1          pkgbuild_1.0.2      
[13] pillar_1.3.1         glue_1.3.0           withr_2.1.2         
[16] sessioninfo_1.1.1    bindrcpp_0.2.2       matrixStats_0.54.0  
[19] plyr_1.8.4           bindr_0.1.1          rstanlm_0.0.0.9000  
[22] stringr_1.3.1        munsell_0.5.0        commonmark_1.7      
[25] gtable_0.2.0         devtools_2.0.1       memoise_1.1.0       
[28] inline_0.3.15        callr_3.1.1          ps_1.3.0            
[31] parallel_3.5.2       curl_3.2             backports_1.1.3     
[34] scales_1.0.0         desc_1.2.0           pkgload_1.0.2       
[37] StanHeaders_2.18.0-1 fs_1.2.6             gridExtra_2.3       
[40] ggplot2_3.1.0        digest_0.6.18        stringi_1.2.4       
[43] processx_3.2.1       dplyr_0.7.8          rprojroot_1.3-2     
[46] grid_3.5.2           cli_1.0.1            tools_3.5.2         
[49] magrittr_1.5         lazyeval_0.2.1       tibble_2.0.1        
[52] crayon_1.3.4         whisker_0.3-2        pkgconfig_2.0.2     
[55] xml2_1.2.0           prettyunits_1.0.2    assertthat_0.2.0    
[58] roxygen2_6.1.1       rstudioapi_0.9.0     R6_2.3.0            
[61] compiler_3.5.2  

Don't remove line numbers with `sed` in cleanup.win

Reported by Slawek Smyl on Stan-users:

rstantools creates a skeleton with cleanup.win file that contains call to sed

sed -i.bak '/current_statement_begin__ = [0-9]/d' src/include/models.hpp

The problem is that on Windows, GNU sed will change permissions (drastically reduce them) of the edited file, making models.hpp unreachable

Modules.cpp:3:30: fatal error: include/models.hpp: Permission denied

It is apparently a well known bug of sed, e.g. https://cygwin.com/ml/cygwin/2012-02/msg00616.html

New generics for wrappers around loo::model_weights and loo::model_select

With the release of loo 2.0, I want to support the model_weights and model_select functions in brms. For this purpose, I need to build wrapper methods around them and I thought it would be a good idea to have a common generic defined in rstantools to minimize naming confusion. I though of the names loo_weights and loo_select, but I am open to other suggestions.

Compilation error under Mac OSX

Dear all, I am trying to write a package containing a Stan program I have written (see https://github.com/corneliussenf/disturbanceBayes). I used the rstantools to build a package skeleton using rstantools::rstan_package_skeleton(). Everythink worked nicely so far. However, when I checked the packge using either R CMD check in the Terminal or devtools::check(), I get following error:

  • installing source package ‘disturbanceBayes’ ...
    ** libs
    rm: stan_files/: is a directory
    make: *** [shlib-clean] Error 1
    clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I"../inst/include" -I""/Library/Frameworks/R.framework/Resources/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=ignore_error -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rstan/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppEigen/include" -I/usr/local/include -fPIC -Wall -g -O2 -c init.cpp -o init.o
    clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o disturbanceBayes.so stan_files/ init.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
    ld: can't map file, errno=22 file 'stan_files/' for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [disturbanceBayes.so] Error 1
    ERROR: compilation failed for package ‘disturbanceBayes’
  • removing ‘/private/var/folders/fx/hyncgzcx6l35ypn4sqm6q2m00000gn/T/RtmpDxCkiU/devtools_install_15e250520bf/disturbanceBayes’

I also checked a clean package skeleton without any stan or R code by myself (i.e., plain package created by rstantools::rstan_package_skeleton()) and got the same error. I am using the newest R Version (3.4.3) and updated all packages. I am working on a Mac with OSX 10.13.2.

Any ideas what causes the error and how I can fix it?

Including functions defined in additional stan files

How do I include a "common_functions.stan" file when using the new package layout?

The old way was to put common functions in the exec/chunks inst/chunks directory and then use an #include statement in the functions block of the stan model.

The advice in the new layout is (from Read-and-delete-me):

  • Additional files to be included by stanmodel definition files
    (via e.g., #include "mylib.stan") must be placed in any subfolder of 'inst/stan'.

Following this, I modified the example given in the step by step vignette to use an external function, doubleit, defined in inst/stan/include/common_functions.stan.
Here's the error I get from pkgbuild::compile_dll():
Function doubleit not found.
error in 'model_lm' at line 17, column 43
-------------------------------------------------
15: model {
16: // ... priors, etc.
17: y ~ normal(intercept + beta * doubleit(x), sigma);
^
18: }
-------------------------------------------------
Error in rstan::stanc(file_name, allow_undefined = TRUE, obfuscate_model_name = FALSE) :
failed to parse Stan model 'lm' due to the above error.

The files I'm using are:

inst/stan/lm.stan

// Save this file as inst/stan/lm.stan
functions {
    #include "common_functions.stan"
}
data {
  int<lower=1> N;
  vector[N] x;
  vector[N] y;
}
parameters {
  real intercept;
  real beta;
  real<lower=0> sigma;
}
model {
  // ... priors, etc.
  y ~ normal(intercept + beta * doubleit(x), sigma);
}

inst/stan/include/common_functions.stan

vector doubleit(vector xx) {
    return xx * 2;
}

R/lm_stan.R

# Save this file as `R/lm_stan.R`
#' Bayesian linear regression with Stan
#'
#' @export
#' @param x Numeric vector of input values.
#' @param y Numberic vector of output values.
#' @param ... Arguments passed to `rstan::sampling` (e.g. iter, chains).
#' @return An object of class `stanfit` returned by `rstan::sampling`
#'
lm_stan <- function(x, y, ...) {
    standata <- list(x = x, y = y, N = length(y))
    out <- rstan::sampling(stanmodels$lm, data = standata, ...)
    return(out)
}

devtools::install in step-by-step instructions fails (missing/empty \title field)

Following the step-by-step guide, I get an error on

devtools::install(local=FALSE)
# [... lots of C++ compiler output ...]
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
Error in Rd_info(db[[i]]) : 
  missing/empty \title field in '/tmp/RtmpfIoONs/R.INSTALL2e133c949d42/rstanlm/man/date.Rd'
Rd files must have a non-empty \title.
See chapter 'Writing R documentation' in manual 'Writing R Extensions'.
* removing ‘/home/stefan/lib/R/rstanlm’
Error: Command failed (1)

Contrary, devtools::load_all(recompile=TRUE) (which is what the vignette does internally) is successful.

error when I compile my rstan based package

Hello,
I've developed my package (ssMousetrack) based on rstantools. The package is on cran and I've never had problems during installation. Now I've tried to install it on a new linux based machine and I've got the following error:

"/usr/lib/R/bin/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" stan_files/fit_model.stan Error: (converted from warning) S3 methods 'print.stanfit', 'as.array.stanfit', 'as.matrix.stanfit', 'as.data.frame.stanfit', 'is.array.stanfit', 'dim.stanfit', 'dimnames.stanfit', 'names.stanfit', 'names<-.stanfit', 'pairs.stanfit', 'loo.stanfit' were declared in NAMESPACE but not found Execution halted Makevars:17: recipe for target 'stan_files/fit_model.cc' failed make: *** [stan_files/fit_model.cc] Error 1 ERROR: compilation failed for package ‘ssMousetrack’ removing ‘/home/stat1/R/x86_64-pc-linux-gnu-library/3.5/ssMousetrack’ Installation failed: Command failed (1)

It seems something get wrongs with stan headers. What is going wrong?

posterior_cdf generic?

We have posterior_interval to get quantiles from the posterior... but sometimes we need the reverse and ask for interval probabilities for which the CDF is needed. This would probably make sense for most of the posterior queries we have (posterior/predictive/linpred). The default implementation could very likely already do the the job for most situations by integrating the indicator functions accordingly.

reloo generic

@paul-buerkner I'd like to add a generic for reloo so we can have reloo.stanreg and reloo.brmsfit methods. But I see that currently brms takes the first argument of reloo to be the loo object. So it can't change to a brmsfit method without breaking backwards compatibility, right? If that's the case then maybe we should use a different name than reloo for the generic and new methods and you can deprecate reloo it in brms. What do you think? Definitely open to other ideas.

Problems with the new 1.4.0 build chain for Stan packages

While trying to migrate one of my Stan based R packages using rstantools 1.4.0, I stumbled upon multiple problems during the build process on Windows.

  • While compiling, g++ complains about not finding file stan_files unless one already provided the names of the Stan files when running rstan_package_skeleton instead of adding them manually later on. The solution to manually amend the Makevars files is obvious in restrospect, but might still confuse many developers first trying to build an R package based on Stan. Do you already point developers to this potential problem?

  • The current build chains expects license.stan to be in stan_files/pre, but rstan_package_skeleton puts it in stan_files/chunks.

  • The point Be sure to import all of Rcpp and methods in the NAMESPACE file. in the Read-and-delete-me file is confusing to me, since both Rcpp and methods are on depends in the DESCRIPTION. I think it would be better to have at least Rcpp only in imports in the DESCRIPTION in order not to pollute the global env, but I am sure you have good reasons for the current way of doing it.

  • SOLVED: On my machine, multiple cores still don't work as described in http://discourse.mc-stan.org/t/using-the-cores-argument-in-a-stan-based-r-package-with-precompiled-models/2236/8. EDIT: It only fails when building the package with "Build & Reload", which is admitedly a minor problem.

problem exporting Rcpp functions

I want to make a C++ function aviliable to R with the // [[Rcpp::export]] command. This does not work when using the rstan.package.skeleton. I get the error "object '[name of the rcpp function]' not found". It appears to be some problem with registering the routine.

However, if I remove lines 16:20 from src\init.cpp the registration works. Here is the code from those lines:

void attribute_visible R_init_sem5r1c(DllInfo *dll) {
  // next line is necessary to avoid a NOTE from R CMD check
  R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
  R_useDynamicSymbols(dll, TRUE); // necessary for .onLoad() to work
}

What do these lines of code actually do and are they safe to remove?

rstan_package_skeleton fails on Windows with R 3.6.0+

With R 3.6.0+ on Windows 10 x64, a simple call of rstan_package_skeleton fails with the following error:

library(rstantools)
rstan_package_skeleton("mypackage")

✔ Creating 'mypackage/'Setting active project to 'MYPATH/mypackage'Creating 'R/'Writing 'DESCRIPTION'
Package: mypackage
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R (parsed):
    * First Last <first.last@example.com> [aut, cre] (<https://orcid.org/YOUR-ORCID-ID>)
Description: What the package does (one paragraph).
License: What license it uses
Depends:
    methods,
    R (>= 3.4.0),
    Rcpp (>= 1.0.1)
Imports:
    rstan (>= 2.19.2),
    rstantools (>= 1.5.1)
LinkingTo:
    BH (>= 1.69.0-1),
    Rcpp (>= 1.0.1),
    RcppEigen (>= 0.3.3.5.0),
    rstan (>= 2.19.2),
    StanHeaders (>= 2.18.1-10)
Encoding: UTF-8
LazyData: true
NeedsCompilation: yes
SystemRequirements: GNU makeWriting 'NAMESPACE'Writing 'mypackage.Rproj'Adding '.Rproj.user' to '.gitignore'Adding '^mypackage\\.Rproj$', '^\\.Rproj\\.user$' to '.Rbuildignore'Setting active project to '<no active project>'Setting active project to 'MYPATH'Creating 'tools/'Creating 'src/'
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file 'MYPATH\mypackage/src/init.cpp': No such file or directory

I am using rstantool 1.5.1 and all other packages are up-to-date (current CRAN releases).

Error: 'rstan_config' is not an exported object from 'namespace:rstantools'

Hello,

Thanks for your time in viewing this.
I developed a R package "DEEPEst" for my lab with function rstan_create_package from rstantools 2.0.0. The installation on my machine works while others guys in my lab failed to install the package from our github. This error happens both on mac and win and I can not solve it by myself.

> devtools::install_github("ColumbiaCDS/DEEPEst")
Downloading GitHub repo ColumbiaCDS/DEEPEst@master
√  checking for file 'C:\Users\kelle\AppData\Local\Temp\Rtmpe606pl\remotes5e2089d477e\ColumbiaCDS-DEEPEst-9e6ed4a/DESCRIPTION' ...
-  preparing 'DEEPEst': (25.1s)
√  checking DESCRIPTION meta-information (532ms)
-  cleaning src
-  checking for LF line-endings in source and make files and shell scripts (24.1s)
-  checking for empty or unneeded directories
-  building 'DEEPEst_1.0.tar.gz'
   Warning: file 'DEEPEst/configure' did not have execute permissions: corrected
   
Installing package into ‘C:/Users/kelle/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
* installing *source* package 'DEEPEst' ...
Error: 'rstan_config' is not an exported object from 'namespace:rstantools'
Execution halted
ERROR: configuration failed for package 'DEEPEst'
* removing 'C:/Users/kelle/Documents/R/win-library/3.5/DEEPEst

Relabelling helper function for working with factors in rstan

Summary:

When using factor variables (which are have attached meaningful level names), would it be useful/possible to have a function that relabels variables in the Stan fit object with the relevant factor levels?

Description:

When using categorical variables in stan you have to drop the level labels. This is fine and sensible, but with variables that have a number of levels, the output can be difficult to read. Would it be possible to write a helper function that relabels the numeric index with the relevant label for easier use? @jgabry thought it might be, but wasn't sure if it would be too complex to create something that was useful in the more general.

Reproducible Steps:

For example. With the 8 schools model the schools are coded as numbers. However, in real world data, they would often be recorded with meaningful names (here we use states).

schools_df <- data.frame(schools = state.name[1:8],
y = c(28,  8, -3,  7, -1,  1, 18, 12),
sigma = c(15, 10, 16, 11,  9, 11, 10, 18))
schools_df$schools = as.factor(schools_df$schools)

I am proposing a pair of functions that force the factors to numeric for use in rstan, and then relabels the relevant variables in the stan fit object. e.g. for the simple 8 schools case.

delabel <- function(x){
  return(as.numeric(x))
}

relabel <- function(x,stan_fit,variables){
   current_names <- names(stan_fit)
   match <- cbind(levels(x),levels(as.factor(as.numeric(x))))
   for (i in 1:length(variables)){
     loc_var <- grepl(paste0("^",variables[i]),current_names)
     for(j in 1:nrow(match)){
       current_names[loc_var] <- gsub(pattern = match[j,2], replacement = match[j,1],current_names[loc_var])
     }
   }
   names(stan_fit) <- current_names
   return(stan_fit)
}

The idea is that is would work something like this:

schools_dat <- list(J = 8, 
                    school = delabel(schools_df$schools),
                    y = schools_df$y,
                    sigma =schools_df$sigma)

library(rstan)

fit <- stan(file = '8schools.stan', data = schools_dat)

fit2 <- relabel(schools_df$schools,fit,c('theta','eta'))

colnames(as.matrix(fit2))
library(bayesplot)
mcmc_areas_ridges(as.matrix(fit2, pars = "theta"))

my rstan based package fails to compile under macOS

Hello,
I have developed ssMousetrack a rstan based package (rstan: 2.18.2, my os: ubuntu 18.04.01) but when trying to install the package under macOS I find the following error:

make_cc(commandArgs(TRUE))" stan_files/fit_model.stan Wrote C++ file "stan_files/fit_model.cc" Error: unexpected symbol in: "cat(' ', sep = ' cat(system.file('include" Execution halted /usr/local/clang7/bin/clang++ -std=gnu++14 -I"/Users/ripley/R/R-patched/include" -DNDEBUG -I"../inst/include" -I"" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error -I"/Users/ripley/R/test-3.5/BH/include" -I"/Users/ripley/R/test-3.5/Rcpp/include" -I"/Users/ripley/R/test-3.5/RcppEigen/include" -I"/Users/ripley/R/test-3.5/rstan/include" -I"/Users/ripley/R/test-3.5/StanHeaders/include" -I/usr/local/include -fPIC -g -O2 -Wall -pedantic -c stan_files/fit_model.cc -o stan_files/fit_model.o In file included from stan_files/fit_model.cc:3: In file included from stan_files/fit_model.hpp:18: In file included from /Users/ripley/R/test-3.5/rstan/include/rstan/rstaninc.hpp:3: /Users/ripley/R/test-3.5/rstan/include/rstan/stan_fit.hpp:11:10: fatal error: 'stan/version.hpp' file not found #include <stan/version.hpp>

Could you please help me with this issue?
Thanks in advance!

Feature suggestions for rstan_package_skeleton

Dear @jgabry and @bgoodri,

Here is a link to an rstantools fork providing a few additional features to the current version of rstan_package_skeleton, namely:

  1. The ability to add your own C++ code to a Stan-enabled package.
  2. The ability to add Stan functionality to an existing R package.

I've extensively documented my work in the repo's README. Aside from these features, I follow the current build mechanism of rstan_package_skeleton very closely. There are however a few notable exceptions:

  1. I use package.skeleton as the driver rather than usethis::create_package. This is mainly because I was following the previous version of rstantools when I created the fork.
  2. In my version, every time a .stan file get added/deleted/modified requires slight manual intervention, i.e., a call to rstantools::rstan_config(). The current version of rstantools circumvents this through the Makevars. However, for reasons outlined in the README, this Makevars will generate a WARNING from R CMD check. I'm in the process of adapting my fork to circumvent this additional call to rstan_config.

With your permission, would love to turn this into a PR -- either way, looking forward to hearing your thoughts!

prepare for next release

@bgoodri Anything you want to change in rstantools before I submit it? We need to get it onto CRAN before the next rstanarm so that the bayes_R2 generic is available to rstanarm, brms, etc.

New version of .travis.yml

Hi,

I have been using the mlysy-rstantools_patch of the repository after being put onto it here to build my new rstan pacakge rater. Overall the branch works great but I've had trouble using the included .travis.yml file. Some issues it has had are:

E: Unable to locate package llvm-5.0-dev
gcc: error: unrecognized command line option ‘-stdlib=libc++’

while building many of the dependencies of devtools

/usr/bin/ld: /usr/local/clang-5.0.0/bin/../lib/LLVMgold.so: error loading plugin: /usr/local/clang-5.0.0/bin/../lib/LLVMgold.so: cannot open shared object file:

while building Rcpp

I understand this may be very low priority but I suspect others will have the same issues especially once this branch is merged into master

Thanks!

Edit: Didn't see #38 before posting this but I will leave it here as it contains more bugs than that issue

rstanarm and brms helpers

@paul-buerkner I think rstanarm and brms should outsource more of their internal helper/utility functions to rstantools. Many are similar and also useful for other developers and it would also simplify the code in rstanarm and brms. What do you think!

my rstan based package cannot be installed on MacOS

Hello,
I have developed a rstan based package (rstan: 2.18.2, my os: ubuntu 18.04.01) but when trying to build the package under macOS I find the following error:

make_cc(commandArgs(TRUE))" stan_files/fit_model.stan
Wrote C++ file "stan_files/fit_model.cc"
Error: unexpected symbol in:
"cat(' ', sep = '
cat(system.file('include"
Execution halted
/usr/local/clang7/bin/clang++ -std=gnu++14 -I"/Users/ripley/R/R-patched/include" -DNDEBUG -I"../inst/include" -I"" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error -I"/Users/ripley/R/test-3.5/BH/include" -I"/Users/ripley/R/test-3.5/Rcpp/include" -I"/Users/ripley/R/test-3.5/RcppEigen/include" -I"/Users/ripley/R/test-3.5/rstan/include" -I"/Users/ripley/R/test-3.5/StanHeaders/include" -I/usr/local/include -fPIC -g -O2 -Wall -pedantic -c stan_files/fit_model.cc -o stan_files/fit_model.o
In file included from stan_files/fit_model.cc:3:
In file included from stan_files/fit_model.hpp:18:
In file included from /Users/ripley/R/test-3.5/rstan/include/rstan/rstaninc.hpp:3:
/Users/ripley/R/test-3.5/rstan/include/rstan/stan_fit.hpp:11:10: fatal error: 'stan/version.hpp' file not found
#include <stan/version.hpp>

Could you please help me with this issue? I cannot see where the error is :-(
Thanks in advance!

Problem with Makevars STANHEADERS_SRC code

Using rstantools 1.5.1 rstan_package_skeleton I'm getting an error in Makevars when trying to build, specifying when

STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(' ', sep = '\\n')" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE), sep = '\\n')" | grep "StanHeaders")

is executed. The error is:

Error: unexpected symbol in:
"cat(' ', sep = '
cat(system.file('include"
Execution halted

This is my sessionInfo():

R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.2

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] rstantools_1.5.1     rstan_2.18.2         StanHeaders_2.18.0-1 ggplot2_3.0.0       

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0         rstudioapi_0.7     bindr_0.1.1        magrittr_1.5       tidyselect_0.2.4   munsell_0.5.0     
 [7] colorspace_1.3-2   R6_2.2.2           rlang_0.2.1        plyr_1.8.4         dplyr_0.7.99.9000  tools_3.5.0       
[13] parallel_3.5.0     pkgbuild_1.0.0     grid_3.5.0         gtable_0.2.0       loo_2.0.0          withr_2.1.2       
[19] matrixStats_0.54.0 yaml_2.2.0         lazyeval_0.2.1     assertthat_0.2.0   tibble_1.4.2       crayon_1.3.4      
[25] processx_3.1.0     bindrcpp_0.2.2     gridExtra_2.3      callr_2.0.4        purrr_0.2.5        inline_0.3.15     
[31] glue_1.3.0         compiler_3.5.0     pillar_1.3.0       scales_0.5.0       stats4_3.5.0       pkgconfig_2.0.1

No leading white space for '#include' of auxilliary stan files

It seems that rstantools::rstan_config() errors that it cannot find the auxiliary file when a stan model in the package has e.g.,

functions {
  #include include/foo.stan
}

The issue appears to be that .make_cc() within rstan_config() uses rstan::stanc() to create the C++ source file, whereas perhaps it should be using rstan::stanc_builder(). Having read the documentation in rstan, I'm not entirely sure what the difference is, as both functions accept the isystem argument, though the function Details only mention #includes via stanc_builder().

On my system (OSX), it seems that either (i) replacing stanc by stanc_builder in .make_cc, or (ii) removing the leading spaces in the code above solves the problem. This was not flagged in the rstantools unit tests, because the relevant file testthat/RStanTest/SimpleModel2.stan omits the leading spaces when calling testthat/RStanTest/helper.stan.

I believe that the preferable solution is (i), save for my confusion about the stanc/stanc_builder distinction. If you agree, then it seems like a very straightforward patch. Happy to do this myself if that would be helpful.

rstantools::loo_pit sometimes returns values larger than 1

@jgabry has access to the data and then should be able to reproduce

mod3 = stan_glmer(log_pm25 ~ log_sat_2014 + (log_sat_2014 | cluster_region),
data=GMs@data)
psis3 <- psislw(-log_lik(mod3))
pit3 <- rstantools::loo_pit(object = posterior_predict(mod3), y = log(GMs@data$pm25), lw = psis3$lw_smooth)

max(pit3)-1
[1] 8.881784e-16

pit values should be between 0 and 1

Don't delete the common_functions.stan file

Hi --

This is just a small issue that could be resolved by adding a sentence to the vignette -- if common_functions.stan is deleted from the chunks folder, then the package will fail to load because of this line in stanmodels.R:

  if (!file.exists(file.path(isystem, "common_functions.stan")))
    isystem <- file.path("inst", "chunks")
  if (!file.exists(file.path(isystem, "common_functions.stan")))
    isystem <- file.path("..", "inst", "chunks")

If the file isn't found, then the script will look in the directory above the current one. I'm not sure why this behavior is in the script, but it should be noted in the package vignette. As a consequence, the other includes in chunks won't be copied over to the new library, and lazy loading will fail with "file not found" errors.

Thanks much,

Bob Kubinec

Confusing SOURCES in makevars.win

Makevars in the default skeleton now simplifies inclusion of sources:

SOURCES = $(wildcard stan_files/*.stan)

but the corresponding line in Makevars.win is highly confusing:

SOURCES = stan_files/bernoulli.stan stan_files/binomial.stan stan_files/continuous.stan stan_files/count.stan stan_files/jm.stan stan_files/lm.stan stan_files/mvmer.stan stan_files/polr.stan

Leftover of some test versions?

directories in step-by-step guide vignette are inconsistent

The instructions in the vignette jump back and forth between assuming that rstanlm is the working directory and assuming that rstanlm is in the working directory.

list.files(all.files = TRUE)
DES <- readLines("DESCRIPTION")
roxygen2::roxygenise(clean=TRUE)
devtools::install(local=FALSE)

versus

cat(readLines("rstanlm/Read-and-delete-me"), sep = "\n")
file.remove('rstanlm/Read-and-delete-me')
# // Save this file as rstanlm/src/stan_files/lm.stan
# Save this file as `rstanlm/R/lm_stan.R`
pkg_file <- readLines(file.path("rstanlm", "R", "rstanlm-package.R"))

Using new version

Hi,

After getting this error:

Error: unexpected symbol in:
"cat(' ', sep = '
cat(system.file('include"
Execution halted

while trying to make a new package skeleton with rstantools. I was told to use a more up to date date branch in this thread in the Stan forums

Branch used: devtools::install_github("stan-dev/rstantools", ref = " c3c59fb")

This works great - i.e. I can build the package, hosted here but I have two questions:

  1. The package structure I got using the more recent branch is very different to the one described in this vignette. Does this represent a progression of the rstantools package or is it a throwback?

  2. Will the branch I am using be merged into rstantools any time soon?

Thanks!

Contradictory statements in Read-and-delete-me

The Read-and-delete-me file says

While developing your package use devtools::install('.', local=FALSE) to reinstall the package AND recompile Stan programs, or set local=FALSE to skip the recompilation.

So... which is it? Does local=FALSE recompile Stan programs or does it skip the recompilation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.