I am developing a package using the RStudio IDE. I have used the Build tab to assist the pkg dev process for years, but I am running into an odd issue recently. When I use the IDE buttons to Check or Test the package, I get a note that two package are not installed when they are indeed installed.
Here's the note I get when trying to check the package.
Below you can see that I have two library paths available and both packages are installed into both libraries. I have no idea how these packages are not being found??? ¯\_(ツ)_/¯
Created on 2023-01-30 with reprex v2.0.2
Additionally, I do add another lib in my project .Rprofile for package dev work (to keep my primary libs clean of dev versions of packages) using devtools::dev_mode(on = TRUE).
I created the Sys.getenv("R_LIBS_USER") folder as you suggested. Now when I open R, the new folder is included in the default libraries. I also copied all packages into the new folder.
Created on 2023-01-30 with reprex v2.0.2
BUT, when I open this Rproj, I have the additional dev folder. and I still get the error that gtsummary and tidyr are not found despite being installed in every lib listed in .libPaths().
Yes, you call dev_mode() in your profile I guess, and it adds C:/Users/SjobergD/R-dev to the library path. For some reason the profile is not used when running the check in RStudio.
Is the dev_mode() call conditional in your profile? Or you always call it?
It's run every time the Rproj is opened. This is what my .Rprofile file looks like.
# this sets the dev folder in the libPath
tryCatch(
devtools::dev_mode(on = TRUE),
error = function(e) invisible()
)
Even if the .Rprofile is not run for IDE submissions of devtools::check(), I don't understand which libraries are active during the IDE check? Since the pkgs are installed in all the libraries, I assume it should find them. (Although, my preference is that the IDE would run .Rprofile so my local env would match the env the IDE-submitted checks are run in.)
Just to rule out that this is an RStudio thing, can you try running devtools::check() from a Windows terminal or cmd window?
There are no issues whendevtools::check() is run interactively in the console. Also no error if it's run from a terminal window with Rscript filename.R where filename.R is a single line with devtools::check().
Try removing the tryCatch() from the profile, I think you would probably want to know about it if the library setup fails.
Issue persists after the tryCatch() is removed. (You're correct that I want to know when devtools::dev_mode() doesn't work, but I keep it because many others fork the repo and don't necessarily have dev mode setup on their machine.)
Thank you again for reviewing these details with me!
So unfortunately this is not going to work with RStudio. You can search the RStudio issues at Issues · rstudio/rstudio · GitHub and report it if it hasn't been reported yet.
A workaround is to modify your library/base/R/Rprofile file within your R installation to add the library to the library path. This file is always loaded.
Since these packages are installed in all the libraries, it's so strange that the packages are not found. I'll file an issue in the GH repo if I don't see a previous posting about it.
Some package must be missing from the system library, I think, or maybe it is broken and cannot be loaded. The system library is always available. (Well, unless you use renv.)