Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R crashing while displaying ggplot after update (process memory read out of range)

Tags:

r

ggplot2

rstudio

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.

like image 576
Elle Avatar asked May 21 '21 14:05

Elle


Video Answer


1 Answers

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.

like image 91
Ben Bolker Avatar answered Oct 23 '22 04:10

Ben Bolker