-1

I'm pretty new to R, but I've used it a little bit. However, I'm running into a problem and can't figure it out, despite having read through over a dozen other resources. For reasons I won't get into, I had to update R and R Studio. However, now none of my packages will install. For example, when I try to install dplyr, this is what I get:

> install.packages("dplyr")

  There is a binary version available but the source version is later:
      binary source needs_compilation
dplyr 1.0.10  1.1.0              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘dplyr’

trying URL 'https://cran.rstudio.com/src/contrib/dplyr_1.1.0.tar.gz'
Content type 'application/x-gzip' length 1068347 bytes (1.0 MB)
==================================================
downloaded 1.0 MB

* installing *source* package ‘dplyr’ ...
** package ‘dplyr’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
/usr/local/Cellar/gcc/9.2.0/bin/g++-7 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c chop.cpp -o chop.o
/bin/sh: /usr/local/Cellar/gcc/9.2.0/bin/g++-7: No such file or directory
make: *** [chop.o] Error 127
ERROR: compilation failed for package ‘dplyr’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/dplyr’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/dplyr’
Warning in install.packages :
  installation of package ‘dplyr’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/k7/pbrcjpr517x06fhvnkvbq0nc0000gp/T/RtmpAODLeZ/downloaded_packages’
> 

From what I've seen on other questions like this, I need to reinstall the packages to a new location. However, let's assume I'm an idiot and I have no idea how to re-install them somewhere else, where to install them, or how to make R/Rstudio that is where my packages can now be found. Can someone help me figure this out?

EDIT:

I now know that the problem is that it can't find the g++-7 dictionary, but I don't know why it is trying to find the g++-7, when my terminal says it my current version (12) is g++-12. Why would R not try to download the packages to my most recent version?

(base) Liams-MacBook-Pro:~ lessig7$ brew list gcc
/usr/local/Cellar/gcc/12.2.0/bin/c++-12
/usr/local/Cellar/gcc/12.2.0/bin/cpp-12
/usr/local/Cellar/gcc/12.2.0/bin/g++-12
/usr/local/Cellar/gcc/12.2.0/bin/gcc-12
/usr/local/Cellar/gcc/12.2.0/bin/gcc-ar-12
/usr/local/Cellar/gcc/12.2.0/bin/gcc-nm-12
/usr/local/Cellar/gcc/12.2.0/bin/gcc-ranlib-12
/usr/local/Cellar/gcc/12.2.0/bin/gcov-12
/usr/local/Cellar/gcc/12.2.0/bin/gcov-dump-12
/usr/local/Cellar/gcc/12.2.0/bin/gcov-tool-12
/usr/local/Cellar/gcc/12.2.0/bin/gfortran
/usr/local/Cellar/gcc/12.2.0/bin/gfortran-12
/usr/local/Cellar/gcc/12.2.0/bin/lto-dump-12
/usr/local/Cellar/gcc/12.2.0/bin/x86_64-apple-darwin21-c++-12
/usr/local/Cellar/gcc/12.2.0/bin/x86_64-apple-darwin21-g++-12
/usr/local/Cellar/gcc/12.2.0/bin/x86_64-apple-darwin21-gcc-12
/usr/local/Cellar/gcc/12.2.0/bin/x86_64-apple-darwin21-gcc-ar-12
/usr/local/Cellar/gcc/12.2.0/bin/x86_64-apple-darwin21-gcc-nm-12
/usr/local/Cellar/gcc/12.2.0/bin/x86_64-apple-darwin21-gcc-ranlib-12
/usr/local/Cellar/gcc/12.2.0/bin/x86_64-apple-darwin21-gfortran-12
/usr/local/Cellar/gcc/12.2.0/include/c++/ (806 files)
/usr/local/Cellar/gcc/12.2.0/lib/gcc/ (719 files)

Once I realized R was trying to save it to an olde version, I tried to tell it to save to the new folder with the following code (just changing the version numbers to match what is on my terminal):

install.packages("dplyr", lib="/usr/local/Cellar/gcc/12.2.0/bin/c++-12/Library/Frameworks/R.framework/Resources/include")

However, that produced the following error:

 install.packages("dplyr", lib="/usr/local/Cellar/gcc/12.2.0/bin/c++-12/Library/Frameworks/R.framework/Resources/include")
Warning in install.packages :
  'lib = "/usr/local/Cellar/gcc/12.2.0/bin/c++-12/Library/Frameworks/R.framework/Resources/include"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) 
Error in install.packages : unable to install packages
> 

install.packages("dplyr", lib="/usr/local/Cellar/gcc/12.2.0/bin/c++-12/Library/Frameworks/R.framework/Resources/include")

I'd really appreciate any help. Thank you in advance.

lwe
  • 323
  • 1
  • 8
  • Is there any reason you are installing R via brew? I find that most errors go away when you just use the offical release version of R from https://cloud.r-project.org/. You can also try installing the already compiled version with `install.packages("dplyr", type="binary")`. Eventually the compiled version will make it to the CRAN repo so there's not a strong reason to compile yourself unless you need the very latest version now. – MrFlick Feb 01 '23 at 19:22
  • Sorry. So I didn't actually install R via brew. I did use the official version from the link you provided. However, for some packages, I needed gcc, so I used the terminal for that. However, the version that R is trying to use (gcc7) is different from the one terminal has (gcc12) and I don't know how to fix that. Should I just delete everything from R/Rstudio and try downloading them both again? – lwe Feb 01 '23 at 19:31
  • Most likely you set that up in a configuration file somewhere. Did you create a `~/.R/Makevars` file at some point? https://stackoverflow.com/a/1618618/2372064 – MrFlick Feb 01 '23 at 20:40
  • Not that I am aware of. I may have deleted it, if I had one. When I typed that in terminal I got the following: ``-bash: /Users/lessig7/.R/Makevars: No such file or directory`` – lwe Feb 03 '23 at 15:57

1 Answers1

0

It looks like the problem you're encountering is due to a missing version of g++.

The error message says:

/usr/local/Cellar/gcc/9.2.0/bin/g++-7: No such file or directory

This means that the g++ compiler, which is necessary for installing some R packages, is not present in the specified location /usr/local/Cellar/gcc/9.2.0/bin/g++-7.

To fix the issue, you can try installing the g++ compiler by running the following command in your terminal:

brew install gcc

After installing g++, try installing the dplyr package again in R. If you continue to face issues, you can try reinstalling the package to a different location by using the lib argument in the install.packages function, for example:

install.packages("dplyr", lib="/path/to/new/library")

Replace "/path/to/new/library" with the desired location for the installed packages.

Kamuffel
  • 592
  • 1
  • 6
  • 17
  • Thanks @Kamuffel. I tried both of those approaches and neither worked. I've updated my post with more information at the bottom, but it seems like I have a later version (g++-12) according to terminal, but R studio keeps trying to save the installed package information to an earlier version that doesn't seem to exist. I then tried to use the ``lib=`` to force it to use the later version, but it said its wasn't writable. Any other recommendations? How can I help R identify the updated version of gcc? – lwe Feb 01 '23 at 19:09