How to fix sf installation issue

I'm trying to install sf on my new computer (M2 MacBook Air). It seems to install fine, but when I try to load it, I keep running into this error:

> library(sf)
Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so, 0x0006): tried: '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so' (no such file), '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

I unfortunately don't understand much of what that means. I'm running macOS Ventura, with R version 4.2.2. I've tried installing GDAL, geos and proj, and rgdal with Homebrew, and a number of other fixes I've seen, but nothing seems to work. Any advice or direction would be appreciated! Thanks!

It looks like you are driving a Silicon chip. The part of the msg about architecture reflects that. I’ll fire up mine later tonight (PST) and see what I did to get it working. If it calls for compiling from source, you’ll need the X-Code app from the App Store, which is a very long download. You will also need the command line tools that come with it. (Check first if the CLI is available without XCode, it’s been a while since I looked.)

... later

Check from the t

I got a clean install with terminal

R --version

and confirm

Platform: aarch64-apple-darwin20 (64-bit)

> library(sf)
Error in library(sf) : there is no package called ‘sf’
> install.packages("sf")
trying URL 'https://ftp.osuosl.org/pub/cran/bin/macosx/contrib/4.2/sf_1.0-9.tgz'
Content type 'application/x-gzip' length 89588367 bytes (85.4 MB)
==================================================
downloaded 85.4 MB


The downloaded binary packages are in
    
> library(sf)
Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 8.2.1; sf_use_s2() is TRUE

Hmmm, from the terminal, I had the same platform listed, but when I typed library(sf), I got:

zsh: invalid mode specification

In fact, I get that, when I type anything in the terminal after R --version, so maybe that's where the problem is?

The terminal and the R prompt can be confusing if they both look like > like mine.

is coming from the terminal "shell" program. Go back and try this

❯ R --version
R version 4.2.2 (2022-10-31) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

❯ which R      
/usr/local/bin/R

If either of these fail, you need to install R in addition to RStudio

Both of those yielded the same results you got. And I see what I did wrong earlier, but I still get the same error when installing sf from the terminal:

> library(sf)
Error in library(sf) : there is no package called ‘sf’
> install.packages("sf")
--- Please select a CRAN mirror for use in this session ---



trying URL 'https://repo.miserver.it.umich.edu/cran/bin/macosx/big-sur-arm64/contrib/4.2/sf_1.0-9.tgz'
Content type 'application/octet-stream' length 89952912 bytes (85.8 MB)
==================================================
downloaded 85.8 MB


The downloaded binary packages are in
	/var/folders/24/d3qffzzx0h12d__hbsql3mh40000gn/T//RtmpQNSyBV/downloaded_packages
> 
> 
> 
> library(sf)
Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so, 0x0006): tried: '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so' (no such file), '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
> 

Ok. Making progress. There’s a system dependency, proxy.so required, which you have, but it’s compiled for the Intel chip and you need it compiled for Silicon. It might require compiling from source.

Do you have XCode installed?

I don't, but I'm pretty sure I have the command line tools installed at /Library/Developer/CommandLineTools (what I get when I run xcode-select -p). Had to install them for something else.

OK, I see it now, proxy.so is in the highlighted library but it's not compiled for Silicon. There are two R binaries. One is compiled for Intel and the other, which you need, is compiled for Silicon. R-4.2.2-arm64.pkg

So, next I'd try re-installing R from the later. That's how I did it on my M1.

I tried this, but kept getting what looks like the same error when I tried to load sf:

> library(sf)
Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so, 0x0006): tried: '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so' (no such file), '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/proxy/libs/proxy.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

I also tried uninstalling sf and reinstalling it, but that didn't seem to help.

Got it to work! I apparently hadn't fully uninstalled R, but once I did, it worked once I reinstalled. Thanks for dealing with me!

1 Like

This topic was automatically closed 7 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.