Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R package geoR won't install on macOS despite available tcl-tk on the system

I've installed R and RStudio via brew. For a project I need a function from the R library geoR which in turn is dependent on tcl-tk. I installed this as well via brew: brew install tcl-tk. However, trying to install geoR still leads to the error below - which I don't get. Reinstalling R/RStudio didn't help. Nor did re-starting my Mac. Oh, and trying to install geoR from the downloaded binary from CRAN doesn't help either...And lastly, trying to install the tcl-tk package from the R website doesn't solve this either.

I also posted this on the GitHub of brew - but perhaps others visit the realms of StackOverflow.

My brew status

brew config
HOMEBREW_VERSION: 1.5.2
ORIGIN: https://github.com/Homebrew/brew
HEAD: 60a30e966b7cece5bd4823dae3fb981ab85106ea
Last commit: 11 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 8c1c4f86a269cb23d9d92008abf1a37eabb297b6
Core tap last commit: 2 hours ago
HOMEBREW_PREFIX: /usr/local
CPU: quad-core 64-bit skylake
Homebrew Ruby: 2.3.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Clang: 9.0 build 900
Git: 2.16.1 => /usr/local/bin/git
Curl: 7.54.0 => /usr/bin/curl
Perl: /usr/bin/perl
Python: /usr/local/opt/python/libexec/bin/python => /usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Java: 9.0.1
macOS: 10.13.3-x86_64
Xcode: N/A
CLT: 9.2.0.0.1.1510905681
X11: 2.7.11 => /opt/X11

ERROR

