简体   繁体   English

RStudioGD() 中的错误:阴影图形设备错误:r 错误 4(R 代码执行错误)

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

I am trying to plot using Rstudio.我正在尝试使用 Rstudio 进行绘图。 But when I do, plot(cars) which is the basic function, I am getting an Graphics Error in R .但是当我这样做时, plot(cars)这是基本功能,我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.请指导我完成。

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:最初,我将 RStudio 重新安装到最新版本(1.1.442),并遵循许多建议,还使用 ​​aptitude 以下列方式使用 R-base* 系统(升级到 R 3.4.3):

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.我使用 aptitude 是因为它通常比 apt-get 更好地解开复杂的依赖树。 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.之后,当没有包被加载到环境中时,它工作得很好,但是任何包加载都会产生各种各样的 DLL 相关错误,如下所示。

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.真正的问题是打开 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 .如果您加载了太多的包或文件,您将达到限制,并且您将在maximal number of DLLs reached...failed to load cairo DLL (此错误警告),甚至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).最后一个是允许更多的 DLL 并且这样做足以将环境变量R_MAX_NUM_DLLS设置为更高的数字(我将其设置为 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 .为了避免每次您可以阅读?Startup文档并因此在您的 Renviron 文件R-HOME/etc/Renviron.site中写入R_MAX_NUM_DLLS=500时设置它的麻烦。 In my case (Ubuntu:16.04 it was /usr/lib/R/etc/Renviron.site . This fixed smoothly the problem.就我而言(Ubuntu:16.04 它是/usr/lib/R/etc/Renviron.site 。这顺利解决了问题。

谢天谢地,我刚刚退出 Rstudio 并重新启动,问题就消失了

Under Ubuntu 13.10 I had the similar issue with rstudio server, tried all different suggestions no work.在 Ubuntu 13.10 下,我在 rstudio 服务器上遇到了类似的问题,尝试了所有不同的建议都没有用。 Finally figured out this way:终于想通了这个办法:

  1. sudo service rstudio-server stop
  2. remove all rstudio related files ( sudo find / -name "rstudio" | xargs sudo rm -r )删除所有 rstudio 相关文件( sudo find / -name "rstudio" | xargs sudo rm -r
  3. uninstall R: sudo apt-get remove r-base-core r-base r-base-dev卸载 R: sudo apt-get remove r-base-core r-base r-base-dev
  4. remove all R related files ( sudo find / -name "R" | xargs sudo rm -r )删除所有 R 相关文件( sudo find / -name "R" | xargs sudo rm -r
  5. re-install R: sudo apt-get install r-base-core r-base r-base-dev重新安装 R: sudo apt-get install r-base-core r-base r-base-dev
  6. test R: making sure plot(cars) works in R, output a pdf file.测试 R:确保 plot(cars) 在 R 中工作,输出一个 pdf 文件。
  7. re-install R studio server: http://www.rstudio.com/ide/download/server重新安装 R studio 服务器: http ://www.rstudio.com/ide/download/server

Solution for error:错误解决方法:

Error in RStudioGD() :

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

In R Studio, navigate to Tools , Global , Graphics (top middle), set Backend to AGG *, Apply , Ok在 R Studio 中,导航到ToolsGlobalGraphics (中上),将Backend设置为AGG *、 ApplyOk

*Depending on your system/installation, you may have other other options in the drop down. *根据您的系统/安装,下拉菜单中可能还有其他选项。 Ex.前任。 AGG , Cairo , Cairo PNG . AGGCairoCairo PNG

AGG is a package which provides graphic devices for R based on the AGG library developed by the late Maxim Shemanarev. AGG是一个基于已故 Maxim Shemanarev 开发的 AGG 库为 R 提供图形设备的包。 AGG provides both higher performance and higher quality than the standard raster devices provided by grDevices. AGG 提供比 grDevices 提供的标准光栅设备更高的性能和更高的质量。 You might need to install AGG.您可能需要安装 AGG。 Compatible with R Studio since v1.4.自 v1.4 起与 R Studio 兼容。

https://ragg.r-lib.org/ https://ragg.r-lib.org/

I had the same issue and found James Mao's answer helpful, but I wanted to avoid reinstalling R so that I would not have to also reinstall all of my R packages.我遇到了同样的问题,发现 James Mao 的回答很有帮助,但我想避免重新安装 R,这样我就不必重新安装所有的 R 包。 I was able to fix the issue by reinstalling RStudio without reinstalling R, which makes sense because the error is with RStudio, not R itself.我能够通过重新安装 RStudio 而不重新安装 R 来解决这个问题,这是有道理的,因为错误出在 RStudio 上,而不是 R 本身。 Here are the instructions:以下是说明:

  1. sudo service rstudio-server stop
  2. remove all rstudio related files ( sudo find / -name "rstudio" | xargs sudo rm -r )删除所有 rstudio 相关文件( sudo find / -name "rstudio" | xargs sudo rm -r
  3. re-install R studio server: http://www.rstudio.com/ide/download/server重新安装 R studio 服务器: http ://www.rstudio.com/ide/download/server

Reinstall the package ggplot2 (install.packages"ggplot2") and invoke the library.重新安装包 ggplot2 (install.packages"ggplot2") 并调用库。 It must work then它必须工作

I meet this today, reindatall Rstudio still can't solve.我今天遇到这个,reindatall Rstudio 仍然无法解决。 finally installed textshaping install.packages('textshaping').终于安装了 textshaping install.packages('textshaping')。 It's ok now现在好了

I had the following error in a CentOS:7 Docker container when running rstudio-server verify-installation :运行rstudio-server verify-installation时,我在 CentOS:7 Docker 容器中出现以下错误:

27 Feb 2017 14:17:09 [rsession-rstudio-server] ERROR r error 4 (R code execution error) [errormsg=Error in system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE) :
  error in running command
]; OCCURRED AT: rstudio::core::Error rstudio::r::exec::<unnamed>::evaluateExpressionsUnsafe(SEXPREC*, SEXPREC*, SEXPREC**, rstudio::r::sexp::Protect*, rstudio::r::exec::<unnamed>::EvalType) /root/rstudio/src/cpp/r/RExec.cpp:159; LOGGED FROM: rstudio::core::FilePath rstudio::session::module_context::findProgram(const std::string&) /root/rstudio/src/cpp/session/SessionModuleContext.cpp:879
27 Feb 2017 14:17:09 [rsession-rstudio-server] ERROR r error 4 (R code execution error) [errormsg=Error in system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE) :
  error in running command
]; OCCURRED AT: rstudio::core::Error rstudio::r::exec::<unnamed>::evaluateExpressionsUnsafe(SEXPREC*, SEXPREC*, SEXPREC**, rstudio::r::sexp::Protect*, rstudio::r::exec::<unnamed>::EvalType) /root/rstudio/src/cpp/r/RExec.cpp:159; LOGGED FROM: rstudio::core::FilePath rstudio::session::module_context::findProgram(const std::string&) /root/rstudio/src/cpp/session/SessionModuleContext.cpp:879

I fixed it by installing which command: yum install which我通过安装which命令修复它: yum install which

I had the same error and am on Ubuntu.我有同样的错误,我在 Ubuntu 上。 I did not install R through sudo apt-get install r-base but instead downloaded a specific version , unpacked it and installed it manually with:我没有通过sudo apt-get install r-base ,而是下载了特定版本,将其解压缩并手动安装:

./configure --with-readline=no --with-x=no --enable-R-shlib
make
sudo make install

I did not have cairograpghics installed, which is apparently important to build 2D graphics with R. So I installed that with:我没有安装 cairograpghics,这对于使用 R 构建 2D 图形显然很重要。所以我安装了它:

sudo apt-get install libcairo2-dev

Or find the version for your OS here: https://www.cairographics.org/download/或者在这里找到适合您操作系统的版本: https ://www.cairographics.org/download/

I then uninstalled R again by simply going into the downloaded R folder that I had previously compiled using the above commands mentioned and typed:然后我再次卸载 R,只需进入我之前使用上述命令编译的下载的 R 文件夹并输入:

sudo make uninstall

And then I configured and installed the same R version again.然后我再次配置并安装了相同的 R 版本。 That did it.做到了。 The uninstall and reinstall was important, just installing cairographics didnt work, you have to have it installed before using ./configure .卸载和重新安装很重要,只是安装 cairographics 不起作用,您必须在使用./configure之前安装它。

I had the same problem (even though I had been using the same installation for over a year without this problem).我遇到了同样的问题(即使我已经使用相同的安装一年多了没有这个问题)。 I just needed to restart the computer and everything was good again.我只需要重新启动计算机,一切就又好了。 :D :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM