1

My R console is 3.5.1. I want to install the rattle package on my Mac Mojave 10.14.1. I realize that you have to install RGtk2 first but still got error messaging even when loaded "from source"

> 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
Len Greski
  • 8,565
  • 2
  • 15
  • 28
Bob Hoyt
  • 43
  • 1
  • 4

1 Answers1

1

This answer is a distillation of content I originally posted on my Johns Hopkins Data Science Specialization Community Mentor Github site in August 2017, in response to student questions about how to install Rattle on OS X in order to produce fancy rpart plots with rattle::fancyRpartPlot().

The install requires the gtk toolkit, and on the Mac one way to accomplish this is, per R 3.0 and GTK+ / RGTK2 Error:

  1. Install macports — tool for installing mac packages

  2. run SUDO to install gtk2 on mac
    sudo port install gtk2 ## (X11 -- not aqua)

  3. export new path
    export PATH=/opt/local/bin:/opt/local/sbin:$PATH

  4. From command line R, enter install rgtk2 with
    install.packages("RGtk2",type="source") to compile from source

  5. Install the rattle package
    install.packages("rattle",type="source")

NOTE: For the RGtk2 install to work correctly from RStudio, one must first confirm that the PATH change listed above is applied to the shell that is used to start RStudio.

The most complete set of instructions is located at Sebastian Kopf's Gist page and verified by my own install on June 17, 2017. Once installed, loading the rattle library will generate the following output in the R console.

enter image description here

In order to use fancyRpartPlot(), one will also need to install the rpart.plot package.

  install.packages("rpart.plot")

Example: Fancy Rpart Plot of Iris Data

Here we've replicated the code needed to generate a fancy tree diagram with caret and rattle that is discussed in the Johns Hopkins Data Science Specialization Practical Machine Learning lecture on 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)

enter image description here

Len Greski
  • 8,565
  • 2
  • 15
  • 28
  • I followed your instructions but when I attemped to install "RGtk2" from the R prompt I got this message Error: unexpected input in "install.packages(‚" – Bob Hoyt Dec 09 '18 at 13:27
  • @BobHoyt - Hmm... looks like the quotation marks were converted by the text editor to “RGtk2”, try instead `install.packages("RGtk2",type="source")`. Notice that “ is not equal to ". – Len Greski Dec 09 '18 at 19:40
  • This did give me the option to once again install GTK 2.24.17 (X11), which I did. Then I got the following message > library(rattle) > rattle() Error in .C("R_gtkInit", length(args), x = args, success = logical(1), : "R_gtkInit" not available for .C() for package "RGtk2" – Bob Hoyt Dec 10 '18 at 13:57
  • 1
    I updated the Ports, installed XQuartz and followed every method by Greski and others and finally, I was able to successfully load RGtk2 and Rattle. Thanks – Bob Hoyt Dec 14 '18 at 15:48
  • You're welcome, and please accept the answer if it was helpful. – Len Greski Dec 15 '18 at 12:02