Error ".onLoad failed in loadNamespace() for 'tcltk'"
Asked Answered
A

7

16

I have a general question about how to effectively load any kind of external package into R. I have found that many sources detailing this information are simply insufficient, but I will leave out mentioning those respective URLs. I have successfully loaded external packages into R before, but I am having difficulties loading the fgui package.

In my specific case, I cannot load the library fgui into R Studio. First I download directly from CRAN with the command:

install.packages("fgui", lib="~/Documents/R_dir")

This works fine for me. My working directory is set to ~/Documents/R_dir

The next command I use is:

library("fgui", lib.loc="~/Documents/R_dir")

The error I get is:

Error : .onLoad failed in loadNamespace() for 'tcltk', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so, 10): Library not loaded: /opt/X11/lib/libX11.6.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so
Reason: image not found
Error: package or namespace load failed for ‘fgui’

I have examined the thread "Error when trying to load library(ggplot2) in R" but it did not answer my question.

Please help me with any suggestions to get the package fgui to work properly in R Studio and feel free to address the more general issue of effectively loading external packages into R.

Ancillary answered 8/8, 2014 at 21:54 Comment(9)
The error message is telling you that it couldn't load the tcltk package. Have you installed it? Can you load it?Bingaman
Isn't manipulate the recommenend gui package for RStudio?Generalissimo
@Bingaman I just tried inserting install.packages("tcltk2", lib="~/Documents/R_dir") before running the other commands, still same error. Also, install.packages("tcltk", lib="~/Documents/R_dir") Warning in install.packages : package ‘tcltk’ is not available (for R version 3.1.1)Ancillary
@KarstenW. Generally speaking, if I wanted to create a GUI for my R code in something else besides R, let's say for instance I wanted to create a GUI in wxpython, would this be possible?Ancillary
Have you noticed that that package hasn't been updated in nearly two years, the website for it doesn't appear to exist, and it claims to import a package (tcltk) that has been removed from CRAN and replaced (I presume) with tcltk2? Those all might be pretty good warning signs.Bingaman
@Bingaman cran.r-project.org/web/packages/fgui/index.html and cran.r-project.org/web/packages/fgui/fgui.pdf (update: July 2, 2014)Ancillary
So we're back to not being able to install tcltk. The error message is pretty clear. And tcltk isn't on CRAN anymore. Doesn't that seem troubling?Bingaman
...what I'm trying to lead you towards is just to start Googling tcltk capabilities in R, getting, for instance, this.Bingaman
@thomas could you help me understand how a question that was asked (and aswered) in 2013 is the duplicate of one that was asked in 2014?!?!?!Pollster
B
20

tcltk is not a typical package. It's probably already installed on your system and it cannot be installed using the usual install.packages procedure because it is not on CRAN (just like the base packages that come with R, like stats, etc.). Also, tcltk2 is not the same as tcltk; that is a package that expands upon (and depends on) the functionality of tcltk.

So, start with this:

> capabilities("tcltk")
tcltk 
 TRUE

If that comes back FALSE it means that your R was not built with tcltk support. You don't say what OS you're using, so it's a little bit difficult to help you.

That said, if you're on Linux, you need to rebuild R with tcltk support. This should be relatively straightforward. Basically, make sure Tcl and tk are available on your system in a standard location (something like sudo apt-get install tcl8.5-dev tk8.5-dev) and then rebuild R per usual procedures.

If you're on Mac OS, you're encountering the same error that John Fox describes here in relation to Rcmdr. In short, it's probably one of two things:

  1. A file permission issue related to the directory where you have Tcl installed. To quote Fox: "You can verify the source of this problem by issuing the following command at the R command prompt:

    system("ls -ld /usr/local /usr/local/lib /usr/local/lib/libtcl*")
    # ls: /usr/local/lib: Permission denied
    # ls: /usr/local/lib/libtcl*: Permission denied
    # drwx------  8 root  wheel  272 Sep 24 10:21 /usr/local
    

If the output of the system command looks like the above, you should go to Terminal and do the following: sudo chmod -R a+rX /usr/local and enter your password to change directory permissions.

  1. You have an out-dated version of X-Windows. Try running Mac OS Software Update.

It may also be solvable by creating a symbolic link as described in this answer.

This should never come up on Windows, unless you built R from source without tcl/tk support.

Backup answered 9/8, 2014 at 14:15 Comment(3)
The above capabilities command works fine for me. I am using MacOSX and looked at the link above. Indeed the tcltk error I get is very similar to the one posted at the bottom of that link. However, running system("ls -ld /usr/local /usr/local/lib /usr/local/lib/libtcl*") returns no file permissions errors for me, and performing sudo chmod -R a+rX /usr/local to double check and rerunning everything over again doesn't fix the issue. Typing library(tcltk) returns an error for me regardless, Error: package or namespace load failed for ‘tcltk’Ancillary
@Backup I know it's an old post, but... I have the error on windows. With R installed by anaconda navigator (dependencie of rpy2)Pompano
And i solved it using this trick: https://mcmap.net/q/747806/-tcltk-in-portable-rPompano
C
8

The official installation instructions for R say:

Note: the use of X11 (including tcltk) requires XQuartz to be installed since it is no longer part of OS X. Always re-install XQuartz when upgrading your OS X to a new major version.

So: Simply (re)install XQuartz if you want to use the tcltk package in R.

Chyle answered 15/1, 2016 at 23:51 Comment(0)
C
8

On Arch Linux, tk is a separate package from tcl and both need to be installed:

sudo pacman -S tcl tk

This is given that the output from capabilities("tcltk") with R is TRUE (which means your R is compiled with tcltk support as noted previously in the answers here, this should be the case if you installed it from the arch repos).

Cullie answered 4/8, 2019 at 17:47 Comment(0)
C
5
  1. delete the X11 file on location : /opt
  2. delete the X11 on application unitiltiy
  3. reinstall X11 again

Problem solved...

Calie answered 7/1, 2015 at 12:14 Comment(0)
L
1

For Mac-OS users:

I struggled with this problem recently and found that R-3.1.2 has a bug, which assumes that otool is installed when it is not.

R-3.0.0 (and later) ships with Tck/Tk 8.6.0, so you shouldn't need to install that.

Simply upgrading to a more recent version of R (3.4.2) fixed the problem for me.

Lorikeet answered 19/10, 2017 at 12:34 Comment(0)
B
1

I had the same issue and went down a rabbit hole before discovering a simple fix. If you install R from bianry it will include tcltk by default. Just run the installer with the default installation. You can get the .dmg here: https://cran.r-project.org/bin/macosx/

Bagging answered 29/11, 2018 at 0:20 Comment(0)
A
0

Easiest answer for Mac users:

1- Install tcl-tk using brew:

brew install tcl-tk

2- Run the following code:

ln -s /usr/local/Cellar/tcl-tk/$version/lib/libtcl8.6.dylib /usr/local/lib/libtcl8.6.dylib
ln -s /usr/local/Cellar/tcl-tk/$version/lib/libtk8.6.dylib /usr/local/lib/libtk8.6.dylib

Problem solved!

Aye answered 9/9, 2022 at 11:54 Comment(1)
Obviously, run the second code in the terminal. Also, do not forget to type in your version in "$version" section. To check the version, go to the following directory: /usr/local/Cellar/tcl-tkAye

© 2022 - 2024 — McMap. All rights reserved.