Measurement Units for R Vectors

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.


version 0.5-0

  • deal with trigonometric functions for units degree; return units rad on inverse trigonometric functions.

  • Unit creation has been significantly refactored. units<- now accepts strings or quoted language objects on the right hand side, powered by new S3 methods for as_units. All valid unit symbols and unit names recognized by package 'udunits2' are now accepted. New user facing function make_units() (plural s) is also provided. See ?as_units for details. @t-kalinowski

  • new functions valid_udunits() and valid_udunits_prefixes() generate tidy dataframes listing all the valid unit names, symbols, and prefixes recognized by udunits. @t-kalinowski

  • new function install_symbolic_unit() for adding custom, user-defined units. @t-kalinowski

  • make_unit and parse_unit (singular unit) have been deprecated, please use as_units instead.

  • ud_units is no longer necessary and is soft-deprecated, and may be removed in a future release.

  • add %*% as an S3 generic; #54

  • add %% and %/% to Ops.units

  • support unary + and - ; #56

  • add seq method for units, converting units to those of the first argument

  • Deprecate as.dt for as_difftime, as.units for as_units and as_cf for deparse_unit

version 0.4-6

  • add all.equal method for units; #51

  • add deparse_unit to replace as_cf

  • add calender/time conversions between udunits time units like minutes from 1900-0-0, and R's POSIXct and Date

  • add as_units to replace as.units

  • rename as.dt to as_difftime

version 0.4-5

  • add support for user-defined unit conversion; #31

  • allow for 1/n integer powers, as in set_units(1:10, m^-2) ^ 0.5; #29

  • properly set log units after log transform; #33

  • sin, cos and tan no longer complain when units is rad, and return unitless; #40

  • now allow for set_units(1:3, "°C") and also set_units(1:3, "degree_Celsius") by resolving names to symbols first; #43

  • set_units(x) with x numeric sets units to unitless; #41

version 0.4-4

  • fix a result units bug when multiplying or dividing units vectors of different length, #34

  • add a rep method for units vectors

version 0.4-3

  • support for set_units(1:10, m) which does not require to declare or define, m (m is resolved automatically from ud_units)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.6-0 by Edzer Pebesma, a month ago

Report a bug at

Browse source code at

Authors: Edzer Pebesma [aut, cre] (<>), Thomas Mailund [aut], Tomasz Kalinowski [aut], James Hiebert [ctb], Iñaki Ucar [ctb] (<>)

Documentation:   PDF Manual  

Task views: Chemometrics and Computational Physics

GPL-2 license

Imports Rcpp

Suggests udunits2, NISTunits, measurements, xml2, tibble, pillar, knitr, testthat, ggforce, rmarkdown, magrittr

Linking to Rcpp

System requirements: udunits-2

Imported by EmissV, cdcfluview, ggforce, hydrolinks, iemisc, jpmesh, lwgeom, nngeo, sf, smoothr, tidycensus, tmap, tmaptools, vein, wikilake.

Suggested by RCzechia, constants, opensensmapr.

See at CRAN