2

I have experienced the following problem during the process of building my package. I tried to search for a solution but was unsuccessful. In order to make the error reproducible, I present a minimal package that could generate the same error.

I started a package with the name mypkg, then I use usethis::use_rcpp and usethis::use_rcpp_armadillo. After that I add the following script in \src folder (which is copied from internet)

#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
arma::vec getEigenValues(arma::mat M) {
  return arma::eig_sym(M);
}

After that, I add an R shell to export the function using Roxygen. So far the package can be successfully documented and built. Then I continue to add features of Rstan by using rstantools::use_rstan, and follow the steps on Step by step guide for creating a package that depends on RStan, and create lm.stan and lm_stan.R as instructed. Then I built the package again but it throws out an error. Here are the results of executing .Last.error.trace

 1. devtools:::document()
 2. withr::with_envvar(r_env_vars(), roxygen2::roxygenise(pkg$path,  ...
 3. base:::force(code)
 4. roxygen2::roxygenise(pkg$path, roclets, load_code = load_code)
 5. roxygen2:::load_code(base_path)
 6. pkgload::load_all(path, helpers = FALSE, attach_testthat = FALSE)
 7. pkgbuild::compile_dll(path, quiet = quiet)
 8. pkgbuild:::install_min(path, dest = install_dir, components = "libs",  ...
 9. pkgbuild:::rcmd_build_tools("INSTALL", c(path, paste("--library=",  ...
 10. pkgbuild:::with_build_tools(callr::rcmd_safe(..., env = env,  ...
 11. withr::with_path(rtools_path(), code)
 12. base:::force(code)
 13. callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE,  ...
 14. callr:::run_r(options)
 15. base:::with(options, with_envvar(env, do.call(processx::run,  ...
 16. base:::with.default(options, with_envvar(env, do.call(processx::run,  ...
 17. base:::eval(substitute(expr), data, enclos = parent.frame())
 18. base:::eval(substitute(expr), data, enclos = parent.frame())
 19. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmdargs,  ...
 20. base:::force(code)
 21. base:::do.call(processx::run, c(list(bin, args = real_cmdargs,  ...
 22. (function (command = NULL, args = character(), error_on_status = TRUE,  ...
 23. throw(new_process_error(res, call = sys.call(), echo = echo,  ...
x System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr (last 10 lines):
E> In file included from  C:/Users/Jasper/Documents/R/win-library/3.6/rstan/include/rstan/rstaninc.hpp:3:0,
E>                  from stanExports_lm.h:20,
E>                  from stanExports_lm.cc:5:
E> C:/Users/Jasper/Documents/R/win-library/3.6/rstan/include/rstan/stan_fit.hpp:11:28: fatal error: stan/version.hpp: No such file or directory 
E>  #include <stan/version.hpp> 
E>                            ^ 
E> compilation terminated.
E> make: *** [C:/PROGRA~1/R/R-36~1.2/etc/x64/Makeconf:213: stanExports_lm.o] Error 1 
E> ERROR: compilation failed for package 'mypkg' 
E> * removing 'C:/Users/Jasper/AppData/Local/Temp/RtmpwXHySZ/devtools_install_1d18454066b0/mypkg'

Could anyone suggest what the problem is? Here is my makevars file

CXX_STD = CXX11
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

However, when I follow the steps of the guide to create a package just with Rstan, it could be successfully built, but not when I also want to use RcppArmadillo.

Thank you very much for your kind help!!

JKL
  • 21
  • 1

0 Answers0