Unable to install ggplot2 in R Studio!!

Hi there-

I am interested in making some figures in R, and I am trying to download the "gglot2" package for the first time. I haven't been able to install it, and I just updated my R to the latest version (1.2.5033).

I am also unsure how to include the code.

I would appreciate any help that can be offered!!

Thanks,

Erik

I wrote a guide to installing packages at https://www.dummies.com/programming/r/how-to-install-load-and-unload-packages-in-r/

In your case, you need to use:

install.packages("ggplot2")

Note that the version number you gave (1.2.5...) relates to your version of RStudio. Your version of R is probably R-3.6.2 or R-3.6.3. But the version number of R is probably not important in this case.

You are using an old version of R (3.3.x) and this is why you are getting the suggestions to install packages from source.

I suggest you upgrade your version of R to the latest (R-3.6.3) and try again.

OK, thanks for the suggestion. I just updated R to 3.6.3... but now I can't even install Readr with library(readr)

I haven't tried re-doing the ggplot2 installation, I just want to get this ReadR thing figured out before I go forward. Here is the error message:

> library(readr)
Error in library(readr) : there is no package called ‘readr’
> install.packages("readr")
also installing the dependencies ‘assertthat’, ‘glue’, ‘utf8’, ‘digest’, ‘cli’, ‘ellipsis’, ‘fansi’, ‘lifecycle’, ‘magrittr’, ‘pillar’, ‘pkgconfig’, ‘rlang’, ‘vctrs’, ‘Rcpp’, ‘tibble’, ‘hms’, ‘R6’, ‘clipr’, ‘crayon’, ‘BH’


  There is a binary version available but the source version is later:
     binary source needs_compilation
glue  1.3.2  1.4.0              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/assertthat_0.2.1.tgz'
Content type 'application/x-gzip' length 53625 bytes (52 KB)
==================================================
downloaded 52 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/utf8_1.1.4.tgz'
Content type 'application/x-gzip' length 196648 bytes (192 KB)
==================================================
downloaded 192 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/digest_0.6.25.tgz'
Content type 'application/x-gzip' length 246357 bytes (240 KB)
==================================================
downloaded 240 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/cli_2.0.2.tgz'
Content type 'application/x-gzip' length 395137 bytes (385 KB)
==================================================
downloaded 385 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/ellipsis_0.3.0.tgz'
Content type 'application/x-gzip' length 33047 bytes (32 KB)
==================================================
downloaded 32 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/fansi_0.4.1.tgz'
Content type 'application/x-gzip' length 210779 bytes (205 KB)
==================================================
downloaded 205 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/lifecycle_0.2.0.tgz'
Content type 'application/x-gzip' length 91621 bytes (89 KB)
==================================================
downloaded 89 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/magrittr_1.5.tgz'
Content type 'application/x-gzip' length 154842 bytes (151 KB)
==================================================
downloaded 151 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/pillar_1.4.3.tgz'
Content type 'application/x-gzip' length 178277 bytes (174 KB)
==================================================
downloaded 174 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/pkgconfig_2.0.3.tgz'
Content type 'application/x-gzip' length 17573 bytes (17 KB)
==================================================
downloaded 17 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/rlang_0.4.5.tgz'
Content type 'application/x-gzip' length 1182651 bytes (1.1 MB)
==================================================
downloaded 1.1 MB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/vctrs_0.2.4.tgz'
Content type 'application/x-gzip' length 1077741 bytes (1.0 MB)
==================================================
downloaded 1.0 MB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/Rcpp_1.0.4.tgz'
Content type 'application/x-gzip' length 3124401 bytes (3.0 MB)
==================================================
downloaded 3.0 MB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/tibble_3.0.0.tgz'
Content type 'application/x-gzip' length 384238 bytes (375 KB)
==================================================
downloaded 375 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/hms_0.5.3.tgz'
Content type 'application/x-gzip' length 103612 bytes (101 KB)
==================================================
downloaded 101 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/R6_2.4.1.tgz'
Content type 'application/x-gzip' length 57479 bytes (56 KB)
==================================================
downloaded 56 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/clipr_0.7.0.tgz'
Content type 'application/x-gzip' length 48251 bytes (47 KB)
==================================================
downloaded 47 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/crayon_1.3.4.tgz'
Content type 'application/x-gzip' length 749917 bytes (732 KB)
==================================================
downloaded 732 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/BH_1.72.0-3.tgz'
Content type 'application/x-gzip' length 11253901 bytes (10.7 MB)
==================================================
downloaded 10.7 MB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/readr_1.3.1.tgz'
Content type 'application/x-gzip' length 792657 bytes (774 KB)
==================================================
downloaded 774 KB


