简体   繁体   中英

Resolve issues installing R packages after switch from Intel to apple silicon

I just migrated things over from my old mac to my my new mac (Intel to Apple Silicon), installed the latest version of R, ran brew upgrade , and began updating R packages. Many needed to be reinstalled, some from source. I bumped into several issues.

  1. Library linkages not being found (eg, Mac OS Big Sur R compilation error: ld: framework not found CoreFoundation )
  2. for CRAN packages, having the CRAN mirror selection pop up in a weird X11 GUI window instead of a numeric selection in the R console (which was the previous behavior).

I didn't really want to troubleshoot each library issue. I got the sense that ~/.R/Makevars and ~/.Rprofile might need to be edited. What did I need to do to make these problems go away?

A few resources were helpful, but some seemed out of date or incomplete. Here is my attempt to give a full step-by-step recreation of what I think worked, and I will edit as needed while I get my new system up and running.

Based largely on the recommendations here , I edited the Makevars file as follows:

In the shell:

vi ~/.R/Makevars

I then hit i (for insert) and deleted Everything that was there. I then added:

LDFLAGS += -L/opt/homebrew/opt/libomp/lib
CPPFLAGS += -I/opt/homebrew/opt/libomp/include
FLIBS   =-L/opt/homebrew/opt/gfortran/lib
F77     = /opt/homebrew/bin/gfortran
FC      = /opt/homebrew/bin/gfortran

CFLAGS   = -I/opt/homebrew/include
CPPFLAGS = -I/opt/homebrew/include
CXXFLAGS = -I/opt/homebrew/include

To save, I hit esc and then :x to save and close.

AFAIK, this resolved the issues with library finding/loading/linking, and I have installed several packages from source without error now.

To deal with the annoying pop-out GUI window to select the CRAN mirror, I edited the ~/.Rprofile (also using vi as described above) to read:

local({r <- getOption("repos")
       r["CRAN"] <- "https://cloud.r-project.org"
       options(repos=r)
})

options(menu.graphics = FALSE)

This was based on the best looking answers to this old but still important question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM