Skip to content

Instantly share code, notes, and snippets.

@slowkow
Last active December 17, 2021 12:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save slowkow/d233d9a7f1ae1560e6d34ade0cd21eed to your computer and use it in GitHub Desktop.
Save slowkow/d233d9a7f1ae1560e6d34ade0cd21eed to your computer and use it in GitHub Desktop.
Install the 'units' R package on Partners

Summary

I had a difficult time installing the units R package on the Partners ERIS servers.

I hope this post helps you to figure out how to work around the errors.

Instructions

Get the source code for udunits2 from the website: ftp://ftp.unidata.ucar.edu/pub/udunits

Download, compile, and install udunits2:

# Download the library
wget ftp://ftp.unidata.ucar.edu/pub/udunits/udunits-2.2.26.tar.gz

# Decompress the archive
tar xf udunits-2.2.26.tar.gz

# Configure the build for your system
./configure prefix=$HOME/.local

# Use 4 jobs to build quickly
make -j 4

# Install to our prefix
make install

Start a new R session and install the units R package:

install.packages("units", configure.args = '--with-udunits2-lib=/PHShome/ks38/.local/lib')

Here is the error I get:

checking udunits2.h usability... no
checking udunits2.h presence... no
checking for udunits2.h... no
checking udunits2/udunits2.h usability... no
checking udunits2/udunits2.h presence... no
checking for udunits2/udunits2.h... no
checking for ut_read_xml in -ludunits2... yes
configure: error: in `/tmp/Rtmpx7dkME/R.INSTALLd6c32cc182a6/units':
configure: error:
--------------------------------------------------------------------------------
  udunits2.h not found!

  If the udunits2 library is installed in a non-standard location, use:

    --configure-args='--with-udunits2-lib=/usr/local/lib'

  for example, if the library was not found, and/or

    --configure-args='--with-udunits2-include=/usr/include/udunits2'

  if the header was not found, replacing paths with appropriate values for your
  installation. You can alternatively use the UDUNITS2_INCLUDE and UDUNITS2_LIBS
  environment variables.

  If udunits2 is not installed, please install it.
  It is required for this package.
--------------------------------------------------------------------------------

See `config.log' for more details
ERROR: configuration failed for package ‘units’
* removing ‘/PHShome/ks38/.local/lib/R/x86_64-linux-gnu-library/3.4/units’

The downloaded source packages are in
        ‘/tmp/RtmpOYDlSm/downloaded_packages’
Warning message:
In install.packages("units", configure.args = "--with-udunits2-lib=/PHShome/ks38/.local/lib") :
  installation of package ‘units’ had non-zero exit status

@ilyakorsunsky helped me figure this one out.

I had to modify ~/.R/Makevars as follows:

# ~/.R/Makevars
CFLAGS += -I/PHShome/ks38/.local/include -L/PHShome/ks38/.local/lib
CPPFLAGS += -I/PHShome/ks38/.local/include -L/PHShome/ks38/.local/lib

Then I can install the units package:

# Download the units package source code
wget https://cran.r-project.org/src/contrib/Archive/units/units_0.6-0.tar.gz

# Install it
R CMD INSTALL \
  --configure-args='--with-udunits2-lib=/PHShome/ks38/.local/lib --with-udunits2-include=/PHShome/ks38/.local/include' \
  units_0.6-0.tar.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment