verify_units: Assert that a unitted object has the expected units

Description Usage Arguments Value

Description

Throws an error (or calls a user-specified function) if the units are not as expected. If the first element of return.values is x, verify_units(x) returns x when units are as expected, and the function may therefore be chained with other commands.

Usage

1
2
verify_units(x, expected.units, return.values = list(x, NULL),
  violation.handler = stop, nounits.handler = warning)

Arguments

x

character. The object to test for whether it has the expected units.

expected.units

character. The expected units as a character [vector].

return.values

list(2). The values to return if units are (1) as expected, or (2) not as expected. Good options are list(x,NULL) and list(TRUE, FALSE). Elements beyond position 2 are ignored.

violation.handler

closure. The function to call if the expectation is violated. Good options are stop, warning, message, and function(msg) .

nounits.handler

closure. The function to call if x or its elements have no units. Good options are stop, warning, message, and function(msg) .

Value

If units are as expected, returns return.values[[1]] (by default, x). Otherwise stops on an error (if violation.handler=stop) or returns return.values[[2]].


appling/unitted documentation built on May 10, 2019, 12:44 p.m.