Support for measurement units in R vectors, matrices and arrays: automatic propagation, conversion, derivation and simplification of units; raising errors in case of unit incompatibility. Compatible with the POSIXct, Date and difftime classes. Uses the UNIDATA udunits library and unit database for unit compatibility checking and conversion.
Documentation is provided in an R Journal publication. Cite this package as:
The main units vignette derives from this manuscript and is kept up to date with the package development.
measurement units for R vectors: conversion, derivation, simplification and error checking:
library(units) (spd1 = set_units(1:5, m/s)) # Units: m/s #  1 2 3 4 5 (spd2 = set_units(1:5, km/h)) # Units: km/h #  1 2 3 4 5 spd1 + spd2 # automatic conversion # Units: m/s #  1.277778 2.555556 3.833333 5.111111 6.388889 spd1 * spd2 # unit derivation # Units: km*m/h/s #  1 4 9 16 25 spd1 * set_units(10, s) # unit simplification # Units: m #  10 20 30 40 50 spd1 + set_units(10, s) # error checking # cannot convert s into m/s
Install the release version from CRAN:
The installation of the development version from GitHub requires, e.g., the
If the installation fails due to a missing udunits2 system library, either install it e.g. on Ubuntu or Debian by
sudo apt-get install libudunits2-dev
on CentOS7 with
sudo yum install udunits2-devel
or on MacOS with
brew install udunits
or equivalent in your distribution. Alternatively, install it from the sources by downloading
udunits-2.2.20.tar.gz from ftp://ftp.unidata.ucar.edu/pub/udunits/, and executing the following commands in the download directory:
tar zxf udunits-2.2.20.tar.gz cd ./udunits-2.2.20/ ./configure make sudo make install sudo ldconfig
Then, retry the installation of
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.