When plotting something with the rgl package for R on an Ubuntu 22.04 LTS machine, how can I get any plot output?
When I run a plot command, I am not getting any plot window or visual output. E.g., the README of rgl suggests the following to run a demo:
library("rgl")
demo("rgl")
but it shows no plot windows when I browse through the demos (by hitting return several times). All I get is text in the R console.
What I have tried:
I noticed the following during the rgl package installation:
install.packages("rgl")
This completes without error, but I get the following message during the configure phase of the build process:
checking for X... no
configure: WARNING: X11 not found, continuing without OpenGL support.
and if I load rgl afterwards, using library(rgl), you get a notice:
library(rgl)
This build of rgl does not include OpenGL functions. Use
rglwidget() to display results, e.g. via options(rgl.printRglwidget = TRUE).
If I follow the advice given there, i.e., first run options(rgl.printRglwidget = TRUE); demo(rgl);, then it opens one tab in my browser (firefox) per demo, and all tabs show File not found errors for temporary files like /tmp/RtmpWqj4zX/viewhtml53511cd8b2f5/index.html..
I am running a graphical user interface, so I found it strange that X11 was not being found, maybe this is because my system is using Wayland: grep -i wayland /etc/gdm3/custom.conf outputs WaylandEnable=true. However, this is pure speculation.
To repeat, my question is, how can I get rgl plot output under Ubuntu 22.04? I would prefer to have an X11 window open, but the browser-based rendering would be better than nothing.
System info:
Ubuntu version (the VERSION of cat /etc/os-release): 22.04.1 LTS (Jammy Jellyfish)
R version (from R --version in shell): 4.1.2 (2021-11-01) -- "Bird Hippie"
rgl version (from packageVersion("rgl") in R): 0.110.2
Note: This is a machine under control of our IT department, I have no root access.
Related
Using R version 4.1.2 on Ubuntu 20.04, I run hist(10). The error says
X11 font -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*, face 2 at size 14 could not be loaded
I find two things on google. This thread I can't understand, and this thread suggests I build R differently. I did recently build R from source, without the cairo flag recommended by the Bio-Deago github thread, but I have now replaced it with a binary from Rstudio, and the problem persists. Any suggestions? Thanks!
EDIT: the problem only occurs in Rstudio, not when I run R through a terminal.
R gets installed to different places depending on whether you install from source or as a binary: see this, which says:
For versions of R installed by system package managers (e.g. r-base on Debian or Ubuntu) this will be /usr/bin/R. For versions of R installed from source this will typically (but not always) be /usr/local/bin/R.
Rstudio looks first at which R, which in this case is the version from source. I deleted the source version (target of symlink at which R). Then when I ran R in a terminal, said R is not installed. Then, I followed the Rstudio binary install instructions mentioned in the question. I followed them from the beginning even though I had already installed an Rstudio binary. Now I can run hist(10) and get a plot as expected.
I just updated to R 4.1.0 and re-installed my packages and Rstudio (on Ubuntu 20.04). Now R runs out of memory and crashes when I try to make any ggplot. The error message is long and I can't fully read it because the R session immediately aborts, but it mentions "missing nul terminator", "process memory read out of range" and a bunch of lines of [XXXX:XXXX:YYYYYYYY,ZZZZZZ,AAAAAA ERROR: elf_dynamic_array_reader.h:61] tag not found and finally [XXXX:XXXX:YYYYYYYY,ZZZZZZ,AAAAAA] ERROR directory_reader_posix.cc:42] opendir: No such file or directory (2) (where X, Y, Z, and A are numbers).
I originally got this error with my data but it seems to happen with any ggplot:
library(ggplot2)
ggplot(mtcars, aes(x = cyl, y = mpg)) + geom_boxplot()
I think it's to do with actually displaying the plot because it doesn't crash when I save the plot into a variable and then ggsave() it, and the resulting file is fine. It's also OK when I do ggplot(...) within a function with ggsave() in the next line.
The same plot in base R works fine.
boxplot(mpg~cyl, data = mtcars)
==> displays boxplot in the Plots pane
Reinstalling ggplot2 with install.packages() didn't fix the problem, and I tried to sudo apt install ./rstudio-1.4.1106-amd64.deb again but it just says Rstudio is already the newest version.
This tweet from Kevin Ushey says:
PSA: If you're an RStudio user planning to upgrade to R 4.1.0, you may want to install the preview release of RStudio (https://rstudio.com/products/rstudio/download/preview/) -- otherwise, you may see RStudio crash when you try to use ggplot2.
The version number is "1.4.1714-2 Preview", so well ahead of the 1.4.1106 version you're installing via apt. Release notes on that page include
Support for the upcoming R 4.1.0 release, including the new |> pipe, (x) function shorthand, and new graphics engine.
Another alternative would be to downgrade R to an older version; for Windows the 4.0.5 binary appears to be available here. Unfortunately, the MacOS download page only appears to offer 3.6.3 in previous versions (not any 4.0.x releases) — which feels like a long way to downgrade.
I just had this same issue and checked RStudio for an update. They now have, at the time of writing this, version 1.4.1717 for Debian/Ubuntu (I am running Ubuntu 20). Updating has fixed my ggplot issue with the same warnings.
I am trying to understand why capabilities() are not the same between R running in the console and RStudio despite that both use the same R binaries.
In the console:
In RStudio:
I only have 1 R installation:
> Sys.getenv("R_HOME")
[1] "/usr/local/lib/R"
Because dynamic libraries may need to be changed by RStudio for its display purposes? On Linux it is well known that via the LD_PRELOAD trick you can get yourself different libraries (for, say, debug versions). Maybe Cairo gets in the way? (And there are add-on packages for Cairo-based graphics too, and now the ragg package and ....) It could also be on purpose.
In my case (on Linux using the CRAN-mirrored Ubuntu binary by Michael based on my Debian package of R), all capabilities() appear to be the same and TRUE (with the exception of aqua, but RStudio Server for example has X11 as FALSE where as RStudio (desktop) still has it. All seems to make sense to me :)
I initially tried, using RStudio, to install rgl using install.packages("rgl"), which appeared to have worked. It did give me a message that the binary is older than the source, and that it would install from the binary, but I received no other messages. However library(rgl) gets stuck and doesn't do anything.
I removed the package using remove.packages(rgl), and attempted to install from source using R CMD INSTALL rgl_0.95.1409.tar.gz. That gets stuck on "testing if installed package can be loaded." I had X11 installed, but I downloaded XQuartz 2.7.8 and tried again, with the same result.
?rgl::plot3d in RStudio does take me to the documentation for the plot3d function, so I think it installed, just not completely/successfully (rgl::plot3d as an attempt to call the plot3d function also results in endless computation).
However, I finally did manage to load rgl (and use plot3d) by manually launching the Xapp from the Terminal prior to loading the library in my current R session (just X in Terminal, xterm by itself doesn't seem to have the same effect). Can anyone explain why this might be the case, and if there is a workaround to avoid having to manually launch the Xapp? (I do not want to have an application running when I do not need it, but I will also probably sometimes forget to launch the Xapp prior to running this script.)
I'm running OS X Yosemite (10.10.5), RStudio 0.98.1103, R 3.1.3 3.2.2.
The 'rgl' package does not use XQuartz, but rather opens a separate X11 window. Not being able to launch X(11) automatically makes me think that either your system PATH does not have the X11 server in the search path or an environment variable needs to be fixed. I wasn't able to see any differences in the Sys.getenv() results after loading rgl but I see that I have these in my PATH: /usr/X11/bin:/usr/X11R6/bin1
For a while I was rather confused about this as well. The XQuartz.app appeared very similar to the the X11.app , showing up with the very similar icons, (both appearing in the Taskbar as "X".)
I'm running Mac OS Maverick.
In my previous setup, the plots would correctly display on the plot tab on RStudio.
I reinstalled R with homebrew and, when I use RStudio, it gives me the following warning
WARNING: The version of R you are running against does not support the
quartz graphics device (which is required by RStudio for graphics).
The Plots tab will be disabled until a version of R that supports
quartz is installed.
When I plot something, it opens up the XQuartz app on my mac. It does display the graphs (sometimes with weird colors though), but I'd really like it to plot in RStudio itself.
Is it that homebrew has a version of R that doesn't support the quartz graphics device or have I messed up something elsewhere?
As always, any help will be very much appreciated.
Some details of my setup:
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
RStudio Version 0.98.1091
Platform: x86_64-apple-darwin13.4.0 (64-bit). Mac OS 10.9.5
I installed R with homebrew the following way
brew tap homebrew/science
brew install r
Previously I had installed tcl/tk the following way
brew tap homebrew/dupes
brew install tcl-tk --with-tk
I run into the same issue.
According to the R brew formula history the last bottled version (i.e. precompiled version, which is what is installed by default) isn't run against aqua due to some bug so the installation of R has no aqua capabilities, which is what RStudio graphics device requires.
After trying to understand the formula logic I figured that if built from source:
brew install r --build-from-source
it would compile with clang (check brew --env) and therefore correctly build against aqua. It takes a little longer to install but it worked for me. To check, from the terminal open R and see capabilities() aqua should be TRUE for RStudio's graphics device to work.
I'm using homebrewed R and Rstudio on Yosemite. I ran into the same problem, probably after I had updated R from ver. 3.1.2 to ver. 3.1.2_1.
My ad-hoc solution is
to brew uninstall R, and
to install R from CRAN.
RStudio display graphs inside its window when I use CRAN version of R. However, this is not the best solution to me, because I love to manage all unix packages using homebrew to avoid possible conflicts.
I ran into this problem too. I previously had homebrewed R installation with a working quartz graphic device, which comports with others in this thread who suggest that an update to homebrew's R script caused the problem.
I can confirm that daniel's answer works. I tried brew install r --build-from-source and quartz() has stopped throwing errors.