unicode in ggplot pdf output if Cairo is broken - r

I have been using cairo_pdf(...) to ggplot pdf's that contain unicode for phonetic (IPA) characters (like "\u025B"). This worked great until today when I updated RStudio to 1.1.456 and R to 3.5.1 (running on OS X 10.13.5). Now, when I call cairo_pdf(...) I get a message saying "failed to load cairo DLL". I have done install.packages("Cairo") and now library("Cairo") spits out a series of messages:
Error: package or namespace load failed for ‘Cairo’:
.onLoad failed in loadNamespace() for 'Cairo', details:
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Cairo/libs/Cairo.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Cairo/libs/Cairo.so, 6): Library not loaded: /opt/X11/lib/libfreetype.6.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/Cairo/libs/Cairo.so
Reason: Incompatible library version: Cairo.so requires version 19.0.0 or later, but libfreetype.6.dylib provides version 17.0.0
I'm not sure whether I should try to work out what has changed in Cairo or R, or learn a different way to put unicode characters in plots. I did try .png outputs but the quality was inadequate.
tx

The most recent version of the system cairo package in the Mac http://r.research.att.com/libs/ directory is: http://r.research.att.com/libs/cairo-1.14.2-darwin.13-x86_64.tar.gz
You might get some information and possibly even some success with the suggested method at the bottom the the libs page. Open Terminal.app and paste these two lines (all of them) into the Unix console:
curl -O http://r.research.att.com/libs/cairo-1.14.2-darwin.13-x86_64.tar.gz
sudo tar fvxz gmp-4.2.4-darwin8-bin4.tar.gz -C /
I edited your tags since the other possibility of a system issue is whether Rstudio honors or recognizes the location of the cairo lib.
On my Rstudio installation it seems to. I was able to load, update, run: detach("package:Cairo", unload=TRUE), and reload the (R) Cairo package from the R console. But I'm not a particularly knowledgeable user of Rstudio. I'm still using the CRAN distributed R.app.

Related

libfreetype.6.dylib is not loaded (R project using kableExtra; renv for reproducibility)

