I installed the packages tidycensus
and mapview
in RStudio but I get the following error when I try load either one:
library(tidycensus)
Error: package or namespace load failed for ‘tidycensus’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/sf/libs/sf.so': dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/sf/libs/sf.so, 6): Library not loaded: /usr/lib/libpq.5.dylib Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/sf/libs/sf.so Reason: image not found
library(mapview)
Error: package or namespace load failed for ‘mapview’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/sf/libs/sf.so': dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/sf/libs/sf.so, 6): Library not loaded: /usr/lib/libpq.5.dylib Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/sf/libs/sf.so Reason: image not found
I've tried this solution but it is not solving my problem.
This issue indeed happened to me today when upgraded to Big Sur. After researching, finally I found a solution here:
copy libpq.5.dylib to /usr/lib/libpq.5.dylib
Looks like macOS is keeping libraries on
/usr/lib
closed. Basically is needed to point back/usr/lib/libpq.5.dylib
against anotherlibpq
, like the one you get by installing it with Homebrew.This is what worked for me, first uninstall
sf
andrgdal
packages in R and use HomeBrew to installlibpq
if needed:Check if library is pointing itself:
If not, point it against itself:
And link the new path of
libpq
to each R package binary that references to it:In this case, for
sf
andrgdal
: