Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: units
Version: 1.0-1.2
Version: 1.0-1.3
Title: Measurement Units for R Vectors
Authors@R: c(person("Edzer", "Pebesma", role = c("aut", "cre"), email = "edzer.pebesma@uni-muenster.de", comment = c(ORCID = "0000-0001-8049-7069")),
person("Thomas", "Mailund", role = "aut", email = "mailund@birc.au.dk"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Add `[<-.mixed_units` method; #432

* Several fixes in documentation files; #433 @tszberkowitz

# version 1.0-1

* Add internal workaround for udunits2 bug with parsing of units that contain
Expand Down
10 changes: 5 additions & 5 deletions R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' \code{make_units(m/s)} is equivalent to \code{as_units(quote(m/s))}.
#' \item \code{set_units}, a pipe-friendly version of \code{`units<-`}. By
#' default it operates with bare expressions, but this
#' behavior can be disabled by a specifying \code{mode = "standard"} or setting
#' behavior can be disabled by specifying \code{mode = "standard"} or setting
#' \code{units_options(set_units_mode = "standard")}.
#' If \code{value} is missing or set to \code{1}, the object becomes unitless.
#' }
Expand All @@ -25,7 +25,7 @@
#'
#' @details
#' If \code{value} is of class \code{units} and has a value unequal to 1, this
#' value is ignored unless \code{units_options("simplifiy")} is \code{TRUE}. If
#' value is ignored unless \code{units_options("simplify")} is \code{TRUE}. If
#' \code{simplify} is \code{TRUE}, \code{x} is multiplied by this value.
#'
#' @export
Expand Down Expand Up @@ -207,9 +207,9 @@ as.Date.units = function (x, ...) {

#' @param ... passed on to other methods.
#' @param mode if \code{"symbols"} (the default), then unit is constructed from
#' the expression supplied. Otherwise, if\code{mode = "standard"},
#' standard evaluation is used for the supplied value This argument can be set
#' via a global option \code{units_options(set_units_mode = "standard")}
#' the expression supplied. Otherwise, if \code{mode = "standard"},
#' standard evaluation is used for the supplied value. This argument can be set
#' via a global option \code{units_options(set_units_mode = "standard")}.
#'
#' @name units
#' @export
Expand Down
16 changes: 9 additions & 7 deletions R/make_units.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @export
#'
#' @param bare_expression a bare R expression describing units. Must be valid R
#' syntax (reserved R syntax words like \code{in} must be backticked)
#' syntax (reserved R syntax words like \code{in} must be backticked).
#'
#' @examples
#' # The easiest way to assign units to a numeric vector is like this:
Expand Down Expand Up @@ -155,8 +155,10 @@ as_units.symbolic_units <- function(x, value, ...) {
}

#' @examples
#'
#' # Use difftime object as units
#' s = Sys.time()
#' d = s - (s+1)
#' d = s - (s+1)
#' as_units(d)
#'
#' @name units
Expand Down Expand Up @@ -225,12 +227,12 @@ pc_and <- function(..., sep = "") {
#' @name units
#' @export
#'
#' @param check_is_valid throw an error if all the unit symbols are not either
#' recognized by udunits2, or a custom
#' user defined via \code{install_unit()}. If \code{FALSE}, no check
#' @param check_is_valid throw an error if all the unit symbols are either not
#' recognized by udunits2 or not custom units
#' defined via \code{install_unit()}. If \code{FALSE}, no check
#' for validity is performed.
#'
#' @param force_single_symbol Whether to perform no string parsing and force
#' @param force_single_symbol whether to perform no string parsing and force
#' treatment of the string as a single symbol.
#'
#' @section Character strings:
Expand Down Expand Up @@ -269,7 +271,7 @@ pc_and <- function(..., sep = "") {
#' otherwise encouraged to use \code{R}'s date and time functionality provided
#' by \code{Date} and \code{POSIXt} classes.
#'
#' @note By default, unit names are automatically substituted with unit names
#' @note By default, unit names are automatically substituted with unit symbols
#' (e.g., kilogram --> kg). To turn off this behavior, set
#' \code{units_options(auto_convert_names_to_symbols = FALSE)}
#'
Expand Down
7 changes: 3 additions & 4 deletions R/math.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
#' and \code{lg(...)} respectively instead of \code{ln(...)}.
#'
#' This is particularly important for some units that are typically expressed in
#' a logarithmic scale (i.e., \emph{bels}, or, more commonly, \emph{decibels}),
#' a logarithmic scale (e.g., \emph{bels}, or, more commonly, \emph{decibels}),
#' such as Watts or Volts. For some of these units, the default \pkg{udunits2}
#' database contains aliases: e.g., \code{BW} (bel-Watts) is an alias of
#' \code{lg(re 1 W)}; \code{Bm} (bel-milliWatts) is an alias of
#' \code{lg(re 0.001 W)}; \code{BV} is an alias of \code{lg(re 1 V)} (bel-Volts),
#' and so on and so forth (see the output of \code{valid_udunits()} for further
#' reference).
#' \code{lg(re 0.001 W)}; \code{BV} is an alias of \code{lg(re 1 V)} (bel-Volts).
#' See the output of \code{valid_udunits()} for further reference.
#'
#' Additionally, the \pkg{units} package defines \code{B}, the \emph{bel}, by
#' default (because it is not defined by \pkg{udunits2}) as an alias of
Expand Down
41 changes: 21 additions & 20 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
#'
#' Create axis label with appropriate labels.
#'
#' @param lab length one character; name of the variable to plot
#' @param lab character; name of the variable to plot
#' @param u vector of class \code{units}
#' @param sep length two character vector, defaulting to \code{c("~","~")}, with
#' the white space between unit name and unit symbols, and between subsequent
#' symbols.
#' symbols
#' @param group length two character vector with grouping symbols, e.g.
#' \code{c("(",")")} for parenthesis, or \code{c("","")} for no group symbols
#' @param parse logical; indicates whether a parseable expression should be
#' returned (typically needed for super scripts), or a simple character string
#' without special formatting.
#' returned (typically needed for superscripts), or a simple character string
#' without special formatting
#'
#' @details \link{units_options} can be used to set and change the defaults for
#' \code{sep}, \code{group} and \code{doParse}.
#' @details \code{\link{units_options}} can be used to set and change the
#' defaults for \code{sep}, \code{group} and \code{doParse}.
#'
#' @name plot.units
#' @export
Expand Down Expand Up @@ -51,7 +51,8 @@ make_unit_label = function(lab, u,

#' @description Plot method for \code{units} objects.
#'
#' @param x object of class units, to plot along the x axis, or, if y is missing, along the y axis
#' @param x object of class \code{units}, to plot along the x axis or (if
#' \code{y} is missing), along the y axis
#' @param y object to plot along the y axis, or missing
#' @param xlab character; x axis label
#' @param ylab character; y axis label
Expand All @@ -67,16 +68,16 @@ make_unit_label = function(lab, u,
#' units_options(group = c("(", ")") ) # parenthesis instead of square brackets
#' plot(weight, displacement)
#'
#' units_options(sep = c("~~~", "~"), group = c("", "")) # no brackets; extra space
#' units_options(sep = c("~~~", "~"), group = c("", "")) # extra space; no brackets
#' plot(weight, displacement)
#'
#' units_options(sep = c("~", "~~"), group = c("[", "]"))
#' gallon = as_units("gallon")
#' consumption = mtcars$mpg * make_units(mi/gallon)
#' units(consumption) = make_units(km/l)
#' plot(displacement, consumption) # division in consumption
#' plot(displacement, consumption) # division in consumption
#'
#' units_options(negative_power = TRUE) # division becomes ^-1
#' units_options(negative_power = TRUE) # division becomes ^-1
#' plot(displacement, consumption)
#'
#' plot(1/displacement, 1/consumption)
Expand Down Expand Up @@ -104,13 +105,13 @@ plot.units <- function(x, y, xlab = NULL, ylab = NULL, ...) {
NextMethod("plot", xlab=xlab, ylab=ylab)
}

#' histogram for unit objects
#' Histogram for \code{units} objects
#'
#' histogram for unit objects
#' @param x object of class units, for which we want to plot the histogram
#' Histogram for \code{units} objects
#' @param x object of class \code{units}, for which we want to plot the histogram
#' @param xlab character; x axis label
#' @param main character; title of histogram
#' @param ... parameters passed on to \link{hist.default}
#' @param ... parameters passed on to \code{\link{hist.default}}
#' @export
#' @examples
#' units_options(parse = FALSE) # otherwise we break on the funny symbol!
Expand All @@ -125,13 +126,13 @@ hist.units <- function(x, xlab = NULL, main = paste("Histogram of", xname), ...)
NextMethod("hist", xlab=xlab, main=main)
}

#' boxplot for unit objects
#' Boxplot for \code{units} objects
#'
#' boxplot for unit objects
#' @param x object of class units, for which we want to plot the boxplot
#' @param ... parameters passed on to \link{boxplot.default}
#' @param horizontal logical indicating if the boxplots should be horizontal;
#' default FALSE means vertical boxes.
#' Boxplot for \code{units} objects
#' @param x object of class \code{units}, for which we want to plot the boxplot
#' @param ... parameters passed on to \code{\link{boxplot.default}}
#' @param horizontal logical; whether boxplots should be horizontal;
#' default \code{FALSE} means vertical boxes.
#' @export
#' @examples
#' units_options(parse = FALSE) # otherwise we break on the funny symbol!
Expand Down
8 changes: 4 additions & 4 deletions R/symbolic_units.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ as.character.symbolic_units <- function(x, ...,

# This is just a brute force implementation that takes each element in the
# numerator and tries to find a value in the denominator that can be converted
# to the same unit. It modifies "value" to rescale the nominator to the denominator
# to the same unit. It modifies "value" to rescale the numerator to the denominator
# before removing matching units.

drop_ones = function(u) u[ u != "1" ]
Expand Down Expand Up @@ -153,10 +153,10 @@ as.character.symbolic_units <- function(x, ...,
#' the udunits database (SI units).
#'
#' @param x object of class \code{units}.
#' @param simplify logical; if TRUE (default), the resulting units are simplified.
#' @param keep_fraction logical; if TRUE (default), the result is kept as a fraction.
#' @param simplify logical; if \code{TRUE} (default), the resulting units are simplified.
#' @param keep_fraction logical; if \code{TRUE} (default), the result is kept as a fraction.
#'
#' @return object of class \code{units} with units converted to base units.
#' @return An object of class \code{units} with units converted to base units.
#' @export
#'
#' @examples
Expand Down
28 changes: 14 additions & 14 deletions R/valid_udunits.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ pcc <- function(...) paste0(..., collapse = ", ")
#' Get information about valid units
#'
#' These functions require the \pkg{xml2} package, and return data frames with
#' complete information about pre-defined units from UDUNITS2. Inspect this data
#' frames to determine what inputs are accepted by \code{as_units} (and the
#' other functions it powers: \code{as_units}, \code{set_units} , \code{units<-}).
#' complete information about pre-defined units from UDUNITS2. Inspect these
#' data frames to determine what inputs are accepted by \code{as_units} (and the
#' other functions it powers: \code{as_units}, \code{set_units}, \code{units<-}).
#'
#' Any entry listed under \code{symbol} , \code{symbol_aliases} , \code{
#' name_singular} , \code{name_singular_aliases} , \code{name_plural} , or
#' Any entry listed under \code{symbol}, \code{symbol_aliases},
#' \code{name_singular}, \code{name_singular_aliases}, \code{name_plural} or
#' \code{name_plural_aliases} is valid. Additionally, any entry under
#' \code{symbol} or \code{symbol_aliases} may can also contain a valid prefix,
#' \code{symbol} or \code{symbol_aliases} may also contain a valid prefix,
#' as specified by \code{valid_udunits_prefixes()} .
#'
#' Note, this is primarily intended for interactive use, the exact format of the
#' Note, this is primarily intended for interactive use. The exact format of the
#' returned data frames may change in the future.
#'
#' @param quiet logical, defaults \code{TRUE} to give a message about the location of
#' @param quiet logical; \code{FALSE} (default) prints a message about the location of
#' the udunits database being read.
#'
#' @return a data frame with columns \code{symbol} , \code{symbol_aliases} ,
#' \code{name_singular} , \code{name_singular_aliases} , \code{name_plural} ,
#' or \code{name_plural_aliases} , \code{def} , \code{definition} ,
#' \code{comment} , \code{dimensionless} and \code{source_xml}
#' @return A data frame with columns \code{symbol}, \code{symbol_aliases},
#' \code{name_singular}, \code{name_singular_aliases}, \code{name_plural},
#' \code{name_plural_aliases}, \code{def}, \code{definition},
#' \code{comment}, \code{dimensionless} and \code{source_xml}.
#'
#' @export
#'
Expand Down Expand Up @@ -104,7 +104,7 @@ valid_udunits <- function(quiet = FALSE) {
})

df <- do.call(rbind, c(l, stringsAsFactors=FALSE, make.row.names=FALSE))
class(df) <- c( "tbl_df", "tbl", "data.frame")
class(df) <- c("tbl_df", "tbl", "data.frame")
df
}

Expand Down Expand Up @@ -137,6 +137,6 @@ valid_udunits_prefixes <- function(quiet = FALSE) {

df <- do.call(rbind.data.frame,
c(l, stringsAsFactors = FALSE, make.row.names = FALSE))
class(df) <- c( "tbl_df", "tbl", "data.frame")
class(df) <- c("tbl_df", "tbl", "data.frame")
df
}
7 changes: 3 additions & 4 deletions man/Math.units.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions man/boxplot.units.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/convert_to_base.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/hist.units.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading