Is there any way to tell RStudio where to look for R packages?

When I try and build my package and at the same time generate documentation, I see:

Error in (function (dep_name, dep_ver = NA, dep_compare = NA)  : 
  Dependency package tidyr not available.
Calls: suppressPackageStartupMessages ... <Anonymous> -> load_all -> load_imports -> mapply -> <Anonymous>
Execution halted

Exited with status 1.

I think I figured out that this is happening when I build my package because I don't use the standard R package directory. But, I only got the above error because I started following the second answer to second StackOverflow question linked below. I used to see that devtools wasn't installed. But installing it on a vanilla R call made that work. Is there now way to just make Rstudio use whatever R package locations are in .libPaths?

1 Like

Where are you telling R to use a custom library path? What are your library paths (output of .libPaths())?

RStudio passes the library to be used down to R by setting the R_LIBS_USER environment variable before launching R, and does so with R --vanilla.

Also, how exactly are you trying to build the package -- are you clicking Build and Reload in the Build pane, or otherwise?

I have in my .Rprofile custom logic for setting .libPaths differently depending on the detected version of R and the detected operating system. I was using it to let me drag and drop my .Rprofile across a few computers. I'm guessing this may be throwing me a curve ball? Note: I am working from the RStudio server edition.

Yes, I was trying to do everything from the Build and Reload pane. I was eager to see how much I could do with the GUI instead of document(); build(); install.packages(...).

Addendum: I tried commenting that part out of my .Rprofile and setting R_LIBS_USER in my .profile file. RStudio server edition doesn't seem to re-source environment variables when starting new sessions.

I had a dependency problem for MONTHS and couldn't update my Shiny app.

I just worked around it by loading the dependencies accessing R in the terminal. From there, Rstudio found them. In your case, you'd have to open terminal, type R, and run install.packages("tidyr"), then you should be able to go back into Rstudio and access it there.

Kevin, it maybe the way Rstudio is loading dependencies with Kite-Eating Tree. I was sure Thomas Lumley would be able to solve my problem in early Feb but he was totally stumped.

I found a way around the problem by creating a symbolic link between the default location and my working package directory.