Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installation information for R with GTK on Windows/Mac OS

Installation information for R with GTK+

Windows

Install the newest version of R. Additionally, I highly recommend R-Studio for working with R regularly (but the basic command line will work just fine for most applications). Once R is installed, you can install GTK directly from within R (details below). In short:

  1. From the R command line (e.g. in R-Studio), install the RGtk2 package by running: install.packages("RGtk2", depen=T)
    This might fail with the warning that package ‘RGtk2’ is not available (for R version xxx) if your version of R has been released very recently. If so, just run install.packages("RGtk2", depen=T, type="source") instead to install the RGtk2 package directly from its source code (this might take a few minutes).
  2. Then load the package by running: library(RGtk2)
    This will notice the missing GTK and prompt you to install it. Choose "Install GTK+" when prompted, it might take a few minutes to install. Afterwards it will likely still complain (restart required).
  3. Restart R/Rstudio and confirm GTK is now up and running by reloading the package: library(RGtk2)

Note: for some reason on Windows 8, the RGtk2 package is not always recognized during compilation of other source packages, even if it can be loaded and works perfectly fine. If the other package depends on RGtk2 and installation from source fails during package test loading with an error that RGtk2 could not be found, try installing without automatic reload, e.g. in installations from GitHub using devtools, try: install_github(..., reload=F, quick=T).

MacOS

With some versions of R > 3.1 and Mac OS X, GTK+ now works out of the box with the following installation instructions. Certain combinations of R and Mac OS X have trouble with this (details on the problem and instructions on how to work around it below). For example, with R 3.1.1 and Mac OS X 10.9.3 it seems to work mostly without trouble (tested in July 2014), but with R 3.1.2 and Mac OS X 10.10.1, the work-around was necessary again (tested in December 2014). When in doubt, I recommend giving the quick installation below a try and if RGtk2 does not install properly right away, not to waste any time trying to get it to work and instead just taking the work-around route below.

Install the newest version of R. Additionally, I highly recommend R-Studio for working with R regularly (but the basic command line will work just fine for most applications). For graphical user interfaces (GUIs) from R, you need both the X Window System (included by default with Mac OS X before Mountain Lion, i.e. < 10.8) and GTK. In short:

  1. Install R for Mac (get the right one for your version of Mac OS X)
  2. Optional but recommended: install R-Studio
  3. Check if you have the X11 application (relevant for newer versions of Mac OS X such as Mountain Lion, Maverick, Yosemite, etc.): go into your Applications folder and look for X11 in the Utilities subfolder. Start the program. In newer versions of Mac OS X, this will prompt an info box that X11 is no longer included with OS X. If you get this info box, follow the installation instructions to install the X11 replacement XQuartz (you might have to log out and back in after installation)
  4. Install GTK 2.24.
  5. From the R command line (e.g. in R-Studio), install the RGtk2 package by running: install.packages("RGtk2", depen=T)
    This might fail with the warning that package ‘RGtk2’ is not available (for R version xxx) depending on your version of R. If so, you can try to run install.packages("RGtk2", depen=T, type="source") instead to install the RGtk2 package from source (this might take a few minutes and ask you to install the Xcode command line tools - just hit Install and follow the instructions if you get this message, then rerun install.packages("RGtk2", depen=T, type="source")). If installation from source fails, you can try a slighlty older R version that has the binaries or check out the work-around below.
  6. Restart R/Rstudio and confirm GTK is up and running by loading the package: library(RGtk2) (should execute without errors)
Troubleshooting for GTK+ 2.24 issues

R version 3 requires the GTK+ 2.24 framework which does not always work properly out of the box on Mac OS X throwing a malloc error when running the following simple example (or failing even before that during the installation of RGtk2 with an error that claims GTK to be missing, along the lines of configure: error: GTK version 2.8.0 required):

library(gWidgets)
options(guiToolkit="RGtk2")
win <- gwindow("test")
glabel("test label", container = win)

gedit("test text field", container = win)
> guiWidget of type: gEditRGtk for toolkit: guiWidgetsToolkitRGtk2 
> R(9523,0x7fff76be1960) malloc: *** error for object 0x4024000000000000: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug
Abort trap: 6

