Rstantools rstan_package_skeleton() failing with "Error in getDLLRegisteredRoutines.DLLInfo"

Thanks for the near-instant reply! The repo is here.

It is probably fixed by my PR. The pkgbuild::compile_dll() may or may not work for you depending on whether you use r-devel, but you should be able to R CMD build and R CMD INSTALL it in a separate process.

Thanks. I merged your pull request, and now pkgbuild::compile_dll() gives a slightly different error:

Re-compiling CJStan 
-  installing *source* package 'CJStan' ... (511ms)
   ** libs
   Error in .shlib_internal(args) : 
     C++14 standard requested but CXX14 is not defined
-  removing 'C:/Users/myname/AppData/Local/Temp/RtmpqivfNX/devtools_install_2bbc42412b2b/CJStan'
   In R CMD INSTALL
 Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command error 

I also tried installing the latest rstantools from GH with devtools::install_github("stan-dev/rstantools", build_vignettes = TRUE), and then the error from pkgbuild::compile_dll() is different again:

Re-compiling CJStan 
-  installing *source* package 'CJStan' ... (493ms)
   Error: 'rstan_config' is not an exported object from 'namespace:rstantools'
   Execution halted
   ERROR: configuration failed for package 'CJStan'
-  removing 'C:/Users/myname/AppData/Local/Temp/RtmpIR49KL/devtools_install_35e44bb3024/CJStan'
   In R CMD INSTALL
 Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command error 

In either case roxygen2::roxygenise(clean=TRUE) still fails.

I tried the R CMD build approach (FWIW, I had to google this; I’ve only ever built packages using the Install & Restart button in RStudio before), but that gives the error 'R' is not recognized as an internal or external command, operable program, or batch file.

Oh, and I’m not using r-devel. It’s R version 3.5.3.

To compile something from source on Windows, you will need o

CXX14 = g++

in ~/.R/Makevars. Details here

OK, thanks for bearing with me. (I’m an ecologist, not a computer scientist, and I know very little about C++.) My ~/.R/Makevars had the CXX11FLAGS and CXX14FLAGS, but not the line

CXX14 = g++ -m$(WIN) -std=c++1y

It is now exactly as shown in the Configuration section of the linked vignette, but with -mtune=native in addition to -march=native (per the RStan Getting Started vignette; this has not caused any problems with rstan). However, I’m still getting the same two errors as above, depending on which GitHub version of rstantools I have installed.

I don’t know if this means anything, but I see that at some point these pkgbuild::compile_dll() calls have added several files to /src, including ones called Makevars and Makevars.win.

@ebuhle FWIW, I use R 3.5.3 on Windows, to build a package dependent on rstan. I use the “Install and Restart” button as part of my workflow. And I’ve been finding the following to work…

My ~/.R/Makevars file looks like:

CXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function
CXX14 = $(BINPREF)g++ -m$(WIN) -std=c++1y
CXX11FLAGS=-O3 -Wno-unused-variable -Wno-unused-function

(Perhaps adding the $(BINPREF) will help you, I have no idea).

And when I get the

Error in getDLLRegisteredRoutines.DLLInfo(dll, addNames = FALSE) : 
  must specify DLL via a “DLLInfo” object. See getLoadedDLLs()

error message (which seems to happen quite a lot lately), I do the following…

  • go to Options > Configure Build Tools and then deselect ‘Generate documentation with roxygen’
  • build the package via “Install and Restart” (which seems to create the DLL file ok because roxygen doesn’t get in the way)
  • and then when I want to build the package again with the documentation, but without changing the .stan files or recompiling, I can reselect the ‘Generate documentation with roxygen’ option and click “Install and Restart”.

Thanks for the suggestions. I changed the CXX14 variable in ~/.R/Makevars as shown, leaving the -mtune=native -march=native flags because they seem to speed up execution a bit. But both pkgbuild::compile_dll() and “Install and Restart” still throw the error about

   Error in .shlib_internal(args) : 
     C++14 standard requested but CXX14 is not defined

