4

Each time I run pkgload::load_all(), I get the message below.

> pkgload::load_all()
ℹ Loading my_package
ℹ The packages "dm" and "sf" are required.
✖ Would you like to install them?

1: Yes
2: No

After each restart of RStudio, I need to reinstall "dm" and "sf" using "renv" by inserting 1 in the console. And then "sf" will be installed from source.

How could I solve this?

I ran devtools::install_dev_deps(). Now I only have the message, but nothing will be installed if I choose the option 1: Yes.

> pkgload::load_all()
ℹ Loading my_package
ℹ The packages "dm" and "sf" are required.
✖ Would you like to install them?

1: Yes
2: No

Selection: 1

> 
> devtools::load_all()
ℹ Loading my_package
ℹ The packages "dm" and "sf" are required.
✖ Would you like to install them?

1: Yes
2: No

Selection: 1

> renv::restore()
* The library is already synchronized with the lockfile.

> renv::install('dm') 
Installing dm [1.0.4] ...
    OK [linked cache]
> devtools::load_all()
ℹ Loading my_package
ℹ The packages "dm" and "sf" are required.
✖ Would you like to install them?

1: Yes
2: No

Selection: 1

> 

I get the following error when I load the dm or sf packages:

> library(dm)
Error: package or namespace load failed for ‘dm’ in dyn.load(file, DLLpath = DLLpath, ...):
  unable to load shared object '/Users/user_name/Library/Application Support/renv/cache/v5/R-4.3/x86_64-apple-darwin20/igraph/1.4.1/a7ef0d811cb66d8be9da0d7b5ab80ded/igraph/libs/igraph.so':
  dlopen(/Users/user_name/Library/Application Support/renv/cache/v5/R-4.3/x86_64-apple-darwin20/igraph/1.4.1/a7ef0d811cb66d8be9da0d7b5ab80ded/igraph/libs/igraph.so, 0x0006): Library not loaded: /osxcross/bin/../x86_64-apple-darwin22/lib/libgfortran.5.dylib
Reason: tried: '/osxcross/bin/../x86_64-apple-darwin22/lib/libgfortran.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/osxcross/bin/../x86_64-apple-darwin22/lib/libgfortran.5.dylib' (no such file), '/osxcross/bin/../x86_64-


> library(sf)
Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):
  unable to load shared object '/Users/user_name/Library/Application Support/renv/cache/v5/R-4.3/x86_64-apple-darwin20/KernSmooth/2.23-20/8dcfa99b14c296bc9f1fd64d52fd3ce7/KernSmooth/libs/KernSmooth.so':
  dlopen(/Users/user_name/Library/Application Support/renv/cache/v5/R-4.3/x86_64-apple-darwin20/KernSmooth/2.23-20/8dcfa99b14c296bc9f1fd64d52fd3ce7/KernSmooth/libs/KernSmooth.so, 0x0006): Library not loaded: /osxcross/bin/../x86_64-apple-darwin22/lib/libgfortran.5.dylib
Reason: tried: '/osxcross/bin/../x86_64-apple-darwin22/lib/libgfortran.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/osxcross/bin/../x86_64-apple-darwin22/lib/libgfortran.5.dylib'
layal
  • 180
  • 11
  • 1
    Your renv seems broken. What does `renv::status()` say? – Konrad Rudolph Aug 11 '23 at 14:09
  • @KonradRudolph I get: > renv::status() The following package(s) are installed but not recorded in the lockfile: _ zip [2.2.2] Use `renv::snapshot()` to add these packages to your lockfile. – layal Aug 13 '23 at 05:35
  • renv::snapshot(), did you try, let me know the message you got – jkatam Aug 14 '23 at 07:30

3 Answers3

5

I had to deal with the error messages returned by library(dm) and library(sf).

