PianoEntropy
PianoEntropy

Reputation: 131

install.packages() does not find arm64 binaries

I have been setting up renv on my Macbook with M1 chip (ARM64 architecture) and encounter problems installing packages. Basically, I think the problem is that my setup does not correctly detect my arm64 architecture and cannot find the correct binaries on CRAN.

I start my environment using renv::init() and then install packages with either install.packages() or renv::install(). Many packages fail to install with error messages such as:

> renv::install('png')
# Downloading packages -------------------------------------------------------
- Downloading png from CRAN ...                 OK [file is up to date]
Successfully downloaded 1 package in 0.56 seconds.

The following package(s) will be installed:
- png [0.1-8]
These packages will be installed into "~/[***]/renv/library/R-4.3/aarch64-apple-darwin20".

Do you want to proceed? [Y/n]: y

# Installing packages --------------------------------------------------------
- Installing png ...                            FAILED


Error: Error installing package 'png':
===============================

* installing *source* package ‘png’ ...
** package ‘png’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C compiler: ‘Apple clang version 14.0.3 (clang-1403.0.22.14.1)’
using SDK: ‘MacOSX13.3.sdk’
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include    `libpng-config --cflags` -fPIC  -falign-functions=64 -Wall -g -O2  -c dummy.c -o dummy.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include    `libpng-config --cflags` -fPIC  -falign-functions=64 -Wall -g -O2  -c read.c -o read.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include    `libpng-config --cflags` -fPIC  -falign-functions=64 -Wall -g -O2  -c write.c -o write.o
clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o png.so dummy.o read.o write.o -L/Users/[***]/miniconda3/lib -lpng16 -lz -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Users/[***]/renv/staging/1/00LOCK-png/00new/png/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘png’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/[***]/staging/1/00LOCK-png/00new/png/libs/png.so':
  dlopen(/Users/[***]/renv/staging/1/00LOCK-png/00new/png/libs/png.so, 0x0006): Library not loaded: @rpath/libpng16.16.dylib
  Referenced from: <B6F4C788-8DD4-3818-9093-3979F76F79B5> /Users/[***]/renv/staging/1/00LOCK-png/00new/png/libs/png.so
  Reason: tried: '/Library/Frameworks/R.framework/Resources/lib/libpng16.16.dylib' (no such file), '/Library/Java/JavaVirtualMachines/jdk-11.0.18+10/Contents/Home/lib/server/libpng16.16.dylib' (no such file)
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘[***]/renv/staging/1/png’
install of package 'png' failed [error code 1]

Now, it appears that my Mac has problems installing form source, but I can install binaries. If I directly download the arm64 binaries from CRAN and install them manually this gives no problem. Also no problems by installing from the binary URL. However, if I try install.packages("png", type="binary"), then I get the message

Installing package into ‘/Users/[***]/renv/library/R-4.3/aarch64-apple-darwin20’
(as ‘lib’ is unspecified)

   package ‘png’ is available as a source package but not as a binary

Warning message:
package ‘png’ is not available as a binary package for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

Basically, this suggests to me that the setup is not detecting the correct architecture and cannot find the binaries, but has no problems installing binaries.

My R version is

platform       aarch64-apple-darwin20      
arch           aarch64                     
os             darwin20                    
system         aarch64, darwin20           
status                                     
major          4                           
minor          3.0                         
year           2023                        
month          04                          
day            21                          
svn rev        84292                       
language       R                           
version.string R version 4.3.0 (2023-04-21)
nickname       Already Tomorrow            

Upvotes: 1

Views: 396

Answers (1)

Kevin Ushey
Kevin Ushey

Reputation: 21285

What CRAN repository are you using? Everything seems fine using the Cloud mirror:

> options(repos = c(CRAN = "https://cloud.r-project.org"))
> install.packages("png", type = "binary")
Installing package into '/Users/kevin/Library/R/arm64/4.3/library'
(as 'lib' is unspecified)
trying URL 'https://cloud.r-project.org/bin/macosx/big-sur-arm64/contrib/4.3/png_0.1-8.tgz'
Content type 'application/x-gzip' length 389013 bytes (379 KB)
==================================================
downloaded 379 KB

Upvotes: 1

Related Questions