I'm working on this code, and when I try to knit analyses.Rmd on one of my computers, I get an error specifically due to the attempt to load kableExtra:
Error: package or namespace load failed for ‘kableExtra’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/acristia/Library/Application Support/renv/cache/v5/R-4.1/x86_64-apple-darwin17.0/systemfonts/1.0.3/5be9fcf8ef6763e8cb13ab009e273a1d/systemfonts/libs/systemfonts.so':
dlopen(/Users/acristia/Library/Application Support/renv/cache/v5/R-4.1/x86_64-apple-darwin17.0/systemfonts/1.0.3/5be9fcf8ef6763e8cb13ab009e273a1d/systemfonts/libs/systemfonts.so, 0x0006): Library not loaded: /usr/local/opt/freetype/lib/libfreetype.6.dylib
Referenced from: /Users/acristia/Library/Application Support/renv/cache/v5/R-4.1/x86_64-apple-darwin17.0/systemfonts/1.0.3/5be9fcf8ef6763e8cb13ab009e273a1d/systemfonts/libs/systemfonts.so
Reason: tried: '/usr/local/opt/freetype/lib/libfreetype.6.dylib' (no such file), '/Library/Frameworks/R.framework/Resources/lib/libfreetype.6.dylib' (no such file), '/Users/acristia/lib/libfreetype.6.dylib' (no such file), '/usr/local/lib/lib
I've checked that:
I have the latest version of R, and Rstudio
I have the latest version of freetype (also run brew doctor & fixed all warnings there)
Since brew was not installing libfreetype where kableExtra expected it, I did sudo mkdir -p /usr/local/opt/freetype/lib/ and sudo ln -s /opt/homebrew/lib/libfreetype.6.dylib /usr/local/opt/freetype/lib/libfreetype.6.dylib MacBook-Air:weirdChildes acristia$ ls /usr/local/opt/freetype/lib/libfreetype.6.dylib
With this, I changed the error from not loaded because it doesn't exist, to not loaded because of wrong architecture:
tried: '/usr/local/opt/freetype/lib/libfreetype.6.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')),
(I also saw a suggestion to do brew install freetype --universal but that command is not recognized.
For context: I migrated my mac account to a new laptop, which is intel / monterey, and this probably means that some basic files are not right.
Or potentially, the error arises because makers of kableExtra need to take into account this new architecture. I did find two open issues mentioning libfreetype in the kableExtra github (one saying the problem was resolved with the latest R version, which is not my case).
For full information on my system, see
renv-diagnostics.txt
You have linked a copy of freetype from your old Apple Silicon homebrew directory, which is /opt/homebrew/lib
For Intel macs, the directory in which homebrew installs the freetype package is /usr/local/lib
Intel macs use the architecture x86_64
Apple Silicon (M1) uses the arm64 architecture.

can't load R package geoR because of incompatible version library version [duplicate]

I have a general question about how to effectively load any kind of external package into R. I have found that many sources detailing this information are simply insufficient, but I will leave out mentioning those respective URLs. I have successfully loaded external packages into R before, but I am having difficulties loading the fgui package.
In my specific case, I cannot load the library fgui into R Studio. First I download directly from CRAN with the command:
install.packages("fgui", lib="~/Documents/R_dir")
This works fine for me. My working directory is set to ~/Documents/R_dir
The next command I use is:
library("fgui", lib.loc="~/Documents/R_dir")
The error I get is:
Error : .onLoad failed in loadNamespace() for 'tcltk', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so, 10): Library not loaded: /opt/X11/lib/libX11.6.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so
Reason: image not found
Error: package or namespace load failed for ‘fgui’
I have examined the thread "Error when trying to load library(ggplot2) in R" but it did not answer my question.
Please help me with any suggestions to get the package fgui to work properly in R Studio and feel free to address the more general issue of effectively loading external packages into R.
tcltk is not a typical package. It's probably already installed on your system and it cannot be installed using the usual install.packages procedure because it is not on CRAN (just like the base packages that come with R, like stats, etc.). Also, tcltk2 is not the same as tcltk; that is a package that expands upon (and depends on) the functionality of tcltk.
So, start with this:
> capabilities("tcltk")
tcltk
TRUE
If that comes back FALSE it means that your R was not built with tcltk support. You don't say what OS you're using, so it's a little bit difficult to help you.
That said, if you're on Linux, you need to rebuild R with tcltk support. This should be relatively straightforward. Basically, make sure Tcl and tk are available on your system in a standard location (something like sudo apt-get install tcl8.5-dev tk8.5-dev) and then rebuild R per usual procedures.
If you're on Mac OS, you're encountering the same error that John Fox describes here in relation to Rcmdr. In short, it's probably one of two things:
A file permission issue related to the directory where you have Tcl installed. To quote Fox: "You can verify the source of this problem by issuing the following command at the R command prompt:
system("ls -ld /usr/local /usr/local/lib /usr/local/lib/libtcl*")
# ls: /usr/local/lib: Permission denied
# ls: /usr/local/lib/libtcl*: Permission denied
# drwx------ 8 root wheel 272 Sep 24 10:21 /usr/local
If the output of the system command looks like the above, you should go to Terminal and do the following: sudo chmod -R a+rX /usr/local and enter your password to change directory permissions.
You have an out-dated version of X-Windows. Try running Mac OS Software Update.
It may also be solvable by creating a symbolic link as described in this answer.
This should never come up on Windows, unless you built R from source without tcl/tk support.
On Arch Linux, tk is a separate package from tcl and both need to be installed:
sudo pacman -S tcl tk
This is given that the output from capabilities("tcltk") with R is TRUE (which means your R is compiled with tcltk support as noted previously in the answers here, this should be the case if you installed it from the arch repos).
The official installation instructions for R say:
Note: the use of X11 (including tcltk) requires XQuartz to be
installed since it is no longer part of OS X. Always re-install
XQuartz when upgrading your OS X to a new major version.
So: Simply (re)install XQuartz if you want to use the tcltk package in R.
delete the X11 file on location : /opt
delete the X11 on application unitiltiy
reinstall X11 again
Problem solved...
For Mac-OS users:
I struggled with this problem recently and found that R-3.1.2 has a bug, which assumes that otool is installed when it is not.
R-3.0.0 (and later) ships with Tck/Tk 8.6.0, so you shouldn't need to install that.
Simply upgrading to a more recent version of R (3.4.2) fixed the problem for me.
I had the same issue and went down a rabbit hole before discovering a simple fix. If you install R from bianry it will include tcltk by default. Just run the installer with the default installation. You can get the .dmg here: https://cran.r-project.org/bin/macosx/
Easiest answer for Mac users:
1- Install tcl-tk using brew:
brew install tcl-tk
2- Run the following code:
ln -s /usr/local/Cellar/tcl-tk/$version/lib/libtcl8.6.dylib /usr/local/lib/libtcl8.6.dylib
ln -s /usr/local/Cellar/tcl-tk/$version/lib/libtk8.6.dylib /usr/local/lib/libtk8.6.dylib
Problem solved!