Here is the process of how I solved the problem. I needed to create a symbolic link for libgfortran.5.dylib and libquadmath.0.dylib in /usr/local/lib/ (see https://www.kombitz.com/2022/07/28/error-message-usr-local-lib-libgfortran-3-dylib-no-such-file-on-intel-mac-solved/).


# Solution for dm ----
devtools::install_github("igraph/rigraph")
renv::install("cynkra/dm")
devtools::load_all()

# After that, I only get 
> devtools::load_all()
* The project may be out of sync -- use `renv::status()` for more details.
ℹ Loading my_package
ℹ The package "sf" is required.
✖ Would you like to install it?

1: Yes
2: No

# For sf ----
brew install pkg-config
brew install gdal

install.packages("rgdal", type = "source", configure.args = c("--with-proj-lib=$(brew --prefix)/lib/", "--with-proj-include=$(brew --prefix)/include/"))

# https://github.com/fxcoudert/gfortran-for-macOS/releases 
# https://brew.sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install gcc

# cf. https://www.kombitz.com/2022/07/28/error-message-usr-local-lib-libgfortran-3-dylib-no-such-file-on-intel-mac-solved/
sudo ln -s /usr/local/Cellar/gcc/13.1.0/lib/gcc/13/libgfortran.5.dylib /usr/local/lib/libgfortran.5.dylib

install.packages("rgdal", type = "source", configure.args = c("--with-proj-lib=$(brew --prefix)/lib/", "--with-proj-include=$(brew --prefix)/include/"))
renv::install("rgdal", type = "source", configure.args = c("--with-proj-lib=$(brew --prefix)/lib/", "--with-proj-include=$(brew --prefix)/include/"))

# next error
# libquadmath.0.dylib' (no such file)

# sudo find / -name libquadmath.0.dylib  
# Password:
#/usr/local/gfortran/lib/i386/libquadmath.0.dylib
# /usr/local/gfortran/lib/libquadmath.0.dylib
# /usr/local/Cellar/gcc/13.1.0/lib/gcc/current/libquadmath.0.dylib
# /usr/local/Cellar/gcc/13.1.0/lib/gcc/13/libquadmath.0.dylib


sudo ln -s /usr/local/Cellar/gcc/13.1.0/lib/gcc/13/libquadmath.0.dylib /usr/local/lib/libquadmath.0.dylib 


Restarting R session...

devtools::load_all()
> pkgload::load_all()
ℹ Loading my_package
layal
  • 180
  • 11
3

This message:

Reason: tried: '/osxcross/bin/../x86_64-apple-darwin22/lib/libgfortran.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/osxcross/bin/../x86_64-apple-darwin22/lib/libgfortran.5.dylib' (no such file), '/osxcross/bin/../x86_64-

implies that you're currently using Posit Package Manager, and unfortunately the binaries delivered on PPM on macOS currently have an issue for packages which link to libgfortran.5.dylib. The team is actively investigating and we're hoping to have the issue resolved soon.

As a workaround, you can switch back to the CRAN repositories with:

options(repos = c(CRAN = "https://cloud.r-project.org"))

and then reinstall the affected packages. If you're using renv, after setting the repositories, you can run:

renv::snapshot()

to update the lockfile.

EDIT: A fix has now been pushed to Posit Package Manager, and the x86_64 macOS binaries should no longer have this issue. A similar fix for RStudio is being investigated in https://github.com/rstudio/rstudio/issues/13085; the RStudio team hopes to have a fix in the next RStudio release (Desert Sunflower; targeted for 2023-09).

krlmlr
  • 25,056
  • 14
  • 120
  • 217
Kevin Ushey
  • 20,530
  • 5
  • 56
  • 88
0

why you are using the pkgload::load_all() instead of devtools::load_all()

please try to install the dm and sf with renv

jkatam
  • 2,691
  • 1
  • 4
  • 12
  • Thank you. Please see my edited message above. It did not change anything. – layal Aug 14 '23 at 07:25
  • could you please try to install the dm and sf via renv::install('dm') – jkatam Aug 14 '23 at 07:44
  • I did but nothing changed. See the edited description above. – layal Aug 14 '23 at 07:50
  • 1
    within your project in any of the R code please call library(dm) and then run the code and then run the renv::snapshot() so that the lock file will get updated and we can avoid that message – jkatam Aug 14 '23 at 07:54
  • I get an error when I load dm or sf. See above. – layal Aug 14 '23 at 08:16
  • i dont see you have updated the lock file, did you run the renv::snapshot() after this – jkatam Aug 14 '23 at 08:20
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/254902/discussion-between-layal-and-jkatam). – layal Aug 14 '23 at 08:22