Skip to content

Corrupt R installation

10 messages · Simon Urbanek, Jeff Newmiller, Dr Eberhard W Lisse +3 more

#
Copied from SO (
https://stackoverflow.com/questions/67892321/major-r-installation-corruption)
and sent here instead at the suggestion of  Dirk Eddelbuettel
<https://stackoverflow.com/users/143305/dirk-eddelbuettel>

I have no idea why, but my R installation (Mac OS X - Big Sur)
automatically updates causing havoc with my libraries each time. My Mac is
under administration from the university and their software center, but
they claim it is not their fault - but I still suspect them for causing all
the trouble.

Anyhow - after that last update to 4.1.0 the packages were again all lost.
I tried a dirty hack just symlinking to the old version and updating (I
know-- very stupid, but I didnt have time for a major update of all the
packages), but after this my R-installation has been totally chaos for the
past week. I?ve reinstalled everything multiple times (brew, llvm, gcc,
CLI, X-code -- you name it) and I?ve finally managed to get data.table
working again with openMP support using the instructions at SO
<https://stackoverflow.com/questions/65251887/clang-7-error-linker-command-failed-with-exit-code-1-for-macos-big-sur/65334247#65334247>
 (
https://stackoverflow.com/questions/65251887/clang-7-error-linker-command-failed-with-exit-code-1-for-macos-big-sur/65334247#65334247
).

However I still get the following error message when installing data.table
from source:

dylib (/usr/local/opt/llvm/lib/libunwind.dylib) was built for newer macOS
version (11.0) than being linked (10.16)
Does it matter? Any idea how I can fix it?
#
You seem to have entirely non-standard setup that you're on your own and I assume you're not using CRAN R since you involve homebrew (which explains the chaos) so presumably you re-compiled R yourself and all packages, but I'd like to point out that if all you are after is OpenMP support then you don't need any of that fragile mess as explained at https://mac.r-project.org/openmp/

Cheers,
Simon
#
Also, symlinking an X.Y R version package library to any other major-minor version is never supported (even if it sometimes works). Re-install your packages when the minor version Y increments.
On June 8, 2021 5:07:28 PM PDT, Simon Urbanek <simon.urbanek at R-project.org> wrote:

  
    
#
On 08/06/2021 22:46, moleps islon wrote:
[...]
[...]

Sounds like Homebrew to me.  If so, or anyway, create a file (before
updating) which contains something like

	 #!/usr/bin/env Rscript --vanilla
	 #
	 # set the Mirror
	 #
	 local({
		r <- getOption("repos")
		 r["CRAN"] <- "https://cloud.r-project.org/"
		options(repos = r)
	 })
	 install.packages(c(
		  "lubridate",
		  "tidyverse"
	 ), dependencies = TRUE)


or similar and run it if the additional libraries disappear.

You can fill this with something like

	 grep -h library *R \
	 |awk -F 'library' '{print $2}' \
	 |sed 's/(//g;s/)//g' \
	 |sort -u \
	 |awk '{print "\"" $1 "\","}'
	 |sed '$ s/,$//'

or in a few lines of the language of your choice generate the whole
script. And of course refine to your liking with something like

	 find ~/R -name '*.R' -exec grep -h library {} ';' \
	 ...

greetings, el
#
Besides that Homebrew does not explain any chaos and does not do a
fragile mess, he clearly stated that his installation is
managed/controlled by his University, so the below isn't helpful.

See my other response in this thread about how to automagically
re-install packages after Homebrew updates.

el
On 09/06/2021 02:07, Simon Urbanek wrote:
[...]
[...]
#
Um, this is actually a lot easier purely with R - if you want to keep track of your favorite packages it is as simple as

pkgs = rownames(installed.packages())
writeLines(pkgs, "packages.txt")

and oyu have a list of all packages that you can edit if desired. if you ever want to re-install then simply

pkgs = readLines("packages.txt")
install.packages(pkgs)

and if you only want to install missing it's simply

missing.pkgs = pkgs[!pkgs %in% rownames(installed.packages())]
install.packages(missing.pkgs)

All trivially done in R. It is always beyond me why people come up with incredibly convoluted solutions to simple things ..

Cheers,
Simon
#
Yep. (In the first form, you likely want a stoplist for base and recommended packages.)

You can also base it on a listing of the library directory. This has the advantage that you can fairly easily twiddle it to look at older versions after the upgrade.
[1] "/Library/Frameworks/R.framework/Versions/4.0/Resources/library"
[1] "3.0"     "3.1"     "3.2"     "3.3"     "3.4"     "3.5"     "3.6"    
[8] "4.0"     "Current"
[1] "assertthat"            "backports"             "base"                 
  [4] "base64enc"             "BH"                    "bitops"               
  [7] "boot"                  "caTools"               "chron"                
 ...
[1] "caTools"      "dplyr"        "plogr"        "translations"

(Notice that "translations" is not a package, so  a red herring in this context)

-pd

  
    
#
Allright - I?m way beyond believing I could save my packages and ended up
removing everything (including all versions in R.framework dir.) I
reinstalled from CRAN. But there is still something out of the ordinary.
After installing some of them : Some work, others (meaning most) display

"Error: package or namespace load failed for ?tidyr? in dyn.load(file,
DLLpath = DLLpath, ...):
 unable to load shared object
'/Users/Misha/Library/R/4.0/library/glue/libs/glue.so':
  dlopen(/Users/Misha/Library/R/4.0/library/glue/libs/glue.so, 6): Library
not loaded: /usr/local/opt/r/lib/R/lib/libR.dylib
  Referenced from: /Users/Misha/Library/R/4.0/library/glue/libs/glue.so
  Reason: image not found"

- but the library is listed both when I run installed.packages() from R and
when I enter the correct directory from the terminal. Moreover - all
privileges are OK within the directory.

I promise I?ll never try another shortcut in updating R--must have taken me
better part of a week to try and sort this out.
On Thu, Jun 10, 2021 at 8:34 AM peter dalgaard <pdalgd at gmail.com> wrote:

            

  
  
#
Those errors come from packages that you didn't re-install - anything that uses /usr/local is not from CRAN. So check 
/Users/Misha/Library/R/4.0/library/
Best way is to move the entire tree aside (Eg. rename "library" to "old") to make sure you don't pick up old stuff.

BTW: you can list packages from a tree even if it's not used by R by using lib.loc, so if you renamed the library as above, you can still list all packages in there by using

pkg=rownames(installed.packages(lib.loc="/Users/Misha/Library/R/4.0/old"))

Cheers,
Simon

PS: just an aside, avoid using RStudio to perform upgrades as it has issues when packages that it is using get upgraded, using R is safer.
#
With RStudio I just quit, restart and then update the packages.

Ken