Can't load package 'lattice', which causes install to fail for 'geomorph'

Hi all,
I'm trying to install the 'geomorph' package. Apparently, it depends on the package 'RRPP', which in turn depends on 'lattice'.

When I try to install 'geomorph', I get the following error:

> install.packages("geomorph")
Retrieving 'https://cran.rstudio.com/src/contrib/geomorph_3.3.2.tar.gz' ...
	OK [file is up to date]
Installing geomorph [3.3.2] ...
	FAILED
Error installing package 'geomorph':
====================================

* installing to library ‘/private/var/folders/sj/b05g_2wn5rvfkw9cfjcf5h8c0000gn/T/Rtmpa0Y62y/renv-staging-c4785f1e9c82’
* installing *source* package ‘geomorph’ ...
** package ‘geomorph’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
Error: package or namespace load failed for ‘RRPP’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/lattice.so':
  dlopen(/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/lattice.so, 6): no suitable image found.  Did find:
	/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/lattice.so: code signature invalid for '/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/lattice.so'

Error: package ‘RRPP’ could not be loaded
Execution halted
ERROR: lazy loading failed for package ‘geomorph’
* removing ‘/private/var/folders/sj/b05g_2wn5rvfkw9cfjcf5h8c0000gn/T/Rtmpa0Y62y/renv-staging-c4785f1e9c82/geomorph’
Error: install of package 'geomorph' failed

Digging into that error message, it seems that the problem is related to 'lattice'. Indeed, I tried just loading 'lattice', and got the same message:

> library(lattice)
Error: package or namespace load failed for ‘lattice’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/lattice.so':
  dlopen(/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/lattice.so, 6): no suitable image found.  Did find:
	/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/lattice.so: code signature invalid for '/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/lattice.so'

Note that install.packages("lattice") works just fine; it's library(lattice) that gives the error.

The error seems to be this "code signature invalid" thing. I googled a bit, and it seems that that might have to do with my OS, but I couldn't find any information about how to deal with it for R.

I've uninstalled and reinstalled lattice. I've restarted R and RStudio several times. I'm not sure how to get around this.

Probably relevant info: I am using renv, as of today. Before I started using renv, 'geomorph' installed fine. But because of some breaking changes in the most recent 'geomorph' version, I need to install an older version of the package, which is why I initialized 'renv'.

Here is my sessionInfo():

R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
 [1] compiler_4.0.3  htmltools_0.5.1 tools_4.0.3     yaml_2.2.1     
 [5] rmarkdown_2.6   grid_4.0.3      knitr_1.30      xfun_0.20      
 [9] digest_0.6.27   rlang_0.4.10    renv_0.12.5     evaluate_0.14  

EDITED TO ADD: I am now getting the same "code signature invalid" error for the 'MASS' package.

Thank you in advance for any help on this!

Sorry you're having trouble! Some questions worth asking:

  1. Do you see this outside of renv projects as well? Does lattice fail to load if you attempt to install and load it outside the context of an renv project?

  2. Do you see the issue in a "plain" R session, outside of RStudio? Or, only within RStudio?

  3. Does it make a difference if you install those packages from sources, e.g. via install.packages("lattice", type = "source")? You may need to install command line tools in that case; you can run sudo xcode-select --install from the command line to do so.

Hi Kevin,
Thanks for getting back to me! These are all really good questions. Let me take them one by one.

  1. In a non-renv RStudio session, lattice installs and loads fine. geomorph also installs and loads. It does give this warning:
Warning messages:
1: In rgl.init(initValue, onlyNULL) : RGL: unable to open X11 display
2: 'rgl.init' failed, running with 'rgl.useNULL = TRUE'. 

This is strange, because I installed X11 this morning to fix an issue with rgl, and I restarted the session after the install, so not sure why it's still not finding X11. But I don't think that is germane to the "code signature invalid" error, so I'll leave it alone for now.

  1. lattice is fine in a plain R session (outside of RStudio), and geomorph is likewise fine (same RGL warning, but no "code signature invalid" error). I don't know if it's possible to run renvoutside of RStudio? If so, I could try that, but I can't immediately see how.

  2. Installing from source does get rid of the error, but now there's a new error. For example, this is what happens when I install geomorph and then call library(geomorph):

> library(geomorph)
Loading required package: RRPP
Error: package or namespace load failed for ‘RRPP’ in get(Info[i, 1], envir = env):
 lazy-load database '/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/R/lattice.rdb' is corrupt
Error: package ‘RRPP’ could not be loaded
In addition: Warning message:
In get(Info[i, 1], envir = env) : internal error -3 in R_decompress1

I also tried uninstalling and re-installing lattice, but I got the same error.

Oh my gosh, I think I fixed it, but I don't know why.

I restarted my computer, and then all of a sudden lattice started working again. But I was still getting an error with MASS. So I removed MASS and re-installed it from source, and then restarted my computer again. After the second restart, MASS is no longer throwing the error. Hooray!

This does make me wonder, though, whether I'm going to run into this problem again, and whether I'll have to restart my computer after installing each new package, which would be less than ideal. I guess time will tell.

@kevinushey thanks for the troubleshooting!

For what it's worth, this error message is somewhat commonly seen when attempting to install a package that is already loaded in the current R session. Restarting the R session normally fixes things up.

Glad to hear things are working again now; please let us know if you bump into this again!

Right, that's why I thought it was so weird. I restarted the R session several times, to no effect. It was only when I fully restarted the computer that anything changed.

Anyway, thanks for your help! Hopefully there won't be too many other bumps. I'm really excited about using renv; I think it'll solve a lot of problems I've been having.

That is especially weird! But I'm glad to hear restarting has helped.

We hope so as well -- please let us know if you encounter any issues while using the package.