I suspected I had something wrong in my tool chain, so I followed the instructions in this blog post to make sure I was up to date, and reinstalled rstan but I’m still getting the same error.
Is my example too minimal to install, or is there something wrong in my setup?
Operating System: MacOS 10.14.2
RStan Version 2.18.2
Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
Following reinstallation of toolchain and rstan, my ~/.R/Makevars is blank. But the issue was present before this.
Output of devtools::session_info("rstan")
─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 3.5.0 (2018-04-23)
os macOS 10.14.2
system x86_64, darwin15.6.0
ui X11
language (EN)
collate en_GB.UTF-8
ctype en_GB.UTF-8
tz Europe/London
date 2018-12-21
I deleted the package and tried using rstantools::rstan_create_package('junk', stan_files = '~/8schools.stan', rstudio = FALSE) to create the directory structure, but the error is the same.
Back from my Christmas/New Year break and I’ve been trying to get back into this.
As I couldn’t get it working and there was a new version of R, I decided to go for a clean install. Removed R and old packages, installed the new version and then installed packages from scratch.
I still needed the github version of rstantools as above.
devtools::install(local=FALSE)
✔ checking for file ‘/Users/xxxxxx/src/R/rstanlm/DESCRIPTION’ ...
─ preparing ‘rstanlm’:
✔ checking DESCRIPTION meta-information ...
─ cleaning src
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
Removed empty directory ‘rstanlm/man’
Removed empty directory ‘rstanlm/src’
─ building ‘rstanlm_0.0.0.9000.tar.gz’
Warning: invalid uid value replaced by that for user 'nobody'
Warning: invalid gid value replaced by that for user 'nobody'
Running /Library/Frameworks/R.framework/Resources/bin/R CMD INSTALL \
/var/folders/m9/lpvpvw_53qgg5tdwxvgdcylmj6fvfv/T//RtmprnfCv5/rstanlm_0.0.0.9000.tar.gz \
--install-tests
* installing to library ‘/Users/xxxxxx/Library/R/library/3.5’
* installing *source* package ‘rstanlm’ ...
** libs
Error: unexpected symbol in:
"cat(' ', sep = '
cat(system.file('include"
Execution halted
clang++ -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"../inst/include" -I"" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error -I"/Users/xxxxxx/Library/R/library/3.5/BH/include" -I"/Users/xxxxxx/Library/R/library/3.5/Rcpp/include" -I"/Users/xxxxxx/Library/R/library/3.5/RcppEigen/include" -I"/Users/xxxxxx/Library/R/library/3.5/rstan/include" -I"/Users/xxxxxx/Library/R/library/3.5/StanHeaders/include" -I/usr/local/include -fPIC -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o
In file included from RcppExports.cpp:4:
In file included from /Users/xxxxxx/Library/R/library/3.5/RcppEigen/include/RcppEigen.h:25:
In file included from /Users/xxxxxx/Library/R/library/3.5/RcppEigen/include/RcppEigenForward.h:25:
In file included from /usr/local/clang6/include/c++/v1/iterator:416:
In file included from /usr/local/clang6/include/c++/v1/iosfwd:90:
/usr/local/clang6/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
^~~~~~~~~
1 error generated.
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘rstanlm’
* removing ‘/Users/xxxxxx/Library/R/library/3.5/rstanlm’
Trying to run roxygen2::roxygenise(clean = TRUE) before the install gives the error which had resulted in installing rstantools from github.
Not sure what to try next. Anybody have any more suggestions?
devtools::install(local = FALSE)
✔ checking for file ‘/Users/xxxxxx/src/R/rstanlm/DESCRIPTION’ ...
─ preparing ‘rstanlm’:
✔ checking DESCRIPTION meta-information ...
─ cleaning src
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
Removed empty directory ‘rstanlm/man’
─ building ‘rstanlm_0.0.0.9000.tar.gz’
Warning: invalid uid value replaced by that for user 'nobody'
Warning: invalid gid value replaced by that for user 'nobody'
Running /Library/Frameworks/R.framework/Resources/bin/R CMD INSTALL \
/var/folders/m9/lpvpvw_53qgg5tdwxvgdcylmj6fvfv/T//RtmpqQe7Sh/rstanlm_0.0.0.9000.tar.gz \
--install-tests
* installing to library ‘/Users/xxxxxx/Library/R/library/3.5’
* installing *source* package ‘rstanlm’ ...
** libs
Error: unexpected symbol in:
"cat(' ', sep = '
cat(system.file('include"
Execution halted
clang++ -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"../inst/include" -I"" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error -I"/Users/xxxxxx/Library/R/library/3.5/BH/include" -I"/Users/xxxxxx/Library/R/library/3.5/Rcpp/include" -I"/Users/xxxxxx/Library/R/library/3.5/RcppEigen/include" -I"/Users/xxxxxx/Library/R/library/3.5/rstan/include" -I"/Users/xxxxxx/Library/R/library/3.5/StanHeaders/include" -I/usr/local/include -fPIC -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o
In file included from RcppExports.cpp:4:
In file included from /Users/xxxxxx/Library/R/library/3.5/RcppEigen/include/RcppEigen.h:25:
In file included from /Users/xxxxxx/Library/R/library/3.5/RcppEigen/include/RcppEigenForward.h:25:
In file included from /usr/local/clang6/include/c++/v1/iterator:416:
In file included from /usr/local/clang6/include/c++/v1/iosfwd:90:
/usr/local/clang6/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
^~~~~~~~~
1 error generated.
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘rstanlm’
* removing ‘/Users/xxxxxx/Library/R/library/3.5/rstanlm’
I’ve just been looking at c3c59fb on Github - I had tried that fix already. It lead to the "cat(' ', sep = ' problem going away but instead led to a lot of weird compiler warnings… Odd that it has different effect when in rstantools itself.
I’m now playing around with that branch - it seems that rstan_create_package uses usethis and so does create an R.proj file but rstan_package_skeleton uses the base package.skeleton and so doesn’t.
I don’t really understand the differences between these functions…
Sorry to bug you but when I create a rstan project with rstan_create_package I get a Read-and-delete-me-file containing the following:
Stan-specific notes:
* All '.stan' files containing stanmodel definitions must be placed in 'inst/stan'.
* Additional files to be included by stanmodel definition files
(via e.g., #include "mylib.stan") must be placed in any subfolder of 'inst/stan'.
* Additional C++ files needed by any '.stan' file must be placed in 'inst/include',
and can only interact with the Stan C++ library via '#include' directives
placed in the file 'inst/include/stan_meta_header.hpp'.
* The precompiled stanmodel objects will appear in a named list called 'stanmodels',
and you can call them with e.g., 'rstan::sampling(stanmodels$foo, ...)'
This contradicts the information in the Step by step guide for creating a package that depends on RStan vignette. Which should I follow? (Happy to fix this with a pull request if that would be helpful)
Just to confirm that using the above (minus the space before the c3c59fb) allowed me to create and install the rstanlm package from the vignette without error.
There were a lot of compiler warnings though, and I think all of them report a -W<something> compiler setting. Are these avoidable through .R/Makevars? And would this be recommended?
I can confirm that I can also build the package in the vignette - following the instructions in the Read-and-delete-me this branch created. I also get, however, all the nasty compiler warnings. A sample:
/mat/fun/autocorrelation.hpp:18:8: warning: function 'fft_next_good_size' is not needed and will not be emitted [-Wunneeded-internal-declaration]
size_t fft_next_good_size(size_t N) {