Rstudio and R both freeze when plotting with plot() and ggplot() - r

I have a problem since that has to do with plotting in R and Rstudio. I am using a MacBook Pro 14'' with macOS Monterey Version 12.1. The RStudio version is 2022.12.0+353 (2022.12.0+353), and the R version is 4.2.2.
I was previously using R 4.2.0 and a previous version of RStudio and still the plots did not show up.
What happens is that as soon as I try to plot anything, the panel freezes and the only way to go forward is to press the red "stop" button of the console. Usually, the only way to go is to restart R because pressing the stop button is not enough. It happens with any plotting function that I am aware of, including ggplot(), hist(), and plot().
I have already tried to restart the laptop, to unload the packages and to update them.
Did anybody encounter a similar issue? It's quite puzzling to me.
Thanks,
Marco
I have already tried to restart the laptop, to unload the packages and to update them.

I solved the problem. my system did not recognise the Arial font. After installing it manually, ggplot worked again.
Thanks!
M

Related

Problems with new R version [duplicate]

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.

RStudio does not render Plotly plot on new machine

I bought a new laptop a few days ago (Windows 10) and installed R 4.0.0 and the last RStudio version (Desktop 1.2.5042) on it. Subsequently I ran the rtools40 installer and installed the latest versions of the popular R packages (including ggplot, plotly and so on). Everything seems to work, except for the RStduio viewer pane when trying to render a plotly plot. What happens is that, when I run a minimal example (like this https://plotly.com/r/line-charts/) the view pane is activated, but no plot is rendered. Also no error is raised and the RStudio R session starts draining a lot of CPU capacity, although no code is apparently running (e.g. I can run a plot() and it will be properly displayed in the plot pane).
Now, I've tried downgrading and running RStudio (3.x) from Anaconda - neither worked.
Also - my browser wold not render local plotly plots, bit it would render external plots (like in the example above https://plotly.com/r/line-charts/).
Any ideas?
Apparently it is an issue with R 4.0 and RStudio 1.2.5042 on Windows 10 x64:
https://github.com/rstudio/rstudio/issues/6737
I downgraded to R 3.6.1 and RStudio 1.2.5042 and the problem is gone.
RStudio is due to fix the issue with its v1.3-patch.

RStudio Viewer can't visualize plotly map

I am very new to ploty package and I am learning to make some interective maps.
I found the code below on https://plot.ly/r/choropleth-maps/#new-to-plotly
and I would like to reproduce it, but the R Viewer window doesn't show the map, only the scale bar.
I have already updated my RStudio version with 3.6.1
I tried to update my release version of RStudio, but apparently I can't.
I have download it from https://www.rstudio.com/products/rstudio/download/preview/ and installed it, but when I run
rstudioapi::versionInfo()
the version shown is still
$version
[1] ‘1.0.44’
I found those tips on
https://community.rstudio.com/t/plotly-map-does-not-display-in-viewer-pane/11655/7
Thanks in advance!
Solved, just needed to uninstall and reinstall R and RStudio from scratch.

cannot load rgl package without manually launching Xapp

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".)

Running system command from R console cannot locate installed programs since upgrading to Mac OSX 10.10

I have been having some weird issues with R (3.1.1) and RStudio (0.98.1079) and I suspect that it is due to the fact that these programs are not longer referencing the right places after I upgraded to Mac OSX 10.10.
In particular, I cannot seem to find packages that I know I have installed on my computer to run using the system command in the R console. That is, running man pdflatex in a Terminal window yields the help manual for PDFLATEX. However running system('man pdflatex') from the R console yields the error message No manual entry for pdflatex.
The issue persists even though I reinstalled R, RStudio and MacTex since I upgraded to Mac OSX 10.10. Any help would be appreciated!
Yosemite has a bug wherein some environment variables, including PATH, appear twice in a program's environment with different values. For instance, you might notice that Sys.getenv("PATH") will show you one PATH, and system("echo $PATH") will show you an entirely different one.
I expect that most of your problems are due to this bug.
There are a few workarounds you can try immediately:
You can manually forward PATH yourself. Try this:
> system2("man", "pdflatex", env=paste0("PATH=", Sys.getenv("PATH")))
Or, you can start RStudio from Terminal:
$ open /Applications/RStudio.app
Both the R and RStudio engineers have implemented workarounds in the last few days. R (as of 3.1.2) and RStudio (as of 0.98.1087) should behave as you'd expect.
There are a host of questions about similar problems. All of them appear to come up when you update OS X to either Yosemite or Sierra with an older version of R already installed.
The easiest solution is to completely uninstall R (note the comments about using which R !), and then to install it again.
This also solves problems such as R showing different version numbers in terminal and the GUI.

Resources