and roxygen2::roxygenise(clean=TRUE) still chokes. Interestingly, it turns out the “Generate documentation with roxygen” box under Project Options was already deselected (I may have deselected it before, but not in this project), but Configure > Roxygen Options had “Automatically roxygenize when running: _R CMD check _Source and binary package builds” selected. I turned them off; same thing. Tried turning on “Generate documentation…”; nope.

Before rstantools and the official guidelines, I successfully built a rstan-dependent package using a more generic skeleton (Stan files go in /inst/stan and are compiled at runtime), so I may just revert to that approach for now and hope the roxygen2 issues get resolved in the future. But I’d prefer to use the approved structure, plus precompiled models would be very nice.

Do you have both a ~/.R/Makevars and a ~/.R/Makevars.win that are inconsistent with each other?

Good question, but no. (I’m assuming the /src/Makevars and /src/Makevars.win that are created by rstantools are not at issue here.) I also checked to make sure I didn’t somehow have a CXX14 environment variable set.

I tried working through the rstanlm vignette from scratch, using the ref = "c3c59fb" version of rstantools, and noticed a few things that presumably also occurred before, but didn’t stand out to me.

First, remotes::install_github("stan-dev/rstantools", ref = "c3c59fb") produces a bunch of warnings:

Downloading GitHub repo stan-dev/rstantools@c3c59fb
√  checking for file 'C:\Users\myname\AppData\Local\Temp\Rtmp0ycCPr\remotes199c776b2473\stan-dev-rstantools-c3c59fb/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.9000.tar.gz'
   Warning: file 'rstantools/inst/include/sys/configure' did not have execute permissions: corrected
   
* installing *source* package 'rstantools' ...
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package 'rstantools'
    finding HTML links ... done
    bayes_R2                                html  
Rd warning: C:/Users/myname/AppData/Local/Temp/RtmpWkFPhi/R.INSTALL2b0079184739/rstantools/man/bayes_R2.Rd:32: file link 'rstanarm' in package 'rstanarm' does not exist and so has been treated as a topic
Rd warning: C:/Users/myname/AppData/Local/Temp/RtmpWkFPhi/R.INSTALL2b0079184739/rstantools/man/bayes_R2.Rd:36: file link 'rstanarm' in package 'rstanarm' does not exist and so has been treated as a topic
    init_cpp                                html  
    log_lik                                 html  

[a whole bunch of similar warnings]

    rstan_config                            html  
    rstan_package_skeleton                  html  
    finding level-2 HTML links ... done

    rstantools-package                      html  
    use_rstan                               html  
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (rstantools)
In R CMD INSTALL

Second, rstan_package_skeleton(path = 'rstanlm') produces the error about DLLInfo, along with some warnings:

Creating package skeleton for package: rstanlm
Running usethis::create_package ...
✔ Setting active project to 'C:/Users/myname/My Application Data/R/rstanlm'
✔ Creating 'R/'
✔ Creating 'man/'
✔ Writing 'DESCRIPTION'
✔ Writing 'NAMESPACE'
✔ Writing 'rstanlm.Rproj'
✔ Adding '.Rproj.user' to '.gitignore'
✔ Adding '^rstanlm\\.Rproj$', '^\\.Rproj\\.user$' to '.Rbuildignore'
✔ 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()
In addition: Warning messages:
1: In file.remove(file.path(STAN_FILES, "chunks", "license.stan.bak")) :
  cannot remove file 'C:\Users\myname\My Application Data\R\rstanlm/src/stan_files/chunks/license.stan.bak', reason 'No such file or directory'
2: In file.remove(file.path(DIR, "R", "stanmodels.R.bak")) :

But it does “succeed” in producing a package skeleton. The call to roxygenise() still fails, and the call to pkbuild::compile_dll() still gives the error about the C++14 standard.

I had this issue too. I think I’ve fixed it by installing roxygen2 v7.0.2 and calling roxygen2::roxygenise(load_code = "source").