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 '' ...
	OK [file is up to date]
Installing geomorph [3.3.2] ...
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/':
  dlopen(/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/, 6): no suitable image found.  Did find:
	/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/ code signature invalid for '/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/'

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/':
  dlopen(/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/, 6): no suitable image found.  Did find:
	/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/ code signature invalid for '/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/lattice/libs/'

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

[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.

1 Like

Hi Kevin,
Unfortunately, I've run into the same issue described here, this time for the package sf. I'm still working in the same folder as before, with the same renv instance.

This time, I get the following error message when I try to load sf


Error: package or namespace load failed for ‘sf’ 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/class/libs/':
  dlopen(/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/class/libs/, 6): no suitable image found.  Did find:
	/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/class/libs/ code signature invalid for '/Users/kaijagahm/Box/BluegillMorphologyDataDOCMain/renv/library/R-4.0/x86_64-apple-darwin17.0/class/libs/'

This time, I tried both restarting the RStudio session and restarting my computer, but the problem was not fixed. My system details are the same as I showed before.

Do you have any other thoughts on what I could do to fix this problem?

One thought I had was that this could be an issue with Box Drive, where my project is stored.
Evidence in support of this:

  • I created a new R project outside of Box Drive, initialized renv, and installed sf. In that project's R session, I had no trouble loading sf.
  • There are some files in my Box Drive folder, specifically in the renv library folder, that are having trouble syncing.

Evidence against this:

  • The files in the renv folder that are having trouble syncing do not correspond to the packages I'm having trouble loading, at all. For example, the sf folder has no problems syncing, while e.g. ape does. But library(ape) is completely fine, while library(sf) throws an error (that's just one example--I tested others and got similar results)
  • A newly-created project inside the Box Drive folder, in which I initialized renv and installed sf, also had no trouble loading sf.

So I think this is not a Box Drive problem per se; it seems to be a problem with my particular project repo.

Next I am going to try removing and re-initializing the renv folder, to see if that does anything.
EDIT: I re-initialized renv for this repo, and now all the packages that were initially giving me trouble are back to throwing errors on load: lattice, MASS, and sf so far.

For what it's worth, this error indicates that the error occurred while loading the class package, which is presumeldy a dependency of the sf package. Is there anything recorded about syncing issues in the Box Drive folder for that package in particular?

Good catch, I'll check that and let you know (folder is currently syncing so I'm not sure right this second).

In the meantime, I think I'm going to pull this repo out of Box and see if it works there. It will be too bad, though, if renv turns out to just not work when combined with Box Drive, since that's my usual workflow.

Okay, an update. I'm now getting explanatory messages from Box Drive that I wasn't getting before. Apparently, the files that are failing to sync all have the extension ".so.dSYM".

The error message says "The file did not upload because packaged file types are not currently supported in Box Drive. Suggestion: convert the file to a single file in order for it to upload."

I think I've come to the end of the line here. It seems that many packages have a .so.dSYM file, and it's not like I can manually go and change how each package is bundled. Unfortunately, I think I have to conclude that Box Drive is fundamentally incompatible with renv, with the problem being on the Box side of things.

Thanks @kevinushey for your help!

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.