Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in RStudioGD() : Shadow graphics device error: r error 4 (R code execution error)

Tags:

r

rstudio

I am trying to plot using Rstudio. But when I do, plot(cars) which is the basic function, I am getting an Graphics Error in R.
Here is what I have done :

> plot(cars)
Error in RStudioGD() : 
  Shadow graphics device error: r error 4 (R code execution error)

Please guide me through.

like image 856
Avinash Avatar asked Oct 22 '13 09:10

Avinash


1 Answers

Initially, I reinstalled RStudio to the newest version (1.1.442) and, following many advice also the R-base* system (getting to R 3.4.3) using aptitude in the following way:

sudo aptitude reinstall libpangocairo-1.0-0 libpango-1.0-0 sudo aptitude reinstall r-base r-base-core r-base-dev

I used aptitude because it is usually better than apt-get to disentangle intricate dependency trees. Afterwards, when no package was loaded into the environment it was working just fine but any package loading was creating a whole variety of DLL-related errors as follows.

FINAL SOLUTION (NO NEED OF REINSTALL):

The error was showing again as soon as I loaded my self-made library. The real problem is the number of open DLL. If you load too many packages or files you will get to the limit and you will have error messages between maximal number of DLLs reached... or failed to load cairo DLL (this error warning) or even lapack routines cannot be loaded. I had these three error randomly as I loaded my full-of-dependencies-homemade-library.

So I started again looking for a solution. The final one is to allow more DLL and to do so it is enough to set the environmental variable R_MAX_NUM_DLLS to a higher number (I set it to 500). In order to avoid the hassle of setting it every time you can read ?Startup documentation and consequently write R_MAX_NUM_DLLS=500 in your Renviron file R-HOME/etc/Renviron.site. In my case (Ubuntu:16.04 it was /usr/lib/R/etc/Renviron.site. This fixed smoothly the problem.

like image 114
Garini Avatar answered Sep 19 '22 11:09

Garini