* installing *source* package ‘geoR’ ...
** package ‘geoR’ successfully unpacked and MD5 sums checked
** libs
clang -I/usr/local/Cellar/r/3.4.3_1/lib/R/include -DNDEBUG   -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/include   -fPIC  -g -O2  -c geoR.c -o geoR.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/Cellar/r/3.4.3_1/lib/R/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o geoR.so geoR.o -L/usr/local/Cellar/r/3.4.3_1/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation
installing to /usr/local/lib/R/3.4/site-library/geoR/libs
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Warning: S3 methods ‘as.character.tclObj’, ‘as.character.tclVar’, ‘as.double.tclObj’, ‘as.integer.tclObj’, ‘as.logical.tclObj’, ‘as.raw.tclObj’, ‘print.tclObj’, ‘[[.tclArray’, ‘[[<-.tclArray’, ‘$.tclArray’, ‘$<-.tclArray’, ‘names.tclArray’, ‘names<-.tclArray’, ‘length.tclArray’, ‘length<-.tclArray’, ‘tclObj.tclVar’, ‘tclObj<-.tclVar’, ‘tclvalue.default’, ‘tclvalue.tclObj’, ‘tclvalue.tclVar’, ‘tclvalue<-.default’, ‘tclvalue<-.tclVar’, ‘close.tkProgressBar’ were declared in NAMESPACE but not found
Error : .onLoad failed in loadNamespace() for 'tcltk', details:
  call: fun(libname, pkgname)
  error: Tcl/Tk support is not available on this system
ERROR: lazy loading failed for package ‘geoR’
* removing ‘/usr/local/lib/R/3.4/site-library/geoR’
* restoring previous ‘/usr/local/lib/R/3.4/site-library/geoR’

The downloaded source packages are in
    ‘/private/var/folders/kh/0s66cjl5487fg_fhwgxqd2340000gn/T/RtmpooD5vJ/downloaded_packages’
Warning message:
In install.packages("geoR") :
  installation of package ‘geoR’ had non-zero exit status
like image 807
Sander W. van der Laan Avatar asked Feb 04 '18 21:02

Sander W. van der Laan


1 Answers

Well, after a lot of googling, and analyses of what I read, I deduced a solution.

Here I add some background on why I needed a solution and the Step-by-Step procedure I took. Note it certainly is not a final solution/procedure and maybe some steps are redundant - I'll let that to others.

Background

Sometimes data is very skewed and contains a lot of 'zeros' (or very small numbers approaching 'zero'). Before analyses such data need normalisation to meet the assumptions of a statistical test (you can find more on transformation and normalisation here). Usually people log-transform (e.g. natural log, or log2), the disadvantage is that you loose the 'zeros'.

In my case that is an issue, because the measurements made were properly done (no technical issues), so 'zero' really represents 'zero'. In other words: I don't want to loose them. Some years back a colleague of mine pointed me to 'Box-Cox' transformation (you can find more on that here), and this method is available in R via the geoR package.

The thing is: I use brew to install R and many other packages/libraries lacking on macOS, e.g. wget. For reasons I still don't get - but I also realize it's beyond my coding capabilities - brew does not normally install R with the tcl-tk package. And let that be the critical part you need for geoR and by extension the function boxccoxfit to work. After some googling I got some hints that led me to a (on the face of it) permanent solution; the discussion on the brew website were critical.

Step-by-Step

  1. I made sure I have tcl-tk installed via brew.

    • brew install tcl-tk
    • I made sure tcl-tk was in my path: echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.bash_profile.
    • The command wish also confirmed this.
  2. I also made sure I had installed Command Line Tools properly - there were some updates to High Sierra in the last week, and others had reported issues with that, so I feared it might had to re-installed. I didn't have to, but here's how I checked that. The command brew config shows:

    HOMEBREW_VERSION: 1.5.2
    ORIGIN: https://github.com/Homebrew/brew
    HEAD: 60a30e966b7cece5bd4823dae3fb981ab85106ea
    Last commit: 13 days ago
    Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
    Core tap HEAD: 8c1c4f86a269cb23d9d92008abf1a37eabb297b6
    Core tap last commit: 2 days ago
    HOMEBREW_PREFIX: /usr/local
    CPU: quad-core 64-bit skylake
    Homebrew Ruby: 2.3.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
    Clang: 9.0 build 900
    Git: 2.16.1 => /usr/local/bin/git
    Curl: 7.54.0 => /usr/bin/curl
    Perl: /usr/bin/perl
    Python: /usr/local/opt/python/libexec/bin/python => /usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/bin/python2.7
    Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby Java: 9.0.1
    macOS: 10.13.3-x86_64
    Xcode: N/A
    ** CLT: 9.2.0.0.1.1510905681**
    X11: 2.7.11 => /opt/X11

    The bold printed line suggests that Command Line Tools should be installed.

  3. I than double checked if the path was really set, using the command xcode-select -p, which shows:

    /Library/Developer/CommandLineTools


  4. Also gcc is properly set. I checked this using gcc --version, which shows:

    Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
    Apple LLVM version 9.0.0 (clang-900.0.39.2)
    Target: x86_64-apple-darwin17.4.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin


  5. Now that I had confirmed the basics are present, I proceeded by re-installing Xquartz, R and RStudio. To make sure I get the R with tcl-tk I used the R version of @srfore. These are the subsequent commands.

    • brew cask reinstall xquartz, re-install Xquartz. Optional, if already installed.
    • brew reinstall -s sethrfore/homebrew-r-srf/r, installed a edited version of R.
    • brew cask reinstall rstudio, re-install Rstudio. Optional, if already installed.
  6. All seemed well, I double checked with brew doctor.

    Your system is ready to brew.

  7. Of course, for me, this all started with the need to use the function boxcoxfit from the R package geoR which is dependent on tcl-tk. So, now it was showtime and I started R:

    install.packages("geoR")
    Installing package into ‘/usr/local/lib/R/3.4/site-library’
    (as ‘lib’ is unspecified)
    --- Please select a CRAN mirror for use in this session ---
    Secure CRAN mirrors

    To many to show here, so I deleted this part.

    Selection: 1
    trying URL 'https://cloud.r-project.org/src/contrib/geoR_1.7-5.2.tar.gz'
    Content type 'application/x-gzip' length 421612 bytes (411 KB)
    ==================================================
    downloaded 411 KB

    * installing source package ‘geoR’ ...
    ** package ‘geoR’ successfully unpacked and MD5 sums checked
    ** libs
    clang -I/usr/local/Cellar/r/3.4.3_1/lib/R/include -DNDEBUG -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/include -fPIC -g -O2 -c geoR.c -o geoR.o
    clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/Cellar/r/3.4.3_1/lib/R/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o geoR.so geoR.o -L/usr/local/Cellar/r/3.4.3_1/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation
    installing to /usr/local/lib/R/3.4/site-library/geoR/libs
    ** R
    ** data
    *** moving datasets to lazyload DB
    ** inst
    ** preparing package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded
    * DONE (geoR)

    The downloaded source packages are in
    ‘/private/var/folders/kh/0s66cjl5487fg_fhwgxqd2340000gn/T/RtmpHJHtGf/downloaded_packages’


    And loading `geoR` was not an issue:

    library("geoR")
    --------------------------------------------------------------
    Analysis of Geostatistical Data
    For an Introduction to geoR go to http://www.leg.ufpr.br/geoR
    geoR version 1.7-5.2 (built on 2016-05-02) is now loaded
    --------------------------------------------------------------

like image 181
Sander W. van der Laan Avatar answered Oct 06 '22 23:10

Sander W. van der Laan