Errors installing ggplot2

Hi all,

I'd like to express my thanks in advance for your help. I have been attempting to install the package "ggplot2" for two weeks now in RStudio, and cannot figure out my non-zero exit status errors. I have posted the resulting error code at the end of this message. I have successfully installed some packages, but have failed to install ggplot2 and plotly. I have an assignment due using these packages tonight and would greatly appreciate any insight you can give.

Code and error output:
Code: install.packages("ggplot2", dependencies = TRUE)
Error Output:

> install.packages("ggplot2", dependencies = TRUE)
also installing the dependencies ‘cli’, ‘rlang’, ‘lifecycle’, ‘scales’


  There are binary versions available but the source versions are later:
          binary source needs_compilation
cli        3.2.0  3.4.1              TRUE
rlang      1.0.2  1.0.6              TRUE
lifecycle  1.0.1  1.0.3             FALSE
scales     1.1.1  1.2.1             FALSE
ggplot2    3.3.5  3.3.6             FALSE

Do you want to install from sources the packages which need compilation? (Yes/no/cancel) Yes
installing the source packages ‘cli’, ‘rlang’, ‘lifecycle’, ‘scales’, ‘ggplot2’

trying URL 'http://archive.linux.duke.edu/cran/src/contrib/cli_3.4.1.tar.gz'
Content type 'application/octet-stream' length 540044 bytes (527 KB)
==================================================
downloaded 527 KB

trying URL 'http://archive.linux.duke.edu/cran/src/contrib/rlang_1.0.6.tar.gz'
Content type 'application/octet-stream' length 742508 bytes (725 KB)
==================================================
downloaded 725 KB

trying URL 'http://archive.linux.duke.edu/cran/src/contrib/lifecycle_1.0.3.tar.gz'
Content type 'application/octet-stream' length 106854 bytes (104 KB)
==================================================
downloaded 104 KB

trying URL 'http://archive.linux.duke.edu/cran/src/contrib/scales_1.2.1.tar.gz'
Content type 'application/octet-stream' length 270609 bytes (264 KB)
==================================================
downloaded 264 KB

trying URL 'http://archive.linux.duke.edu/cran/src/contrib/ggplot2_3.3.6.tar.gz'
Content type 'application/octet-stream' length 3061989 bytes (2.9 MB)
==================================================
downloaded 2.9 MB

* installing *source* package ‘cli’ ...
** package ‘cli’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
ERROR: compilation failed for package ‘cli’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/cli’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/cli’
Warning in install.packages :
  installation of package ‘cli’ had non-zero exit status
* installing *source* package ‘rlang’ ...
** package ‘rlang’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
ERROR: compilation failed for package ‘rlang’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rlang’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rlang’
Warning in install.packages :
  installation of package ‘rlang’ had non-zero exit status
* installing *source* package ‘lifecycle’ ...
** package ‘lifecycle’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  namespace ‘rlang’ 1.0.2 is being loaded, but >= 1.0.6 is required
Calls: <Anonymous> ... withCallingHandlers -> loadNamespace -> namespaceImport -> loadNamespace
Execution halted
ERROR: lazy loading failed for package ‘lifecycle’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/lifecycle’
Warning in install.packages :
  installation of package ‘lifecycle’ had non-zero exit status
ERROR: dependency ‘lifecycle’ is not available for package ‘scales’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/scales’
Warning in install.packages :
  installation of package ‘scales’ had non-zero exit status
ERROR: dependency ‘scales’ is not available for package ‘ggplot2’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/ggplot2’
Warning in install.packages :
  installation of package ‘ggplot2’ had non-zero exit status

The downloaded source packages are in
	‘/private/var/folders/sr/02bnxzdx0hvcp6c37xfhlf300000gn/T/Rtmpje9xhl/downloaded_packages’
> library(ggplot2)
Error in library(ggplot2) : there is no package called ‘ggplot2’

Try installing the cli package first.

1 Like

On macOS, when answering Yes, compilation failures are common. If at first you don’t succeed, just say “No.”

1 Like

Hi @gamecocks
Try installing only the "binary" (precompiled) versions of the packages you need. If you try to install "source" versions of the packages the compilation may fail if the required additional compiler tools for your OS are not available.
HTH

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.