The problem is documented on stack overflow in some detail. There are two options:

  1. If you're okay running an older version of R, you can install the older GTK+ 2.18 framework (http://r.research.att.com/libs/GTK_2.18.5-X11.pkg) instead and use R 2.15 (http://r.research.att.com/R-2.15-branch-leopard.pkg - works fine with OS X Lion). If you want to run multiple versions of R, no problem, the little helper program RSwitch (http://r.research.att.com/RSwitch-1.2.dmg) provides a simple means for switching back and forth easily. Also, having both GTK+ 2.24 and GTK+ 2.18 installed is no problem either, just make sure the 'Current' symlink in '/Library/Frameworks/GTK+.framework/Versions/' points to 2.18.X11.

  2. There is a relatively straight-forward (but several steps long) work-around that requires installing gtk2 via macports or homebrew and installing the R packages RGtk2 and cairoDevice from source. The approach listed below is inspired by suggestions on stack overflow (especially this contribution from John Verzani and worked well for me and others).

  • install macports, a tool for installing open-source software on MacOS (http://www.macports.org/install.php)
    • macports requires Apple's Xcode command line tools (free but you need an AppleID to download), which include all the necessary compilers for macports (NOTE: newer versions of Mac OS X and certain programs that also require these compilers might ask you directly to install the Xcode command line tools, in which case you don't need an AppleID! for example, the Git App for Mac does this - just hit Install and follow the instructions when you get this message)
    • if needed, you can install the full version of Xcode (~2Gb) or just the command line tools (in either case, make sure to install the latest version for your MacOS version)
      • for the full version, after installation go to the XCode preferences and install the command line tools
      • for the command line tools only, search for command line tools on https://developer.apple.com/downloads/ (the standalone command line tools are not recognized by the MacPorts installers but the warnings can be safely ignored)
  • after installing macports, open a terminal and run the following commands to install GTK (you will be asked for your password), also note that macports might complain about missing XCode if only the command line tools are installed but this is not a problem
  • export PATH=/opt/local/bin:/opt/local/sbin:$PATH
  • sudo port selfupdate
  • sudo port install pkgconfig
  • sudo port install gtk2 +x11 (this may take several minutes)
  • then download the RGtk2 and cairoDevice package source from CRAN:
  • http://cran.r-project.org/web/packages/RGtk2/ - download the package source (RGtk2_version.tar.gz)
  • http://cran.r-project.org/web/packages/cairoDevice/ - download the package source (cairoDevice_version.tar.gz)
  • install the two packages by running the following commands on the terminal (adjust for the correct path to the downloads and the correct version you downloaded, RGtk2 may take several minutes, both may show a few warnings about deprecated code)
  • R CMD INSTALL ~/Downloads/RGtk2_version.tar.gz
  • R CMD INSTALL ~/Downloads/cairoDevice_version.tar.gz
  • Note: this entire installation has to be repeated after operating system upgrades (e.g. from Mavericks to Yosemite, etc.) but only this last step (installing RGtk2 and cairoDevice from source) has to be repeated after upgrading to a new version of R / reinstalling R

To test that the installation was successul, restart R/RStudio and see if RGtk2 now loads without error:

library(RGtk2)

If you want, you can run the following small example too (installs the very user-friendly gWidgets wrapper for RGtk), it should create a simple GUI (Note: some warnings may be printed in RStudio).

install.packages("gWidgets", depen=T)
install.packages("gWidgetsRGtk2", depen=T, type="source") # type="source" only necessary if not available as binary
library(gWidgets)
options(guiToolkit="RGtk2")
win <- gwindow("test")
glabel("test label", container = win)
gedit("test text field", container = win)
@Henri-Lo
Copy link

Henri-Lo commented Jul 17, 2017

@ibusett I tried that but this did not work:

$ wget https://cran.r-project.org/src/contrib/RGtk2_2.20.33.tar.gz
--2017-07-17 14:44:55--  https://cran.r-project.org/src/contrib/RGtk2_2.20.33.tar.gz
Resolving cran.r-project.org... 137.208.57.37
Connecting to cran.r-project.org|137.208.57.37|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2792938 (2.7M) [application/x-gzip]
Saving to: ‘RGtk2_2.20.33.tar.gz’

RGtk2_2.20.33.tar.gz            100%[=====================================================>]   2.66M  1.56MB/s    in 1.7s    

2017-07-17 14:44:58 (1.56 MB/s) - ‘RGtk2_2.20.33.tar.gz’ saved [2792938/2792938]

