Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A brief note on how to install rattle/RGtk2 on macOS

Installing Rattle on MacOS 10.11 (or above)

This document describes steps to successfully install Rattle R Analytic Tool To Learn Easily on macOS 10.11 or above. If you have a macOS lower than 10.11, I recommend you upgrade your system to the newest one (10.12 macOS Sierra using App Store. Without macOS 10.11 or above, you cannot install R 3.4, let alone RGtk2, which now only supports the newest R version.

Throughout the steps to get your Rattle working, we will be using Terminal. You can open it by using Spotlight Search (you can open it by command+space, which is the default shortcut). Type terminal and you will be able to find it and open it.

Note that starting from step 7, I mainly followed instructions on @williamtellme123's comment (the second to last)

  1. Enter the following command in terminal to check your macOS version. Expected output is as below the dashed line ---.
~$ sw_vers
------------------------
ProductName:	Mac OS X
ProductVersion:	10.12.6
BuildVersion:	16G29
  1. If your system is above 10.11, continue. Otherwise, upgrade it to Sierra.

  2. Install homebrew, which is a very convenient package manager for macOS. Copy the following command in terminal and hit Enter:

~$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Follow the instructions to get brew ready. When inputing your password, nothing will show up for security reasons. Just hit Enter when you're finished.

  1. When brew is finished, copy the following command in terminal and hit Enter:
~$ touch ~/.bash_profile
~$ echo "export PATH=/usr/local/bin:$PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib/pkgconfig/gtk+-2.0.pc:/opt/X11/lib/pkgconfig" >> ~/.bash_profile
~$ source ~/.bash_profile
  1. Next, check your R version:
~$ R --version
-------------------------------------------------------------
R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin16.6.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
http://www.gnu.org/licenses/.
  1. If yours is 3.4, continue. Otherwise, upgrade it.

  2. Enter the following into your terminal:

~$ brew uninstall --force cairo --ignore-dependencies
~$ brew cask install xquartz 
~$ brew install --with-x11 cairo
  1. Next, we need to tell brew to change the way it wants to install gtk+:
~$ brew edit gtk+

Then, a text editor window will pop up. Note that if you are not familiar with vim, run export EDITOR=emacs in terminal before the line above to force using emacs, where you can use it as other common text editors.

Find where there is something like this:

def install
	args = [
    		"--disable-dependency-tracking",
			"--disable-silent-rules",
			"--prefix=#{prefix}",
			"--disable-glibtest",
			"--enable-introspection=yes",
			# "--disable-visibility",
			# "--with-gdktarget=quartz",
			"--with-gdktarget=x11",
			"--enable-x11-backend"
		   ]

The original version that you just opened will be exactly the same, except the bottom two lines. Replace the whole chunk by this one. Then hit ctrl+x ctrl+c, followed by y to quit emacs.

  1. Now we can install gtk+ by:
~$ brew install --build-from-source --verbose gtk+

After installation succeeds, add this to your ~/.bash_profile file: export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib/pkgconfig/gtk+-2.0.pc:/opt/X11/lib/pkgconfig. Otherwise, gtk+ will not be recognized.

  1. Download the source file for RGtk2 from https://cran.r-project.org/src/contrib/RGtk2_2.20.33.tar.gz.

  2. Assume that the path to this file is ~/Downloads. Run the following in terminal:

~$ cd ~/Downloads
~/Downloads$ R CMD INSTALL RGtk2_2.20.33.tar.gz

Some people mention that when they finished downloading the file, the filename became RGtk2_2.20.33.tar, missing the trailing .gz extension. If that's the case, use the exact filename that sits in the directory. (Tip: use tab to help autocomplete.)

  1. When it finishes, open XQuartz by using spotlight search.

  2. A window that's very similar to terminal will pop up. Type r and hit enter to open R.

  3. In R, run:

>> install.packages("https://togaware.com/access/rattle_5.0.14.tar.gz", repos=NULL, type="source")
  1. Then try rattle library:
>> library(rattle)
>> rattle()
  1. Rattle will show up and it may ask you whether to install XML and cairoDevice. Click yes for both and you should be good to go now.

paterfamilias commented Sep 21, 2017

I have OS 10.11.4 running on a 2014 iMac, and R 3.4.1. This process breaks for me at step 9 with "Error: gtk+ 2.24.31 did not build"
Has something changed in the past few weeks, or am I doing something wrong?
UPDATE: It looks like I needed to reinstall Xquartz. I did that, the installation went fine (and took a lot longer), and everything seems to work now. Thanks for posting these instructions!

suzliz commented Sep 30, 2017

Thanks a million - it worked!

fallsit commented Oct 11, 2017

I have macOS Sierra 10.12.6, and R version R version 3.4.2. At the step14. It shows some error as below:

trying URL 'https://togaware.com/access/rattle_5.0.14.tar.gz'
Content type 'application/x-tar' length 2993321 bytes (2.9 MB)

downloaded 2.9 MB

ERROR: dependency 'RGtk2' is not available for package 'rattle'

  • removing '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rattle'
    Warning message:
    In install.packages("https://togaware.com/access/rattle_5.0.14.tar.gz", :
    installation of package '/var/folders/hv/4yplv0596sbblcds_jj2_6k80000gn/T//RtmpRgZAKq/downloaded_packages/rattle_5.0.14.tar.gz' had non-zero exit status

Is it something wrong with my steps?

Many thanks for this. Worked for me with Sierra 10.12.6 and R version 3.4.2. Enabled me to install RQDA.

Owner

zhiyzuo commented Oct 19, 2017

@fallsit, I have not seen an error like this. Any updates now?

foohm71 commented Oct 19, 2017

I am getting this when doing "R CMD INSTALL RGtk2_2.20.33.tar.gz"

configure: error: GTK version 2.8.0 required

I am on MacOS Sierra 10.12.6, R version is 3.4.2
When I did "brew install --build-from-source --verbose gtk+" it installed GTK 2.24.31_1

Owner

zhiyzuo commented Oct 20, 2017

@foohm71. Can you do a brew doctor to see if any related message comes up?

foohm71 commented Oct 20, 2017

Not sure if these could cause issues:

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
/usr/local/lib/libtcl8.6.dylib
/usr/local/lib/libtk8.6.dylib

Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .pc files:
/usr/local/lib/pkgconfig/tcl.pc
/usr/local/lib/pkgconfig/tk.pc

Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
/usr/local/lib/libtclstub8.6.a
/usr/local/lib/libtkstub8.6.a

uiang commented Oct 23, 2017

I am on MacOS Sierra 10.12.6 and have R version 3.4.2.
At the step11 it shows an error as below:

R session is headless; GTK+ not initialized.
Error: package or namespace load failed for ‘RGtk2’:
.onLoad failed in loadNamespace() for 'RGtk2', details:
call: .RGtkCall("S_gtk_builder_get_type", PACKAGE = "RGtk2")
error: object has no G type

Owner

zhiyzuo commented Nov 1, 2017

@foohm71 Can you find gtk related folder in /usr/local/Cellar ?

Owner

zhiyzuo commented Nov 1, 2017

@uiang what did you run to get this error?

Owner

zhiyzuo commented Nov 13, 2017

@foohm71, @uiang. See the my revision at step 10 to see if that helps.

berkorbay commented Nov 15, 2017

One important point might be the removal of gtk+ with brew uninstall. Because if you already have gtk+ on your system, brew will ignore your attempt. If that's the case use;

brew uninstall gtk+ --ignore-dependencies

p.s. Amazing tutorial btw.

zvada commented Nov 16, 2017

That's fantastic tutorial, I spent hours to install rattle but without finding this guide I wouldn't succeed! Thanks a lot!!! OS X El Captain (10.11.6) and R version 3.4.2 was my case, though. To uninstall gtk+ I haven't used flag --ignore-dependences.

Thanks a million - it worked!!!! 👍

sanromd commented Nov 28, 2017

Hello, great tutorial, thanks for sharing. I am having an issue at step 7 and I am unable to install cairo. The output of brew install --with-x11 cairo is below. I am running MacOs High Sierra 10.13.1 and gcc 7.2. What could be the error?

`~ brew install --with-x11 cairo
==> Downloading https://cairographics.org/releases/cairo-1.14.10.tar.xz
Already downloaded: /Users/sanromd/Library/Caches/Homebrew/cairo-1.14.10.tar.xz
==> ./configure --prefix=/usr/local/Cellar/cairo/1.14.10 --enable-gobject=yes --enable-svg=yes --enable-tee=yes --enable-quartz-image --enable-xcb=yes --enable-xlib=yes --enable-xlib-xrender=yes
Last 15 lines from /Users/username/Library/Logs/Homebrew/cairo/01.configure:
configure: WARNING: CoreGraphics/CoreGraphics.h: present but cannot be compiled
configure: WARNING: CoreGraphics/CoreGraphics.h: check for missing prerequisite headers?
configure: WARNING: CoreGraphics/CoreGraphics.h: see the Autoconf documentation
configure: WARNING: CoreGraphics/CoreGraphics.h: section "Present But Cannot Be Compiled"
configure: WARNING: CoreGraphics/CoreGraphics.h: proceeding with the compiler's result
configure: WARNING: ## ---------------------------------------------------------------------- ##
configure: WARNING: ## Report this to http://bugs.freedesktop.org/enter_bug.cgi?product=cairo ##
configure: WARNING: ## ---------------------------------------------------------------------- ##
checking for CoreGraphics/CoreGraphics.h... no
checking whether cairo's Quartz surface backend feature could be enabled... no (requires CoreGraphics framework)
checking for cairo's Quartz font backend feature...
checking whether cairo's Quartz font backend feature could be enabled... no (requires CoreGraphics framework)
checking for cairo's Quartz Image surface backend feature...
checking whether cairo's Quartz Image surface backend feature could be enabled... no (requires CoreGraphics framework)

configure: error: Quartz Image surface backend feature could not be enabled`

jingyuzheng commented Dec 5, 2017

Hello! It shows the error below when I did this ~/Downloads$ R CMD INSTALL RGtk2_2.20.33.tar.gz:
Rgtk.c:7:10: fatal error: 'gdk/gdkx.h' file not found
#include <gdk/gdkx.h>
^
1 error generated.
make: *** [Rgtk.o] Error 1
ERROR: compilation failed for package ‘RGtk2’

  • removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RGtk2’

Any idea on how to solve this problem? Thanks in advance!! ps: very helpful tutorial! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment