Error in loading rgl package with Mac OS X - r

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.

Related

unicode in ggplot pdf output if Cairo is broken

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.

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!

How to save plots to the file system

I followed the steps mentioned here:
http://www.stat.berkeley.edu/~s133/saving.html
xyz <- c(1:4)
yz <- c(10,20,30,40)
jpeg('rplot.jpg')
plot(xyz,yz)
dev.off()
and get the following error:
Warning messages:
1: In jpeg("rplot.jpg") :
unable to load shared object '/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so':
dlopen(/Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so, 6): Library not loaded: /usr/X11/lib/libXrender.1.dylib
Referenced from: /Library/Frameworks/R.framework/Resources/library/grDevices/libs//cairo.so
Reason: image not found
2: In jpeg("rplot.jpg") : failed to load cairo DLL
Could anybody suggest what am I doing wrong?
This is clearly on a Mac, code looks correct, throws no error on my Mac, and it suggests that some parts of the grDevices package have gotten corrupted. Unlike vpipkt I think thas is unlikely to have anything to do with how your working directory is set. Since that package is part of the default installation, you will not be able to reinstall it with the GUI package manager. I would recommend reinstalling R.
To get rid of these warnings on my Mac (running OS X El Capitan), I followed this guide. It's for SVGs on OS X Mavericks, but the underlying problem is the same; OS X does not ship with X11 support. You need to download and install XQuartz (there is definitely no need to reinstall R).
After doing this, I ran my code again (in RStudio), but only the first warning disappeared. After logging out, logging back in again, and relaunching RStudio, the second warning also disappeared. I think this process sets XQuartz as your default X11 server.

Problems when trying to load a package in R due to rJava

When I type require(xlsx) in order to load the package xlsx in R, the following messages is shown:
> require(xlsx)
Loading required package: xlsx
Loading required package: xlsxjars
Loading required package: rJava
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: JAVA_HOME cannot be determined from the Registry
Failed with error: ‘package ‘rJava’ could not be loaded’
I've also tried to load the rJava package manually but got this error message:
require(rJava)
Loading required package: rJava
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.
Do you have any suggestion on how to solve the problem?
The reason is probably linked to the fact you are using a 64-bit OS and R version but do not have Java installed with the same architecture.
What you have to do is to download Java 64-bit from this page: https://www.java.com/en/download/manual.jsp
After that just try to reload the xlsx package. You shouldn't need to re-start R or if it does not work restart once.
Its because either one of the Java versions(32 bit/64 bit) is missing from your computer. Try installing both the Jdks and run the code.
After installing the Jdks open R and type the code
system("java -version")
This will give you the version of Jdk installed. Then try loading the rJava package. This worked for me.
I had a similar problem what worked for me was to set JAVA_HOME. I tired it first in R:
Sys.setenv(JAVA_HOME = "C:/Program Files/Java/jdk1.8.0_101/")
And when it actually worked I set it in
System Properties -> Advanced -> Environment Variables
by adding a new System variable. I then restarted R/RStudio and everything worked.
I had a similar issue. It is caused due the dependent package 'rJava'. This problem can be overcome by re-directing the R to use a different JAVA_HOME.
if(Sys.getenv("JAVA_HOME")!=""){
Sys.setenv(JAVA_HOME="")
}
library(rJava)
This worked for me.
If you have this error in RStudio, use Lauren's environmental code above and change your R version to the 32 bit version in Tools, Global Options. There should be both 32bit and 64bit R options if you have a newer version. This will require a restart of R, and limit your memory options. Installing the 64 bit version of the jre won't be required though.
An alternative package that you can use is readxl. This package doesn't require external dependencies.
For reading/writing excel files, you can use :
readxl package for reading and writexl package for writing
openxlsx package for reading and writing
With xlsx and XLConnect (which use rjava) you will face memory errors if you have large files
Answer in link resolved my issue.
Before resolution, I tried by adding JAVA_HOME to windows environments. It resolved this error but created another issue. The solution in above link resolves this issue without creating additional issues.
If you have this issue with macOS, there is no easy way here: ( Especially, when you want to use R3.4. I have been there already.
R 3.4, rJava, macOS and even more mess
For R3.3 it's a little bit easier (R3.3 was compiled using different compiler).
R, Java, rJava and macOS adventures
For me, I simply needed to make sure the Java was 64-bit (to match R).
Here's how I downloaded and installed 64-bit Java:
Go to: https://www.java.com/en/download/manual.jsp
Click on "Windows Offline (64-bit)"
Install it (you may need to find the file that downloaded and double click it, or it may automatically install)
Close and reopen your R/RStudio session
Everything will work as expected!

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