Error: could not find function "geom_sf"

I'm currently running R version 3.4.2 on Windows and have ggplot2 (via tidyverse) and sf package versions 3.4.2. I'm attempting to map spatial data using the ggplot2 sf kit.
When trying to run geom_sf, I receive an error: could not find function "geom_sf".
When I search the ggplot2 package using ls("package:ggplot2"), geom_sf is not listed in the library files.
I installed devtools and ran devtools::install_github("tidyverse/ggplot2"). However, I receive an error: Installation failed: Failed to connect to raw.githubusercontent.come port 443: Timed out. I assume the firewall at work is halting this connection.
To get around this, I tried downloading the zip manually from https://github.com/tidyverse/ggplot2 and running install.packages('ggplot2-master.zip', lib = 'C:/filepath') and receive the error: package 'ggplot2-master.zip' is not available (for R version 3.4.2). I was getting the same error before I updated from 3.4.1.
TLDR: I'm having the same issue as this user: Error when plotting sf object --- Error: could not find function "geom_sf"
but the solution does not work for me.
Does anyone see where I may be missing something? Or how to access this highly referenced (more streamlined) package?
If you downloaded from the URL you cited then the appropriate next step would be to execute this at the R session command line assuming your package is in the working directory:
install.packages('ggplot2', repo=NULL, lib = 'C:/filepath')
The .zip extension is implicit in trying to install from a binary windows file and you need to tell it NOT to attempt downloading from CRAN.

Error in loading rgl package with Mac OS X

I am trying to install rgl package (0.92.858) for R (2.14.2) under Mac OS X (Lion 10.7.3). When I try to load it (library(rgl)), I get the following error:
Error : .onLoad failed in loadNamespace() for 'rgl', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/2.14/Resources/library/rgl/libs/x86_64/aglrgl.so':
dlopen(/Library/Frameworks/R.framework/Versions/2.14/Resources/library/rgl/libs/x86_64/aglrgl.so, 6): Symbol not found: __ZN3gui13OSXGUIFactory12hasEventLoopEv
Referenced from: /Library/Frameworks/R.framework/Versions/2.14/Resources/library/rgl/libs/x86_64/aglrgl.so
Expected in: dynamic lookup
I have a Mac with Norwegian keyboard. Maybe this has something to do with the issue? However, I get the same error, even though I change the language to U.S. Has anyone experienced similar problem? Any way solving it?
I was having this problem with rgl 0.93.996 on OSX 10.9.2, but then after reinstalling several times I saw "Installing rgl - error: X11 not found but required, configure aborted"
A quick search took me here https://stat.ethz.ch/pipermail/r-sig-mac/2012-March/009077.html
Then I was finally able to get it to work by downloading XQuartz https://www.xquartz.org So it was X11 that was the problem in my case.
It requires building from the source as there is a problem with the path to libpng.dylib path if using the built in source install. The process is:
1) Download the source files from http://download.r-forge.r-project.org/src/contrib/rgl_0.92.879.tar.gz
- You need to download the source files from here since you have to manually install the program.
2) Unzip the files to a convenient location. You can do this by double clicking on the .tar file
3) Open Terminal and navigate to the directory that you placed the files in. I put them on my desktop so the command is:
cd ~/Desktop
4) In Terminal run
R CMD INSTALL --with-libpng-prefix=/usr/X11/lib/ rgl
You can then delete all the files you downloaded. Note that I am running Mac OS X 10.7.3 with R 2.15.0. The specific paths may be slightly different if you are on a different version. You do not need the rgl folder or files after you install them and they can be deleted.
I was still having issues installing from source with special flags or any of the other suggestions in comments and things above. I am using Mac OS X 10.7.3 on a 64-bit MacBook Pro and R 2.15.0
I continued to get the following when loading the rgl package:
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/2.14/Resources/library/rgl/libs/x86_64/aglrgl.so'
I tried the following sub-optimal solution works: Delete the aglrgl.so file. Then try loading the package again.
(This is a suggestion I took from a post by Duncan Murdoch
)
A quick way to delete this file is to type the following into the terminal:
open -a Finder /Library/Frameworks/R.framework/Versions/2.15/Resources/library/rgl/libs/x86_64/
In the new Finder window that pops up, delete the aglrgl.so file, and then close the window. Open the R-GUI, and try loading rgl: library("rgl"). It should work fine, and unfortunately use X11 for the 3D graphics instead of the native Quartz window. For me, this is better than nothing.
The problem is now documented on R-forge :
http://r-forge.r-project.org/tracker/index.php?func=detail&aid=1996&group_id=234&atid=946
You basically have to delete the incriminated file, aglrgl.so. R gives you the file's path in the displayed error message.
The new Mac binary version of rgl 0.92.861 installs on 2.14.2 without error and runs the example code.
Okay solution in my case (OS X Yosemite), first download the RGL source (not binaries) in http://cran.r-project.org/src/contrib/rgl_0.95.1247.tar.gz, extract it, and build the library using this command:
R CMD INSTALL --disable-cocoa --x-includes=/usr/X11/ rgl
and it works like a charm.

