Problem creating an rstan package in R 4.1.1?

I upgraded to the latest version of R, R 4.1.1, and I am having trouble with my stan packages. I will start with a completely new package

library("rstantools")
rstan_create_package(path = 'testP')

and then within the resulting package I just do the following:

> devtools::load_all()
ℹ Loading testP
Re-compiling testP
─  installing *source* package ‘testP’ ...
   ** using staged installation
─  DONE (testP) (1.7s)
> devtools::document()
ℹ Updating testP documentation
ℹ Loading testP
Re-compiling testP
─  installing *source* package ‘testP’ ...
   ** using staged installation
─  DONE (testP) (1.8s)
Writing NAMESPACE
Writing testP-package.Rd
> devtools::load_all()
ℹ Loading testP
Re-compiling testP
─  installing *source* package ‘testP’ ...
   ** using staged installation
─  DONE (testP) (1.8s)
Error in getDLLRegisteredRoutines.DLLInfo(dll, addNames = FALSE) : 
  must specify DLL via a “DLLInfo” object. See getLoadedDLLs()
> 

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

I am using MacOS Catalina 10.15.7 on a MacBook Pro. And I tried the same thing on a Linux machine and got the same error.

I have no idea what is going on. Any help appreciated.

I am including the session information for the Mac just in case:

> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/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     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7           lattice_0.20-44      prettyunits_1.1.1    ps_1.6.0             digest_0.6.27       
 [6] assertthat_0.2.1     rprojroot_2.0.2      utf8_1.2.2           V8_3.4.2             R6_2.5.1            
[11] stats4_4.1.1         ggplot2_3.3.5        pillar_1.6.2         rlang_0.4.11         curl_4.3.2          
[16] rstudioapi_0.13      callr_3.7.0          Matrix_1.3-4         desc_1.3.0           devtools_2.4.2      
[21] stringr_1.4.0        RcppEigen_0.3.3.9.1  loo_2.4.1            munsell_0.5.0        xfun_0.25           
[26] compiler_4.1.1       rstan_2.21.2         pkgconfig_2.0.3      pkgbuild_1.2.0       rstantools_2.1.1    
[31] tidyselect_1.1.1     tibble_3.1.4         gridExtra_2.3        roxygen2_7.1.1       codetools_0.2-18    
[36] matrixStats_0.60.1   fansi_0.5.0          crayon_1.4.1         dplyr_1.0.7          withr_2.4.2         
[41] commonmark_1.7       BH_1.75.0-0          grid_4.1.1           jsonlite_1.7.2       gtable_0.3.0        
[46] lifecycle_1.0.0      DBI_1.1.1            magrittr_2.0.1       StanHeaders_2.21.0-7 scales_1.1.1        
[51] RcppParallel_5.1.4   stringi_1.7.4        cli_3.0.1            cachem_1.0.6         fs_1.5.0            
[56] remotes_2.4.0        testthat_3.0.4       xml2_1.3.2           ellipsis_0.3.2       generics_0.1.0      
[61] vctrs_0.3.8          tools_4.1.1          glue_1.4.2           purrr_0.3.4          testP_0.0.0.9000    
[66] processx_3.5.2       pkgload_1.2.1        parallel_4.1.1       fastmap_1.1.0        inline_0.3.19       
[71] colorspace_2.0-2     sessioninfo_1.1.1    memoise_2.0.0        knitr_1.33           usethis_2.0.1       
> 

Any help appreciated. This is happening in both Mac with R 4.1.1 and Linux with R 4.1.0

I just got the same error using Linux and R 4.1.0:

rstan_create_package(path = 'testPackage') 

and then:

> library(devtools)                                                                                          
Loading required package: usethis                                                                            
> devtools::document()                                                                                       
ℹ Updating testPackage documentation                                                                         
ℹ Loading testPackage                                                                                        
Re-compiling testPackage                                                                                     
─  installing *source* package ‘testPackage’ ...                                                             
   ** using staged installation                                                                              
─  DONE (testPackage) (2.4s)                                                                                 
Writing NAMESPACE                                                                                            
Writing testPackage-package.Rd                                                                               
> devtools::load_all()                                                                                       
ℹ Loading testPackage                                                                                        
Re-compiling testPackage                                                                                     
─  installing *source* package ‘testPackage’ ...                                                             
   ** using staged installation                                                                              
─  DONE (testPackage) (2.4s)                                                                                 
Error in getDLLRegisteredRoutines.DLLInfo(dll, addNames = FALSE) :                                           
  must specify DLL via a “DLLInfo” object. See getLoadedDLLs()                                               
>                                                         

I am still getting the error

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

Should I downgrade? I can’t use rstan.

Can you try with the development version of rstantools?

if (!require("remotes")) {
  install.packages("remotes")
}
  
remotes::install_github("stan-dev/rstantools")

Thank you very much for your reply. It did not do anything:

> devtools::load_all()
ℹ Loading testDeleteme
Re-compiling testDeleteme
─  installing *source* package ‘testDeleteme’ ...
   ** using staged installation
─  DONE (testDeleteme) (2s)
> devtools::document()
ℹ Updating testDeleteme documentation
ℹ Loading testDeleteme
Re-compiling testDeleteme
─  installing *source* package ‘testDeleteme’ ...
   ** using staged installation
─  DONE (testDeleteme) (1.7s)
Writing NAMESPACE
Writing testDeleteme-package.Rd
> devtools::load_all()
ℹ Loading testDeleteme
Re-compiling testDeleteme
─  installing *source* package ‘testDeleteme’ ...
   ** using staged installation
─  DONE (testDeleteme) (1.7s)
Error in getDLLRegisteredRoutines.DLLInfo(dll, addNames = FALSE) : 
  must specify DLL via a “DLLInfo” object. See getLoadedDLLs()

This happened both on Mac and Linux. Could it be something with the documentation package (I think it’s roxygen?)

And if I try to do devtools::check on one of my old packages (which was working before) now it crashes RStudio on the Mac…

I noticed symptoms of this first during the recent StanConnect event when I was trying to run the examples and started to get strange errors.

Actually, neither the development version of rstan or rstantools did not really do anything. Do you have any suggestions on where I can look to debug this better? Or what this might be related to? Not sure how to move forward with this and it happens on both Mac and Linux.

Ah, the issue is that R is trying to load functions when none exist. If you add a stan model to the inst/stan subdirectory, then the package is created and loads without issue. Make sure you follow the steps from the vignette for the rest: Step by step guide for creating a package that depends on RStan