$ R CMD INSTALL RGtk2_2.20.33.tar.gz 
* installing to library ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library’
ERROR: this R is version 3.3.2, package 'RGtk2' requires R >= 3.4.0

@troehrs
Copy link

troehrs commented Jul 23, 2017

I don't get it... I tried multiple ways to install this package without success.

@charlestsang
Copy link

charlestsang commented Aug 2, 2017

I am with OS Sierra. Using the command line install did help me solve out this problem. Referring to the first post above:

$ R CMD INSTALL -l /Users/username/Library/R/3.0/library ~/downloads/RGtk2_version.tar.gz

The suitable version can be downloaded directly from CRAN:

https://cran.r-project.org/web/packages/RGtk2/index.html

@williamtellme123
Copy link

williamtellme123 commented Aug 11, 2017

Thanks @tobybot11, @kmrozewski-kainos
This worked for me: GTk2 on Sierra (10.12.6)
~ R --version
R version 3.4.1 (2017-06-30) -- "Single Candle"
~ brew uninstall --force cairo --ignore-dependencies
~ brew install --with-x11 cairo
~ brew edit gtk+
def install
args = ["--disable-dependency-tracking",
"--disable-silent-rules",
"--prefix=#{prefix}",
"--disable-glibtest",
"--enable-introspection=yes",
# "--with-gdktarget=quartz",
"--with-gdktarget=x11",
"--enable-x11-backend"
# "--disable-visibility"
]
~ brew install --build-from-source --verbose gtk+
~ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib/pkgconfig/gtk+-2.0.pc:/opt/X11/lib/pkgconfig
~ R CMD INSTALL RGtk2_2.20.33.tar.gz

@cspenn
Copy link

cspenn commented Aug 24, 2017

Thanks @williamtellme123 - this is the ONLY solution I've found that worked for me!

@FangQijun
Copy link

FangQijun commented Sep 9, 2017

@williamtellme123 Thank you soo0000OOO much! I installed RGTk2 by replaying those EXACT steps.

@pnojai
Copy link

pnojai commented Oct 8, 2017

Brilliant. @tobybot11, @kmrozewski-kainos, @williamtellme123, all of you rule.

Forced this sucker to compile. I don't know if it will work, but dang it, it's in there.

I did get a warning that this config, "--enable-x11-backend", wasn't recognized. We'll see. But at least I got my Sunday back.

@sanjulr
Copy link

sanjulr commented Oct 14, 2017

I assume you have R and RStudio installed already. If not, install it. Then do the following.

  1. Install XQuartz

  2. Install GTK 2.24.17-X11

  3. Download cairoDevice and RGtk2

  4. From terminal run R CMD INSTALL ~/Downloads/cairoDevice_2.24.tar.gz

  5. Install Homebrew for Mac.

  6. From terminal type the following commands:

brew uninstall cairo --ignore-dependencies
brew install --with-x11 cairo
  1. Type brew edit gtk+ in terminal and scroll to def install section and edit the reference with quartz to (press i to edit and to save and exit, press escape key and type colon (shift+ semi colon key). Then type wq.)
"--with-gdktarget=x11",
"--enable-x11-backend"
  1. Then type brew install --build-from-source --verbose gtk+ in the same terminal window.

  2. Then type export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib/pkgconfig/gtk+-2.0.pc:/opt/X11/lib/pkgconfig

  3. Type R CMD INSTALL ~/Downloads/RGtk2_2.20.33.tar.gz from the same terminal window.

Hopefully it will work for you.

@dna7gran
Copy link

dna7gran commented Oct 17, 2017

Hi,
I stuck in the last part. I cannot install the RGtk2. I am receiving this error:
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’

can someone please help me?

Thanks

Diana

@berkorbay
Copy link

berkorbay commented Nov 15, 2017

Same 'gdk/gdkx.h' file not found problem here.

SOLVED: https://gist.github.com/zhiyzuo/a489ffdcc5da87f28f8589a55aa206dd

@sanromd
Copy link

sanromd commented Nov 28, 2017

