1

我的 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
4

1 回答 1

1

这个答案是我最初于 2017 年 8 月在我的约翰霍普金斯大学数据科学专业社区导师Github 网站上发布的内容的提炼,以回答学生有关如何在 OS X 上安装 Rattle 以rpart使用rattle::fancyRpartPlot().

安装需要 gtk 工具包,在 Mac 上实现此目的的一种方法是,根据R 3.0 和 GTK+ / RGTK2 错误

  1. 安装 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")

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

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

在此处输入图像描述

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

  install.packages("rpart.plot")

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

在这里,我们复制了生成花哨的树形图所需的代码,caretrattle在 Johns Hopkins Data Science Specialization Practical Machine Learning讲座中的Predicting with Trees中进行了讨论。

  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)

在此处输入图像描述

于 2018-12-08T22:07:31.303 回答