【问题标题】:Error message installing Rattle for R on macOS 10.14.1在 macOS 10.14.1 上为 R 安装 Rattle 时出现错误消息
【发布时间】:2020-04-15 02:07:48
【问题描述】:

我的 R 控制台是 3.5.1。我想在我的 Mac Mojave 10.14.1 上安装拨浪鼓包。我意识到您必须先安装 RGtk2,但即使“从源代码”加载,仍然会收到错误消息

> install.packages("RGtk2")
--- Please select a CRAN mirror for use in this session ---
Package which is only available in source form, and may need
  compilation of C/C++/Fortran: ‘RGtk2’
Do you want to attempt to install these from sources? (Yes/no/cancel) Yes
installing the source package ‘RGtk2’

trying URL 'https://mirrors.nics.utk.edu/cran/src/contrib/RGtk2_2.20.35.tar.gz'
Content type 'application/x-gzip' length 2793137 bytes (2.7 MB)
==================================================
downloaded 2.7 MB

* installing *source* package ‘RGtk2’ ...
** package ‘RGtk2’ successfully unpacked and MD5 sums checked
checking for pkg-config... no
checking for INTROSPECTION... no
checking for GTK... no
configure: error: GTK version 2.8.0 required
ERROR: configuration failed for package ‘RGtk2’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RGtk2’

The downloaded source packages are in
    ‘/private/var/folders/67/r1c_pfwn5ws6y7rsl2bp_qqh0000gn/T/Rtmpi55PMx/downloaded_packages’
Warning message:
In install.packages("RGtk2") :
  installation of package ‘RGtk2’ had non-zero exit status
> install.packages("GTK")
Warning message:
package ‘GTK’ is not available (for R version 3.5.1) 
> install.packages("RGtk2", dependencies=TRUE)
Package which is only available in source form, and may need
  compilation of C/C++/Fortran: ‘RGtk2’
Do you want to attempt to install these from sources? (Yes/no/cancel) no

【问题讨论】:

    标签: r macos rattle rgtk2


    【解决方案1】:

    这个答案是我最初于 2017 年 8 月在我的 Johns Hopkins Data Science Specialization Community Mentor Github 网站上发布的内容的提炼,以回答学生关于如何在 OS X 上安装 Rattle 以使用 rattle::fancyRpartPlot() 生成精美的 rpart 绘图的问题.

    安装需要 gtk 工具包,在 Mac 上完成此操作的一种方法是,R 3.0 and GTK+ / RGTK2 Error

    1. Install macports — mac 包安装工具

    2. 运行SUDO在mac上安装gtk2
      sudo port install gtk2 ## (X11 -- not aqua)

    3. 导出新路径
      export PATH=/opt/local/bin:/opt/local/sbin:$PATH

    4. 从命令行 R,输入 install rgtk2 with
      install.packages("RGtk2",type="source") 从源代码编译

    5. 安装拨浪鼓包
      install.packages("rattle",type="source")

    注意:要从 RStudio 正确安装 RGtk2,必须首先确认上面列出的 PATH 更改已应用于用于启动 RStudio 的 shell。

    最完整的指令集位于Sebastian Kopf's Gist page,并由我自己在 2017 年 6 月 17 日安装验证。安装后,加载 Rattle 库将在 R 控制台中生成以下输出。

    为了使用fancyRpartPlot(),还需要安装rpart.plot 包。

      install.packages("rpart.plot")
    

    示例:虹膜数据的精美 Rpart 图

    在这里,我们复制了生成带有 caretrattle 的精美树形图所需的代码,该代码在约翰霍普金斯大学数据科学专业实用机器学习讲座中进行了讨论用树预测

      library(caret)
      library(rattle)
      inTrain <- createDataPartition(y = iris$Species,
                                     p = 0.7,
                                     list = FALSE)
      training <- iris[inTrain,]
      testing <- iris[-inTrain,]
      modFit <- train(Species ~ .,method = "rpart",data = training)
      fancyRpartPlot(modFit$finalModel)
    

    【讨论】:

    • 我按照您的说明进行操作,但是当我尝试从 R 提示符安装“RGtk2”时,我收到此消息错误:“install.packages(‚"”中的意外输入
    • @BobHoyt - 嗯...看起来引号被文本编辑器转换为“RGtk2”,试试install.packages("RGtk2",type="source")。注意“不等于”。
    • 这确实让我可以选择再次安装 GTK 2.24.17 (X11),我照做了。然后我收到以下消息 > library(rattle) > rattle() Error in .C("R_gtkInit", length(args), x = args, success = logical(1), : "R_gtkInit" not available for .C( ) 用于包“RGtk2”
    • 我更新了端口,安装了 XQuartz 并按照 Greski 和其他人的所有方法,最后,我能够成功加载 RGtk2 和 Rattle。谢谢
    • 不客气,如果有帮助请采纳。
    猜你喜欢
    • 2020-08-16
    • 2018-01-02
    • 2021-01-27
    • 2021-11-06
    • 2021-07-31
    • 2018-05-17
    • 2019-04-27
    • 2014-06-28
    • 1970-01-01
    相关资源
    最近更新 更多