The downloaded binary packages are in
	/var/folders/vn/3hn5_p0j767d0vwkgglpq1p80000gn/T//RtmpnjAnfy/downloaded_packages
installing the source package ‘glue’

trying URL 'https://cran.rstudio.com/src/contrib/glue_1.4.0.tar.gz'
Content type 'application/x-gzip' length 98619 bytes (96 KB)
==================================================
downloaded 96 KB

* installing *source* package ‘glue’ ...
** package ‘glue’ 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 ‘glue’
* removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/glue’
Warning in install.packages :
  installation of package ‘glue’ had non-zero exit status

The downloaded source packages are in
	‘/private/var/folders/vn/3hn5_p0j767d0vwkgglpq1p80000gn/T/RtmpnjAnfy/downloaded_packages’

Actually, I was able to get the ReadR package working.. I just selected "no" when prompted about whether I wanted to "install from sources that needed compilation"

1 Like

Oh wow, thanks for the information! So if I select "no" when it asks if I want to install from source, is there any chance that there will be adverse effects on that specific program? Like if I want to do a specific statistical test that needs a certain package, is there any chance that I could get the wrong results just because I installed from source code?

1 Like

Shortest possible answer: Failing to install ggplot2 won't affect any package's ability to correctly perform statistical calculations. It only limits the ability to present them through the nifty ggplot2 package.

