macos Package Development: install error

Error Information:

==> R CMD INSTALL --preclean --no-multiarch --with-keep.source rstudioProjectTemplate

* installing to library ‘/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library’
Error:
! ERROR: no permission to install to directory ‘/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library’
Backtrace:
    ▆
 1. └─tools:::.install_packages()

Exited with status 1.

Description of issue

I'm trying to build a local package using the "CMD-Shift-B" shortcut on macos Ventura 13.1. The error is clearly related to not having the proper permissions on the directory: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library. I know how to change permissions, but am posting here because I haven't run into this problem before. If anyone can explain what might have changed (my computer/settings, R, RStudio, ...) I would appreciate it. I'm hesitant to change what appear to be default permissions on a directory within /Library.

System Information:

  • OS Version: macos 13.1 (Ventura)
  • R Version: 4.2.2
  • RStudio Edition: Desktop
  • RStudio Version: RStudio 2022.12.0+353 "Elsbeth Geranium" Release (7d165dcfc1b6d300eb247738db2c7076234f6ef0, 2022-12-03) for macOS
    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2022.12.0+353 Chrome/102.0.5005.167 Electron/19.1.3 Safari/537.36

Good call. I've had more than a few griefs doing install to the system tree.

There should be the same command line argument lib where you can direct the .libPaths() setting to put it into a different user-specific site-library (haven't checked).

Generally, be aware that

is broken (open issued on github) because it overrides $PATH, so that nothing in /usr/bin can be invoked, such as install[update].packages(). Works fine, though from the R GUI app or terminal (even the terminal pane in the IDE).

Thanks @technocrat, I believe you're referring to: Problems with C++ compiler toolchain for R on Mac in newer Rstudio versions · Issue #12529 · rstudio/rstudio · GitHub.

1 Like

Solution:

  1. Choose Build | Configure Build Tools ... from the menu
  2. Add --library=/Users/<USERACCOUNT>/Library/R/arm64/4.2/library to the "Install Package -- R CMD INSTALL additional options:" text box. Where, the path provided is based on your setup. I just copied the first entry from .libPaths().

Many thanks.

1 Like

@orderlyquant I don't think that's a good fix in general. I'd start by inspecting .libPaths() and confirming that's correct.

@technocrat My team mostly works on OS X, and most of us have upgraded to ventura, and I'm not aware of any problems. I don't want to dismiss any your problems that you might be experiencing but at the same time I don't think you should assume it affects everyone.

This isn't precisely what's being asked, but this is a great opportunity to make the recommendation that folks use a user library for add-on packages. I highly recommend a lifestyle where only the base and recommended packages (the ones that "come with R") live in the system library. And everything you install from CRAN, GitHub, etc. gets installed into a user library.

On macOS, right after you install R, do this before embarking on any package installation:

fs::dir_create(Sys.getenv("R_LIBS_USER"))

This creates an empty user library at the default location where expects to find it. And given its existence, R's default behaviour is to install add-on packages there. Done!

This is often covered in the "What They Forgot to Teach You About R Workshop", so you can read a bit more in this resource that contains a subset of the workshop materials:

It's hard to say exactly why OP is experiencing problems and I (who did a clean install of Ventura about 10 days ago) am not. Maybe there's a problem with RStudio? But maybe I'm less vulnerable to that given that I treat the system library as untouchable. Empirically, I can just say this lifestyle tends to work better for me and other package devs.

1 Like

Do you get the same problem with R --vanilla? What does Sys.getenv("TAR") return?

Sys.which("tar") works for me:

Sys.which("tar")
#>            tar 
#> "/usr/bin/tar"

Created on 2023-01-18 with reprex v2.0.2

Where are you seeing that PATH variable?

@hadley, my library paths are as:

R > .libPaths()
[1] "/Users/XXX/Library/R/arm64/4.2/library"                      
[2] "/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library"

and as per @jennybryan,

R > fs::dir_exists(Sys.getenv("R_LIBS_USER"))
/Users/XXX/Library/R/arm64/4.2/library 
                                  TRUE 

So the original CMD-Shift-B error:

==> R CMD INSTALL --preclean --no-multiarch --with-keep.source oq_project_template

* installing to library ‘/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library’
Error:
! ERROR: no permission to install to directory ‘/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library’
Backtrace:
    ▆
 1. └─tools:::.install_packages()

Exited with status 1.

confuses me, as I would have expected it to try the R_LIBS_USER directory first as it comes first in .libPaths(). Perhaps the RStudio CMD-Shift-B shortcut is operating in an environment where .libPaths() has a different value?

@orderlyquant @technocrat how did you install R?

I used the CRAN disk image found at R for macOS.

Have you ever used rig? What does Sys.getenv("R_LIBS") return?

Yes, I've used rig,

R > Sys.getenv("R_LIBS")
[1] ""

Looking at my shell history, looks like I ran:

rig add release

in the past couple of weeks. That probably overwrote the disk image install...

There was a bug in rig that incorrectly set the library permissions; if you install the latest version it should correct it.

2 Likes

Thanks, @hadley, I will investigate. I installed rig after the fix was supposedly in place (when asking rig to update, it returned with a response that I was already on the latest version). Perhaps it's due to the fact that R 4.2 was already installed on my machine.

I'll troubleshoot from here, as it doesn't appear to be an RStudio issue. Many thanks :pray: for pointing me in the right direction.

Yeah, it is probably because you don't have a user library for that R version, and the system library is not writeable.

Check the permissions of the libraries, and create the user libraries if they don't exist.

Installed to Ventura/M1 with normal .pkg

There are very few ways that RStudio modifies your execution environment, even fewer that apply by default. You might try temporarily renaming your global RStudio prefs file to see if that resolves the problem.

Thanks, @hadley, @gabor, @jennybryan. I completely removed R4.2 from my system, including removing the user library, then re-installed with rig add release. I can confirm that:

  • all permissions are properly set
  • packages are being installed in the Sys.getenv("R_LIBS_USER") directory
  • CMD-Shift-B is now working as previously

I appreciate all the help and added a lot to my WTF understanding.

For me, the case is closed. :pray:

2 Likes