Not able to Install R package "Rgraphviz" on Mac OS X Lion

I have spent a lot of time trying to solve this, but still no luck. I am trying to get Rgraphviz to work with R 2.14.1 on a Max OS X Lion
These are the steps I took in order to install and use Rgraphviz on Mac OS X Lion:
Installed graphviz via: sudo port install graphviz
Checked that the installation was successful : pkg-config --modversion libgvc
Result: 2.28.0 <- That means its OK
Under R 2.14.1
source("http://www.bioconductor.org/biocLite.R")
biocLite("Rgraphviz")
Whenever I try to use the library I get the following error
Error : .onLoad failed in loadNamespace() for 'Rgraphviz', details:
call: value[[3L]](cond)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rgraphviz/libs/i386/Rgraphviz.so':
dlopen(/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rgraphviz/libs/i386/Rgraphviz.so, 6): Library not loaded: /usr/local/lib/libgvc.5.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rgraphviz/libs/i386/Rgraphviz.so
Check that (1) graphviz is installed on your system; (2) the installed version of
graphviz matches '2.26.3'; this is the version used to build this Rgraphviz
package; (3) graphviz is accessible to R, e.g., the path to the graphviz 'bin'
directory is in the system 'PATH' variable. See additional instructions in the
'README' file of the Rgraphviz 'source' distribution, available at
Some things I notice
The graphviz suggested in the "help" file is 2.26.3 and the graphviz installed by Mac Ports is 2.28.0, but as it is a newer version I don't think this makes a difference, and besides I can not find v 2.26.3
Suggestion number (3) seems to be the key, but I can't find/don't have a bin directory under graphbiz
Also when I run a locate Rgraphviz.so there are no results.
Any clue towards a solution will be much appreciated,
Thanks a lot!
Thanks for the final answer, the installation seems to work for me! (I still have to check that the package runs properly). Just a quick observation: Graphviz was installed in /usr/local on my machine so that the above command had to be entered as follows:
sudo R CMD INSTALL --configure-args='--with-graphviz=/usr/local' Rgraphviz_1.32.0.tar.gz
One more fail point. If you used Fink to install graphviz, you may still, like me, encounter separate build errors even after you use the configure arguments to point to graphviz, which now look like:
R CMD INSTALL --configure-args='--with-graphviz=/sw' Rgraphviz_1.34.0.tar.gz
The installation will fail during build errors for LL_funcs.c because it is looking for libraries that do not install unless you ALSO install graphviz-dev. You will see this:
In file included from LL_funcs.c:1:
common.h:31:17: error: gvc.h: No such file or directory
common.h:32:22: error: gvplugin.h: No such file or directory
common.h:35:20: error: gvcext.h: No such file or directory
common.h:39:20: error: gvcjob.h: No such file or directory
followed by many more build errors of course. Just be sure to
fink install graphviz-dev

Resources