convert: Convert units

convert,character-methodR Documentation

Convert units

Description

Convert units

Add units to convert function

Usage

## S4 method for signature 'character'
convert(from, to, x = 1, database = "base", ...)

## S4 method for signature 'numeric'
convert(x = 1, from, to, database = "base", ...)

## S4 method for signature 'character,character,numeric'
add_to_convert(
  type,
  unit,
  coef,
  alias = "",
  SI_prefixes = FALSE,
  database = "base",
  update = TRUE
)

Arguments

from

character of length one with unit name

to

character of length one with unit name

x

numeric vector with data to convert

database

character name of a database with units (base by default, other options are not implemented yet).

...

currently ignored

type

character, type of the unit (one of "Energy", "Power", "Mass", "Time", "Length", "Area", "Pressure", "Density", "Volume", "Flow Rates", "Currency").

unit

character, the name of the new unit to add to the database.

coef

numeric, convert factor to the base unit of this type (see the first column of convert_data[[database]][[type]]).

alias

character vector, alternative name(s) for the same unit.

SI_prefixes

logical, can be used with SI prefixes, FALSE by default.

Value

numeric vector with converted values

updated convert_data in the .GlobalEnv, the values will not update the package data.

Examples

convert("MWh", "kWh")
convert("kWh", "MJ")
convert("kWh/kg", "MJ/t", 1e-3)
convert("cents/kWh", "USD/MWh")
convert(1000, "kWh", "MWh")
convert("kWh", "MJ")
convert(1, "kWh/kg", "MJ/t")
convert(5, "cents/kWh", "USD/MWh")
## Not run:
convert_data$base$Currency
add_to_convert("Currency", unit = "JPY", coef = 140)
convert_data$base$Currency
## End(Not run)

olugovoy/energyRt documentation built on Nov. 21, 2024, 2:24 a.m.