Thursday, January 17, 2013

Fix R Tcl/Tk dependency problem on Mac OS X by installing working Tcl/Tk

For some reason, if you just install R on Mac OS X, you don't have a working Tcl/Tk by default. The problem manifests itself like this:


> tkplot(g)
Loading required package: tcltk
Loading Tcl/Tk interface ... 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/2.15/Resources/library/tcltk/libs/x86_64/tcltk.so':
  dlopen(/Library/Frameworks/R.framework/Versions/2.15/Resources/library/tcltk/libs/x86_64/tcltk.so, 10): Library not loaded: /usr/local/lib/libtcl8.5.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/2.15/Resources/library/tcltk/libs/x86_64/tcltk.so
  Reason: image not found
Error in tkplot(g) : tcl/tk library not available

There are other functions that depend on Tcl/Tk as well. It's particularly annoying that you don't see the problem when you install or even load a library, but only when you try to use a function that depends on Tcl/Tk.

Fortunately, there's an easy solution. You need these two things:

  1. X Windows for Mac OS X. You may already have this. If not, install it.
  2. A Tcl/Tk installation that actually works. This will do the trick. Just install!
After you have these two installed, things should work. I didn't even have to restart R.

> tkplot(g)
Loading required package: tcltk
Loading Tcl/Tk interface ... done

9 comments:

Anonymous said...

Thanks so much! Fixed it straight away. Saved me hours of time.

Vladislav Petyuk said...

That fixed my problem with "qvalue" package.
Thanks!

Bryan Yang said...

Thank you it's work for me!

Anonymous said...

I have follow your instructions...but it didn't work for me. I recently updated R. Do you think that can be related? I was able to use packages that now I can't. Any suggestions?

Aaron said...

Hi Anonymous! I don't know what your problem is!

Veronica said...

Sorry I did not explain myself better. I have the following error from R when I try to use one package from R.
Error : .onLoad failed in loadNamespace() for 'tcltk', details:
call: system2("otool", c("-L", shQuote(DLL)), stdout = TRUE)
error: error in running command
Error: package or namespace load failed for ‘vegan’
sh: otool: command not found

I was able to use this package before I updated to the newest R version. I downloaded what you suggested in your post, but it is still giving me this error.
Cheers!!

Unknown said...

I have the same problem Veronica. I am trying to use geoR package The error is
sh: otool: command not found
Error : .onLoad failed in loadNamespace() for 'tcltk', details:
call: system2("otool", c("-L", shQuote(DLL)), stdout = TRUE)
error: error in running command
Error: package or namespace load failed for ‘geoR’

I already downloaded and installed the packages that you suggested, but I still have the same problem. What can I do?

Anonymous said...

I have the same problem as Veronica and Maggy, installation did not resolve it. Weird.

Unknown said...

Thank you!!!