Do you have the package code on GitHub or another public repository somewhere? I can try running R CMD check on it too and see what happens. That’s strange that devtools::check() runs fine but R CMD check errors like that.
This sort of thing has happened to me when R looks for packages in different places, depending on how R was opened. For example, if you did devtools::check() from inside Rstudio, then maybe it is looking for packages in a different folder as compared to the command-line R CMD check.
You might open R from the command line (by typing R), then .libPaths() will show the folders where it is looking for packages (maybe R CMD check only looks in the first folder? not sure). If you do install.packages("rstan") while you are there, it usually gets installed where needed and works. This is maybe not the most elegant solution (you could also point R to the folder where rstan is installed), but possibly the easiest solution.
Before I could get it to run at all I got this error:
ERROR: 'configure' exists but is not executable -- see the 'R Installation and Administration Manual'
I’m not sure why the configure files aren’t executable (I haven’t seen that before) but before I could get it to work I had to open up the terminal cd to the eDNAjoint folder and then change the permissions using:
chmod +x configure
chmod +x configure.win
I would run that just in case and update the files on GitHub if that changes anything before submitting to CRAN.
@edm suggestion was exactly right – I had been working on a remote server where I had some packages in my user library and some packages in my system library. rstan was in my user library, and I assume the build was defaulting to the system library. My solution was just to build the package locally, and the problem went away!
And @jonah thanks for your advice – I just implemented your suggestions.
I think that .libPaths() only shows you the folders where R looks for packages; it doesn’t let you set a folder. I think folders are typically set in R (as opposed to in the package), before you build the package. To set the folder, you can set an environment variable R_LIBS to point at the folder you want. To do this automatically (on linux, at least), I have a file in my home folder called .Renviron with this line:
and then R looks for packages in that folder first.
Another thing that often works is to decide how you want to build the package, then ensure you have updated all your packages under that R instantiation. For example, if you wanted to always build your package from Rstudio, then I’d open Rstudio and ensure all the other packages were installed and updated in Rstudio before I tried to build my package there. So instead of using R_LIBS to set the folder yourself, you use whatever folder Rstudio is already using and make sure the packages are all installed/updated there.