https://github.com/r-quantities/units
Measurement units for R
https://github.com/r-quantities/units
Last synced: 9 days ago
JSON representation
Measurement units for R
- Host: GitHub
- URL: https://github.com/r-quantities/units
- Owner: r-quantities
- Created: 2016-06-07T07:39:42.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2025-03-13T09:29:44.000Z (about 1 month ago)
- Last Synced: 2025-04-11T08:40:30.252Z (10 days ago)
- Language: R
- Homepage: https://r-quantities.github.io/units
- Size: 8.06 MB
- Stars: 183
- Watchers: 7
- Forks: 31
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - r-quantities/units - Measurement units for R (R)
README
#
Measurement Units for R
[](https://github.com/r-quantities/units/actions/workflows/build.yml)
[](https://app.codecov.io/github/r-quantities/units?branch=master)
[](http://www.gnu.org/licenses/gpl-2.0.html) [](https://cran.r-project.org/package=units)
[](https://www.r-pkg.org/pkg/units)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
Documentation is provided in an R Journal publication. Cite this package as:
- Edzer Pebesma, Thomas Mailund and James Hiebert (2016). "Measurement Units in R."
_The R Journal_, 8 (2), 486--494.
DOI: [10.32614/RJ-2016-061](https://doi.org/10.32614/RJ-2016-061)The main units
[vignette](https://r-quantities.github.io/units/articles/measurement_units_in_R.html)
derives from this manuscript and is kept up to date with the package development.- Blog posts: [first](https://r-spatial.org/r/2016/06/10/units.html),
[second](https://r-spatial.org/r/2016/08/16/units2.html),
[third](https://r-spatial.org/r/2016/09/29/plot_units.html).
- The UNIDATA [udunits2](https://github.com/Unidata/UDUNITS-2) library at GitHub.### What it does
Package `units` provides
measurement units for R vectors: conversion, derivation, simplification and error checking:```r
library(units)
(spd1 = set_units(1:5, m/s))
# Units: m/s
# [1] 1 2 3 4 5
(spd2 = set_units(1:5, km/h))
# Units: km/h
# [1] 1 2 3 4 5
spd1 + spd2 # automatic conversion
# Units: m/s
# [1] 1.277778 2.555556 3.833333 5.111111 6.388889
spd1 * spd2 # unit derivation
# Units: km*m/h/s
# [1] 1 4 9 16 25
spd1 * set_units(10, s) # unit simplification
# Units: m
# [1] 10 20 30 40 50
spd1 + set_units(10, s) # error checking
# cannot convert s into m/s
```### Installation
Install the release version from CRAN:
```r
install.packages("units")
```The installation of the development version from GitHub requires, e.g., the `remotes` package:
```r
remotes::install_github("r-quantities/units")
```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 Fedora or RHEL/CentOS with
```
sudo dnf install udunits2-devel
```
or on MacOS with
```
brew install udunits
```
or equivalent in your distribution. Alternatively, install it from the sources by downloading the latest version from [UDUNITS downloads](https://downloads.unidata.ucar.edu/udunits/), and executing the following commands in the download directory:```
tar zxf udunits-.tar.gz
cd ./udunits-/
./configure
make
sudo make install
sudo ldconfig
```Then, retry the installation of `units`.