Installation of package had non-zero exit status

Hello, Ive been getting errors every time I try and install any packages into R. Ive looked through every page online and have updated Rstudio (1.3.1093) and my Mac to Big Sur (11.0.1) and neither have helped.

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace ‘rlang’ 0.3.1 is being loaded, but >= 0.4.6 is required
ERROR: lazy loading failed for package ‘tidyselect’

  • removing ‘/Users/jameshallam/Library/R/3.4/library/tidyselect’
  • restoring previous ‘/Users/jameshallam/Library/R/3.4/library/tidyselect’
    Warning in install.packages :
    installation of package ‘tidyselect’ had non-zero exit status
    ERROR: dependencies ‘lifecycle’, ‘pillar’ are not available for package ‘tibble’
  • removing ‘/Users/jameshallam/Library/R/3.4/library/tibble’
    Warning in install.packages :
    installation of package ‘tibble’ had non-zero exit status
    ERROR: dependencies ‘lifecycle’, ‘tibble’ are not available for package ‘dplyr’
  • removing ‘/Users/jameshallam/Library/R/3.4/library/dplyr’
    Warning in install.packages :
    installation of package ‘dplyr’ had non-zero exit status
    ERROR: dependencies ‘dplyr’, ‘tibble’, ‘lifecycle’ are not available for package ‘tidyr’
  • removing ‘/Users/jameshallam/Library/R/3.4/library/tidyr’
    Warning in install.packages :
    installation of package ‘tidyr’ had non-zero exit status
    ERROR: dependencies ‘dplyr’, ‘tibble’, ‘tidyr’ are not available for package ‘broom’
  • removing ‘/Users/jameshallam/Library/R/3.4/library/broom’
    Warning in install.packages :
    installation of package ‘broom’ had non-zero exit status
    ERROR: dependencies ‘tidyr’, ‘broom’, ‘tibble’, ‘dplyr’, ‘car’ are not available for package ‘rstatix’
  • removing ‘/Users/jameshallam/Library/R/3.4/library/rstatix’
    Warning in install.packages :
    installation of package ‘rstatix’ had non-zero exit status

This is a section of the error. I'm not sure if this is just a Mac glitch. I've tried installing the packages one at a time and this doesn't work either.

Any help would be appreciated.

The error message is asking you to update the rlang package. Restart your R session and try installing the latest version with

install.packages("rlang")

Note: Since you are using an old R version (3.4), most likely you are going to have to compile from source, which means you need to install the recommended development tools for macOS systems.

As I said, for installing packages from source you need the recommended development tools for macOS systems (the error message refers XCode). Although, I would recommend updating your R version so you can have access to precompiled binaries.

Yes downloading Xcode helped. This seems like a large installation in order for this to work.

Even after installing Xcode and updating R to 4.0.3, I am still unable to install packages in Rstudio.

You need to be more specific, you should be getting a different error message at least, post it here.

Installing package into ‘/Users/jameshallam/Library/R/3.4/library’
(as ‘lib’ is unspecified)

Warning in install.packages :
dependencies ‘cowplot’, ‘car’ are not available
also installing the dependencies ‘rstatix’, ‘ggpubr’

This seems self explanatory, you are missing package dependencies, so you have to install them.

Also, I should note that you are still using the old 3.4 R version so installing packages is going to be much harder for you since most of them are going to require compilation.

yes but I am unable to install these dependencies, It says they need 3.5.0 or newer but I have fully updated R Studio.

You need to update R not RStudio, they are not the same thing.

My R console is on version 4.0.3.

Then this is an old error message? What is the error message you are getting now?

This says 3.4 but Ive just reinstalled the 4.0.3 version.

Installing package into ‘/Users/jameshallam/Library/R/3.4/library’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘cow’ is not available (for R version 3.4.3)
Error in readRDS(pfile) :
cannot read workspace version 3 written by R 4.0.3; need R 3.5.0 or newer

It seems you have both versions installed in your system but it is configured to use the older one, sadly I can't tell you how to solve this since I'm not a macOS user but hopefully someone else will.

Hi @JamesHallam,

There are a couple of things to check.

First, when in R, what do you get when you type in .libPaths()?

If you are still getting something like

[1] "/Users/jameshallan/Library/R/3.5/library"
[2] "/Library/Frameworks/R.framework/Versions/4.0/Resources/library"

then do you have any .libPaths setting specified in a startup profile like
~/.Rprofile that are overriding the defaults?

Also, if you type Sys.getenv("R_LIBS_USER"), what do you get?

I think when I updated my R version, I had to manually create a folder called 4.0 in ~/Library/R
so that .libPaths could find it. Once you get .libPaths pointing to the right directory, you have a couple of methods of updating packages.

Option 1: The clean way - re-install all the packages from scratch.
Option 2. The quick and dirty way: Rename the 3.5 folder to 4.0 and run update.packages(checkBuilt = TRUE).

when I type .libpaths() In my Studio console I get:
"/Users/jameshallam/Library/R/3.4/library" "/Library/Frameworks/R.framework/Versions/3.4/Resources/library"

when I type in Sys.getenv("R_LIBS_USER") I get:
"~/Library/R/3.4/library"

Okay thank you for your help.

How can I change the directory?

Hmm. The only thing I can think of this point is manually add a "4.0" folder
inside of /Users/jameshallam/Library/R/, make sure you don't have any Rprofile or Rprofile.site files lurking around your home folder and download and reinstall a new copy of the R installer.

To check for Rprofile files that might affect startup:

(Taken from stackover question https://stackoverflow.com/questions/13735745/locate-the-rprofile-file-generating-default-options)

Within R, type

candidates <- c(Sys.getenv("R_PROFILE"),
file.path(Sys.getenv("R_HOME"), "etc", "Rprofile", "Rprofile.site"),
Sys.getenv("R_PROFILE_USER"),
file.path(getwd(), ".Rprofile"))

Filter(file.exists, candidates)

If the file list is not empty, check those files to see if you have "hardwired"
.libPaths pointing to the old version.

If this filelist is empty, if you reinstall the CRAN version R after adding in the folder "4.0" inside of /Users/jameshallam/Library/R/, that should be able to be picked up by .libPaths.

Hello, thank you for your help again.

I have a 3.4 folder inside of /Users/jameshallam/Library/R/.

Am I okayed delete this and reinstall 4.0?

I also get "character(0)" from the input you suggested.

Hi @JamesHallam ,
Thanks for the update.

If you reinstall 4.0, the R packages from 3.4 will still be in "~/Library/R/3.4/library".

What I usually do is upgrade my version of R, but before I delete the old version folder, I save the names of the packages from the old version, and reinstall the packages in the folder for the new version.

oldpkgs <- installed.packages(lib.loc = "~/Library/R/3.4/library")
install.packages(oldpkgs[, 1], lib = "~/Library/R/4.0/library")

After this, it's safe to delete the old folder ~/Library/R/3.4

HTH