diff --git a/R/units.R b/R/units.R index d87ece6..70aaa25 100644 --- a/R/units.R +++ b/R/units.R @@ -17,7 +17,7 @@ #' u(100, "m") > u(1, "km") #' #' @export -u <- function(x, unit) { +u <- function(x, unit = "1") { stopifnot(is.numeric(x)) stopifnot(is.character(unit)) # x must be a pure number @@ -46,9 +46,12 @@ u <- function(x, unit) { #' # from x in units of "meter" #' du(x, "m") #' +#' # drop the unit of a dimensionaless "unit" quantity +#' du(x / x) +#' #' @seealso [units::drop_units()] #' @export -du <- function(x, unit) { +du <- function(x, unit = "1") { stopifnot(inherits(x, "units")) if (has_comp_unit(x, unit)) { diff --git a/man/du.Rd b/man/du.Rd index 9adf445..4244677 100644 --- a/man/du.Rd +++ b/man/du.Rd @@ -4,7 +4,7 @@ \alias{du} \title{Drop physical units from a quantity} \usage{ -du(x, unit) +du(x, unit = "1") } \arguments{ \item{x}{A dimensionful numeric vector (S3 class "units"), e.g. generated with \code{\link[=u]{u()}} or @@ -27,6 +27,9 @@ The dimensionless number is defined by the ratio of \code{x} and one unit \code{ # from x in units of "meter" du(x, "m") + # drop the unit of a dimensionaless "unit" quantity + du(x / x) + } \seealso{ \code{\link[units:drop_units]{units::drop_units()}} diff --git a/man/u.Rd b/man/u.Rd index b986c4b..b8a65ec 100644 --- a/man/u.Rd +++ b/man/u.Rd @@ -4,7 +4,7 @@ \alias{u} \title{Augment a quantity with a physical unit} \usage{ -u(x, unit) +u(x, unit = "1") } \arguments{ \item{x}{A numeric vector to be augmented with a unit.} diff --git a/tests/testthat/test-units.R b/tests/testthat/test-units.R index 28893c6..d997f03 100644 --- a/tests/testthat/test-units.R +++ b/tests/testthat/test-units.R @@ -21,4 +21,6 @@ test_that("du() works", { expect_equal(du(x, "m"), 1000) expect_error(du(x, "Hz")) + + expect_equal(du(x/x), 1) })