Can't download package for RStudio

Hi guys,

First time to learn RStudio, I am running Version 1.2.5033 at Mac ios, having trouble to install a package. I tried to reinstall R but still have the same issue "installation of package ‘Rcpp’ had non-zero exit status". I have no idea how to fix it since I am beginner. Any suggestions would be a huge help, many thanks!

> install.packages("dplyr")
also installing the dependency ‘Rcpp’


  There is a binary version available but the source version is later:
     binary  source needs_compilation
Rcpp  1.0.4 1.0.4.6              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/dplyr_0.8.5.tgz'
Content type 'application/x-gzip' length 6859111 bytes (6.5 MB)
==================================================
downloaded 6.5 MB


The downloaded binary packages are in
	/var/folders/jj/f_lyv6zd44jfhb75572cw_cc0000gn/T//RtmplzQDYx/downloaded_packages
installing the source package ‘Rcpp’

trying URL 'https://cran.rstudio.com/src/contrib/Rcpp_1.0.4.6.tar.gz'
Content type 'application/x-gzip' length 2751467 bytes (2.6 MB)
==================================================
downloaded 2.6 MB

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

The downloaded source packages are in
	‘/private/var/folders/jj/f_lyv6zd44jfhb75572cw_cc0000gn/T/RtmplzQDYx/downloaded_packages’

Since the most recent version of Rcpp didn't have binaries on CRAN at the time you were trying to install it, you needed Xcode Command Line Tools in order to compile it from source (the error message mentioning xcrun is the telltale sign there).

The TL;DR solution is to run:
xcode-select --install
from the command line/terminal, but if you want more info, see section 9.2 at the link below:

1 Like

Thanks so much Mara! I tried your code and it works like a magic!

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

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