@@ -29,8 +29,7 @@ This vignette is identical to @rj, except for two changes:
29
29
## Abstract
30
30
We briefly review SI units, and discuss R packages that deal
31
31
with measurement units, their compatibility and conversion.
32
- Built upon [ udunits2] ( https://cran.r-project.org/package=udunits2 )
33
- and the UNIDATA udunits library, we introduce the package
32
+ Built upon the UNIDATA udunits library, we introduce the package
34
33
[ units] ( https://cran.r-project.org/package=units ) that provides a
35
34
class for maintaining unit metadata. When used in expression, it
36
35
automatically converts units, and simplifies units of results when
@@ -180,7 +179,7 @@ NISTwattPerSqrMeterTOwattPerSqrInch(1:5)
180
179
Both [ measurements] ( https://cran.r-project.org/package=measurements ) and [ NISTunits] ( https://cran.r-project.org/package=NISTunits ) are written entirely
181
180
in R.
182
181
183
- ## UNIDATA's udunits library and the ` udunits2 ` R package
182
+ ## UNIDATA's udunits library
184
183
185
184
Udunits, developed by UCAR/UNIDATA, advertises itself on [ its web
186
185
page] ( https://www.unidata.ucar.edu/software/udunits/ )
@@ -190,50 +189,16 @@ of units and for conversion of numeric values between compatible
190
189
units. The package contains an extensive unit database, which is
191
190
in XML format and user-extendable._ "
192
191
193
- The R package [ udunits2] ( https://cran.r-project.org/package=udunits2 )
194
- [ @udunits2 ] provides a low-level R interface to the most important
195
- functions in the udunits2 C library.
196
-
197
- The functions provided by [ udunits2] ( https://cran.r-project.org/package=udunits2 ) are
198
- ``` {r, eval=requireNamespace("udunits2", quietly=TRUE)}
199
- library(udunits2)
200
- ls(2)
201
- ```
202
- Dropping the ` ud ` prefix,
203
- ` is.parseable ` verifies whether a unit is parseable
204
- ``` {r, eval=requireNamespace("udunits2", quietly=TRUE)}
205
- ud.is.parseable("m/s")
206
- ud.is.parseable("q")
207
- ```
208
- ` are.convertible ` specifies whether two units are convertible
209
- ``` {r, eval=requireNamespace("udunits2", quietly=TRUE)}
210
- ud.are.convertible("m/s", "km/h")
211
- ud.are.convertible("m/s", "s")
212
- ```
213
- ` convert ` converts units that are convertible, and throws an error otherwise
214
- ``` {r, eval=requireNamespace("udunits2", quietly=TRUE)}
215
- ud.convert(1:3, "m/s", "km/h")
216
- ```
217
- and ` get.name ` , ` get.symbol ` and ` set.encoding ` get name, get symbol
218
- or modify encoding of the character unit arguments.
219
- ``` {r, eval=requireNamespace("udunits2", quietly=TRUE)}
220
- ud.get.name("kg")
221
- ud.get.symbol("kilogram")
222
- ud.set.encoding("utf8")
223
- ```
224
-
225
192
Unlike the
226
193
[ measurements] ( https://cran.r-project.org/package=measurements )
227
194
and [ NISTunits] ( https://cran.r-project.org/package=NISTunits ) ,
228
- [ udunits2] ( https://cran.r-project.org/package=udunits2 ) parses
195
+ the underlying udunits2 C library parses
229
196
units as expressions, and bases its logic upon the convertibility
230
197
of expressions, rather than the comparison of fixed strings:
231
- ``` {r, eval=requireNamespace("udunits2", quietly=TRUE) }
198
+ ``` {r}
232
199
m100_a = paste(rep("m", 100), collapse = "*")
233
200
dm100_b = "dm^100"
234
- ud.is.parseable(m100_a)
235
- ud.is.parseable(dm100_b)
236
- ud.are.convertible(m100_a, dm100_b)
201
+ units::ud_are_convertible(m100_a, dm100_b)
237
202
```
238
203
This has the advantage that through complex computations,
239
204
intermediate objects can have units that are arbitrarily complex,
@@ -425,8 +390,7 @@ two set the class attribute of a vector or matrix.
425
390
426
391
Despite all standardization efforts, units may still be ambiguous,
427
392
or subject to interpretation. For instance for the duration of one
428
- year [ NISTunits] ( https://cran.r-project.org/package=NISTunits )
429
- or [ udunits2] ( https://cran.r-project.org/package=udunits2 ) give
393
+ year [ NISTunits] ( https://cran.r-project.org/package=NISTunits ) gives
430
394
us an answer that depends on whether we want a common, leap,
431
395
Gregorian, Julian, tropical or siderial year (@lang , see
432
396
also ` demo(year) ` ). This illustrates that those who apply
0 commit comments