rstudio / renv

renv: Project environments for R.
https://rstudio.github.io/renv/
MIT License
982 stars 153 forks source link

Unable to install packages in environment #1928

Open adamhsparks opened 1 month ago

adamhsparks commented 1 month ago

I'm attempting to use {renv} for an analysis project that I am currently handling. Our university policy dictates that the data must be stored on a specific shared drive that is mounted (on my Mac) by Samba shares.

However, I find myself unable to actually use {renv} in this setting. Attempts to install packages frequently fail with an error.

> renv::install("janitor")
# Downloading packages -------------------------------------------------------
- Downloading janitor from CRAN ...             OK [280.5 Kb in 1.3s]
- Downloading snakecase from CRAN ...           OK [156.8 Kb in 1.1s]
Successfully downloaded 2 packages in 8 seconds.

The following package(s) will be installed:
- janitor   [2.2.0]
- snakecase [0.11.1]
These packages will be installed into "~/Library/Drive-Mappings/.../renv/library/macos/R-4.4/aarch64-apple-darwin20".

Do you want to proceed? [Y/n]: y

# Installing packages --------------------------------------------------------
- Installing snakecase ...                      FAILED
Error: Error installing package 'snakecase':
=====================================

Error: ERROR: cannot cd to directory ‘/Users/283204f/Library/Drive-Mappings/.../renv/staging/1’
install of package 'snakecase' failed [error code 1]
Traceback (most recent calls last):
12: renv::install("janitor")
11: renv_install_impl(records)
10: renv_install_staged(records)
 9: renv_install_default(records)
 8: handler(package, renv_install_package(record))
 7: renv_install_package(record)
 6: withCallingHandlers(renv_install_package_impl(record), error = function(e) writef("FAILED"))
 5: renv_install_package_impl(record)
 4: r_cmd_install(package, path)
 3: r_exec_error(package, output, "install", status)
 2: abort(all)
 1: stop(fallback)

Which is frustrating since I can't find any reason for this. I'm able to cd in the terminal to this directory and browse it using Finder.

kevinushey commented 1 month ago

As a workaround, you could try setting:

RENV_CONFIG_INSTALL_TRANSACTIONAL = FALSE

in your project .Renviron. That will tell renv to eschew the use of the 'staging' directory during package installation.

adamhsparks commented 4 weeks ago

Thank you, @kevinushey, that worked perfectly as far as I can tell.

adamhsparks commented 4 weeks ago

Spoke too soon. I thought it worked, but alas, no.

Some packages will install, while others won't.

I think I'll be OK with the current project, but it would be good to know how to deal with this for future work.

adamhsparks commented 4 weeks ago

I think that using renv::hydrate() gets me around the problem installing in this environment.

kevinushey commented 1 week ago

Sorry for the late response. Fixing this seems like it may be challenging, as the installation failure is happening in R CMD INSTALL itself, so internally something that R is trying to do to install the package therein is failing.

Possibly we could alleviate the issue by installing the package into a separate temporary location, and then moving the installed package to the final location, but I'm not positive that would help. You could try setting this environment variable:

RENV_PATHS_LIBRARY_STAGING = /tmp

(or some other appropriate location) and see if that helps.