If you select the n option, you can *still installthe usually only slightly outdatedbinary` version.

There are two install issues

  There are binary versions available but the source versions are later:
        binary source needs_compilation
rlang    0.1.6  0.4.5              TRUE
ggplot2  2.2.1  3.3.0             FALSE

Do you want to install from sources the package which needs compilation?
y/n: y
Package which is only available in source form, and may need compilation of C/C++/Fortran:
  ‘isoband’

So, ggplot2 depends on rlang and rlang depends on isoband, which needs to be installed from source, but it, again, relies a different resource, xrun and it on xcrun which is not a package, but a compiler tool. Here's mine

/usr/bin/xcrun
 $ 569:  l /usr/bin/xcrun
-rwxr-xr-x  1 root  wheel    30K Jan 23 05:59 /usr/bin/xcrun*

which is in a different location than the one that yours is looking for, /Library/Developer/CommandLineTools/usr/bin/xcrun

Ok, hang in there.

The reason it's not there is that the xcrun in that directory is not there, because, in turn the directory itself isn't there and needs to be.

And the reason that it is missing is because the CommandLine\Tools directory itself isn't there. That isn't there because of two possibilities

  1. the command line tools haven't been installed or
  2. the free Xcode app from the App Store (yes, I used my magical powers to see you are on macOS and also not yet on Catalina*)

Depending on the macOS version, here' the backstory and the fix (unless you are on a waaay old macOS version.)

On macOS, packages sometimes fail to install, often with a non-zero exit status message. This is due to Apple's idiosyncratic compiler. The same packages will install on most Linux systems without trouble. Saint Simon Urbanek of the R Core Development Team takes on the brain damage required to recode the source to get around macOS's peculiar worldview for those in CRAN, but he can't bestow the same mercy on those still in development.

Some packages will successfully install through compilation from source, but many won't.

When installing if you are offered the option to install from source, it makes sense to try it once. But, if at first it doesn't succeed, in all likelihood it never will. It's usually only 7-10 days until a macOS binary is available, but for some reason it's been a year and it hasn't yet been.

And THEREFORE, it doesn't need to be because it readily compiles, so installing the command line utilities SHOULD work.

Whew!

OK, thank you for the in-depth explanation! I definitely could not give a lecture about this subject, but I feel like I understand it more now after reading your post.

So basically one way that I can potentially "fix" these issues is to install the Xcode app from the app store? Will that help?

1 Like

That’s my story. Circle back and help others with your experience trying? First, though take the binary option.

Everything seems to be working fine for me with ggplot2, it is a really cool package!

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

Hi Andrie-

Thanks for your quick response. I have tried the install.packages(ggplot2), but I keep getting error messages. Here they are:

> install.packages("ggplot2")
Installing package into ‘/Users/eriksolhaug/Library/R/3.3/library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘isoband’, ‘rlang’


  There are binary versions available but the source versions are later:
        binary source needs_compilation
rlang    0.1.6  0.4.5              TRUE
ggplot2  2.2.1  3.3.0             FALSE

Do you want to install from sources the package which needs compilation?
y/n: y
Package which is only available in source form, and may need compilation of C/C++/Fortran:
  ‘isoband’
Do you want to attempt to install these from sources?
y/n: y
installing the source packages ‘isoband’, ‘rlang’, ‘ggplot2’

trying URL 'https://cran.rstudio.com/src/contrib/isoband_0.2.0.tar.gz'
Content type 'application/x-gzip' length 1894070 bytes (1.8 MB)
==================================================
downloaded 1.8 MB

trying URL 'https://cran.rstudio.com/src/contrib/rlang_0.4.5.tar.gz'
Content type 'application/x-gzip' length 816813 bytes (797 KB)
==================================================
downloaded 797 KB

trying URL 'https://cran.rstudio.com/src/contrib/ggplot2_3.3.0.tar.gz'
Content type 'application/x-gzip' length 3031461 bytes (2.9 MB)
==================================================
downloaded 2.9 MB

Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'zone/tz/2019c.1.0/zoneinfo/Europe/Zurich'
* installing *source* package ‘isoband’ ...
** package ‘isoband’ successfully unpacked and MD5 sums checked
** libs
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
ERROR: compilation failed for package ‘isoband’
* removing ‘/Users/eriksolhaug/Library/R/3.3/library/isoband’
Warning in install.packages :
  installation of package ‘isoband’ had non-zero exit status
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'zone/tz/2019c.1.0/zoneinfo/Europe/Zurich'
* installing *source* package ‘rlang’ ...
** package ‘rlang’ successfully unpacked and MD5 sums checked
** 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 ‘/Users/eriksolhaug/Library/R/3.3/library/rlang’
* restoring previous ‘/Users/eriksolhaug/Library/R/3.3/library/rlang’
Warning in install.packages :
  installation of package ‘rlang’ had non-zero exit status
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'zone/tz/2019c.1.0/zoneinfo/Europe/Zurich'
ERROR: dependency ‘isoband’ is not available for package ‘ggplot2’
* removing ‘/Users/eriksolhaug/Library/R/3.3/library/ggplot2’
Warning in install.packages :
  installation of package ‘ggplot2’ had non-zero exit status

The downloaded source packages are in
	‘/private/var/folders/vn/3hn5_p0j767d0vwkgglpq1p80000gn/T/RtmpeGdddu/downloaded_packages’

Thanks,

Erik

This is an excellent choice for macOS, especially. If relevant here's the backgrounder

On macOS, packages sometimes fail to install, often with a non-zero exit status message. This is due to Apple's idiosyncratic compiler. The same packages will install on most Linux systems without trouble. Saint Simon Urbanek of the R Core Development Team takes on the brain damage required to recode the source to get around macOS's peculiar worldview for those in CRAN, but he can't bestow the same mercy on those still in development.

Some packages will successfully install through compilation from source, but many won't.

When installing if you are offered the option to install from source, it makes sense to try it once. But, if at first it doesn't succeed, in all likelihood it never will. It's usually only 7-10 days until a macOS binary is available