我的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
答案 0 :(得分:1)
这个答案是我最初于2017年8月在我的Johns Hopkins Data Science Specialization Community Mentor Github网站上发布的内容的汇总,以回应学生有关如何在OS X上安装Rattle以产生精美rpart
地块的问题与rattle::fancyRpartPlot()
。
安装需要gtk工具包,而在Mac上,一种实现方法是按照R 3.0 and GTK+ / RGTK2 Error:
sudo port install gtk2 ## (X11 -- not aqua)
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
install.packages("RGtk2",type="source")
的install rgtk2以从源代码进行编译install.packages("rattle",type="source")
注意:为了使RGtk2
安装能够从RStudio正常运行,必须首先确认上面列出的PATH
更改已应用于用于启动的Shell RStudio。
最完整的说明集位于Sebastian Kopf's Gist page,并于2017年6月17日通过我自己的安装进行了验证。安装完成后,加载手摇铃库将在R控制台中生成以下输出。
要使用fancyRpartPlot()
,还需要安装rpart.plot
软件包。
install.packages("rpart.plot")
这里,我们用caret
和rattle
复制了生成花式树图所需的代码,约翰霍普金斯大学数据科学专业实践机器学习讲座对此进行了讨论在用树预测上。
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)