@sebkopf Thanks for the detailed instructions. In MacOS High Sierra I am seeing an error when trying to install cairo via homebrew.

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`

@numoonchld
Copy link

numoonchld commented Dec 28, 2017

I was seeing the mentioned error:

error: GTK version 2.8.0 required):

This worked for me on macOS 10.12.6 and R version 3.4.3 (Kite-Eating Tree):
(I only have Xcode command line tools installed, NOT the full version of Xcode)
(also, I had to remove the .gz in the command line install of RGtk2 and cairoDevice)

install macports, a tool for installing open-source software on MacOS (http://www.macports.org/install.php)
macports requires Apple's Xcode command line tools (free but you need an AppleID to download), which include all the necessary compilers for macports (NOTE: newer versions of Mac OS X and certain programs that also require these compilers might ask you directly to install the Xcode command line tools, in which case you don't need an AppleID! for example, the Git App for Mac does this - just hit Install and follow the instructions when you get this message)
if needed, you can install the full version of Xcode (~2Gb) or just the command line tools (in either case, make sure to install the latest version for your MacOS version)
for the full version, after installation go to the XCode preferences and install the command line tools
for the command line tools only, search for command line tools on https://developer.apple.com/downloads/ (the standalone command line tools are not recognized by the MacPorts installers but the warnings can be safely ignored)
after installing macports, open a terminal and run the following commands to install GTK (you will be asked for your password), also note that macports might complain about missing XCode if only the command line tools are installed but this is not a problem
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
sudo port selfupdate
sudo port install pkgconfig
sudo port install gtk2 +x11 (this may take several minutes)
then download the RGtk2 and cairoDevice package source from CRAN:
http://cran.r-project.org/web/packages/RGtk2/ - download the package source (RGtk2_version.tar.gz)
http://cran.r-project.org/web/packages/cairoDevice/ - download the package source (cairoDevice_version.tar.gz)
install the two packages by running the following commands on the terminal (adjust for the correct path to the downloads and the correct version you downloaded, RGtk2 may take several minutes, both may show a few warnings about deprecated code)
R CMD INSTALL ~/Downloads/RGtk2_<version>.tar
R CMD INSTALL ~/Downloads/cairoDevice_<version>.tar
Note: this entire installation has to be repeated after operating system upgrades (e.g. from Mavericks to Yosemite, etc.) but only this last step (installing RGtk2 and cairoDevice from source) has to be repeated after upgrading to a new version of R / reinstalling R
To test that the installation was successul, restart R/RStudio and see if RGtk2 now loads without error:

library(RGtk2)

Thanks a lot for this info!

@brooksrelyt
Copy link

brooksrelyt commented Jan 25, 2018

[ALTERNATE SOLUTION FOR HIGHSIERRA (10.13.3) BELOW]

None of this above worked for me.

(!!NOTE: Article says OS X 10.9 - ignore that I am on HighSierra 10.13.3 and it worked perfectly!)
Try this: http://marcoghislanzoni.com/blog/2014/08/29/solved-installing-rattle-r-3-1-mac-os-x-10-9/

@bsou
Copy link

bsou commented Jan 29, 2018

I'm running into the following issue while installing RGtk2 on MacOS 10.13.2 and R 3.4.3

$ R CMD INSTALL ~/Downloads/RGtk2_2.20.34.tar.gz

installing to /Library/Frameworks/R.framework/Versions/3.4/Resources/library/RGtk2/libs
** R
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
objc[56473]: Class GNotificationCenterDelegate is implemented in both /opt/local/lib/libgio-2.0.0.dylib (0x105ae2530) and /usr/local/opt/glib/lib/libgio-2.0.0.dylib (0x10537f510). One of the two will be used. Which one is undefined.
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
Error: loading failed
Execution halted
ERROR: loading failed

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

Any help would be greatly appreciated.

@milti
Copy link

milti commented Feb 23, 2018

@sanjulr your instructions worked for me

R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.4

installing RGtk2_20_34

@sjkiss
Copy link

sjkiss commented Jun 14, 2018

Hi there: I am running

R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.4

i followed the steps above and things worked right up to the point when I tried to load RQDA. The install seemed to work but then running library(RQDA) returned this error.

GdkPixbuf-WARNING **: 12:27:14.350: Cannot open pixbuf loader module file '/opt/local/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache': No such file or directory This likely means that your installation is broken. Try running the command gdk-pixbuf-query-loaders > /opt/local/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache

I really don't have any idea what this means.

@oscci
Copy link

oscci commented Jun 24, 2018

This is hugely helpful. Thank you. However, I'm a newbie at using the command line, and so am not sure how to deal with this:
At the point where I do: R CMD INSTALL ~/Downloads/RGtk2_version.tar.gz

I get

ERROR: this R is version 3.3.2, package 'RGtk2' requires R >= 3.4.0.

I have uninstalled R & updated to R3.5.0 and restarted, but it persists in thinking I am on R 3.3.2, so presumably I somehow to reset the default path. Any idea how to do that? Thanks

@oscci
Copy link

oscci commented Jun 24, 2018

Just solved my own problem! It was trying to install into an Anaconda directory that I never use. I have deleted Anaconda and now it is OK

@naalipalo
Copy link

naalipalo commented Nov 14, 2018

I have posted this question in a couple other forums. This is the closest discussion to my issue, however i am not using a Mac, Windows based issue. I can't get RGtk2 to install at all.
I am running R version 3.5.1 (2018-07-02) -- "Feather Spray" Platform: i386-w64-mingw32/i386 (32-bit) RStudio Version 1.1.456

I need to work with MixSIAR package and I am supposed to install several packages to get a GUI to work. However, I can't even get past the first step and it has nothing to do with MixSIAR package....I have tried to install the RGtk2 package and each time I get errors and the install fails, Ive even tried installing outside of R studio and still have issues. I don't know where to start.

install.packages("RGtk2", dependencies = TRUE)

Installing package into ‘C:/Users/myname/Documents/R/win-library/3.5’ (as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/RGtk2_2.20.35.zip'
Content type 'application/zip' length 16250952 bytes (15.5 MB)
downloaded 15.5 MB
package ‘RGtk2’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\myname\AppData\Local\Temp\RtmponDKXU\downloaded_packages

library(RGtk2)

A window pops up with a system error which says

The program can't start because libatk-1.0-0.dll is missing from your computer. Try reinstalling the program to fix this problem

I click OK and the next screen immediately to pop up is

Need GTK+?

I get 2 options:

Install GTK+ or Do not install GTK+

If I click DO NOT install, I get stuck in a loop that RStudio will not let me out of. It immediately sends the system error message again, I click OK and it brings back the Install GTK+ question. This cycle continues until I select Install GTK+ or I kill RStudio manually

When I click install and OK and every time I get this:

Loading required package: RGtk2
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Users/myname/Documents/R/win-library/3.5/RGtk2/libs/i386/RGtk2.dll':
LoadLibrary failure: The specified module could not be found.

trying URL 'http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.22/gtk+-bundle_2.22.1-20101227_win32.zip'
Error: package or namespace load failed for ‘RGtk2’:
.onLoad failed in loadNamespace() for 'RGtk2', details:
call: download.file(dep_url, path, mode = "wb")
error: cannot open URL 'http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.22/gtk+-bundle_2.22.1-20101227_win32.zip'
Error: package ‘RGtk2’ could not be loaded
In addition: Warning messages:
1: Failed to load RGtk2 dynamic library, attempting to install it.
2: In download.file(dep_url, path, mode = "wb") :
InternetOpenUrl failed: 'The operation timed out'

@greebie
Copy link

greebie commented Jan 29, 2020

Installing gtk for High Sierra required the following which is roughly a repeat of this, except GTK has a different method of installation now apparently.

Download gtk setup script for Mac

Build it via jhbuild.

sh gtk-os-setup.sh
jhbuild bootstrap-gtk-osx
jhbuild build meta-gtk-osx-bootstrap meta-gtk-osx-core

Download install Cairo and RGTK2 in the command line

R CMD INSTALL ~/Downloads/cairoDevice_{VERSION}.tar.gz
R CMD INSTALL ~/Downloads/RGtk2_{VERSION}.tar.gz

@maelmm
Copy link

maelmm commented Jun 1, 2020

Thank you for the detailed steps! I had just upgraded to R v4.0.0, macOS Catalina 10.15.4 and Rstudio Version 1.2.5042 when I had to install the GTK2 package. All I had to do was to follow the steps in the first original posts and it worked like magic! Thanks again!

@inesanchondo
Copy link

inesanchondo commented Mar 20, 2021

I have followed all of the instructions above, except I do not know how to download the script for Mac as greebie mentions.
I still cannot install RGTk2 package. I have downloaded the package, but it is not installed. I get the message below, I'd appreciate any help. Thank you!

Loading required package: RGtk2
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RGtk2/libs/RGtk2.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RGtk2/libs/RGtk2.so, 6): Library not loaded: /usr/local/opt/gtk+/lib/libgtk-quartz-2.0.0.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RGtk2/libs/RGtk2.so
Reason: image not found

@alvaroiramirez
Copy link

alvaroiramirez commented Dec 30, 2021

Hi,

I am getting this error when installing RGtk2 on RStudio 2021.09.1 Build 372 on Windows 10:

> install.packages("RGtk2", depen=T, type="source")
Installing package into ‘C:/Users/alvar/OneDrive/Documents/R/win-library/4.1’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘RGtk2’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

I checked folder 'C:/Users/alvar/OneDrive/Documents/R/win-library/4.1' but I do not see anything called RGtk2 or similar.

The R version I am using is:

R.version

               _                           
platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          4                           
minor          1.2                         
year           2021                        
month          11                          
day            01                          
svn rev        81115                       
language       R                           
version.string R version 4.1.2 (2021-11-01)
nickname       Bird Hippie 

What could the problem be?

@BroVic
Copy link

BroVic commented Jan 4, 2022

@alvaroiramirez
RGtk2 now stands archived on CRAN and thus install.packages() won't work. If you want to install the package, you can use remotes::install_version().

@evabea
Copy link

evabea commented Jan 10, 2022

I'm about to throw in the towel. I've gone through this page several times and followed the workaround exactly as written.

I have macOS Monterey and RStudio version 4.1.2
I installed MacPorts / XQuartz / package dependencies.

On the last step this is what I'm seeing:

library(RGtk2)
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RGtk2/libs/RGtk2.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RGtk2/libs/RGtk2.so, 0x0006): symbol not found in flat namespace '_cairo_destroy'

@BroVic
Copy link

BroVic commented Jan 11, 2022

@evabea
Don't give up, cos you're almost there. I'm not very familiar with Mac OS, so I will find it difficult to help remotely. But here's what you have to do, in principle: Get the GTK distribution so that you can build the RGtk2 dynamic library (the missing object that is causing your error i.e. RGtk2 so). I've written a function that automatically does this on Windows, so it's possible. See this thread .

I don't think this workaround will work without some modifications around the fact that RGtk2 binaries are not currently available on CRAN and have to be built by the user.

@evabea
Copy link

evabea commented Jan 11, 2022

Thanks @BroVic - I saw most of the solutions on that thread were regards to Windows in lieu of Mac.
I get into a never-ending loop to install GTK+ with no end in sight. My XQuartz then freezes.

Here is a screenshot.
image

Again, I do not know what else to do, other than to delete everything.

I require this package for my course so not really sure if there are any other options that don't include the RGtk2 package.

@BroVic
Copy link

BroVic commented Jan 11, 2022

Hi, please generate the error, run sessionInfo() and paste the output.

Ordinarily, when you get to this stage, Gtk+ would be downloaded and installed automatically. So if it doesn't work, it means the RGtk2 itself was not properly built and/or installed (as I explained earlier). You can examine that folder shown in the error message; if you don't see a file called RGtk2.so, then that is likely the problem.

@evabea
Copy link

evabea commented Jan 11, 2022

Hello, I am prompted to install GTK+ and I follow all instructions. It does appear to be successful, however, whenever I run the library I get this verbiage to install again and again.

As per your request, here are my sessionInfo stats:
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base

other attached packages:
[1] rattle_5.4.0 bitops_1.0-7 tibble_3.1.6 RGtk2_2.20.36

loaded via a namespace (and not attached):
[1] fansi_1.0.0 utf8_1.2.2 crayon_1.4.2 lifecycle_1.0.1
[5] magrittr_2.0.1 pillar_1.6.4 rlang_0.4.12 stringi_1.7.6
[9] vctrs_0.3.8 ellipsis_0.3.2 tools_4.1.2 compiler_4.1.2
[13] pkgconfig_2.0.3 tcltk_4.1.2

Also that .so file is present:
image

@BroVic
Copy link

BroVic commented Jan 11, 2022

Okay I presume you're trying to use rattle, which requires RGtk2. Unfortunately I can't reproduce the problem and walk you through (don't have a Mac). I also don't know when you installed RGtk2 as the versions have to match. The simplest hack I can suggest is to try manually installing GTK+ and make sure it's on your System PATH. Use this link: http://r.research.att.com/libs/GTK_2.24.17-X11.pkg​.

Source: https://github.com/lawremi/RGtk2/blob/master/RGtk2/R/zzz.R

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