Skip to content

Commit

Permalink
version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewabirk authored and cran-robot committed Jan 18, 2016
1 parent a7f8662 commit fa11fca
Show file tree
Hide file tree
Showing 22 changed files with 650 additions and 272 deletions.
15 changes: 10 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
Package: birk
Type: Package
Title: MA Birk's Functions
Version: 1.3.0
Date: 2015-01-31
Version: 2.0.0
Date: 2016-01-17
Author: Matthew A. Birk
Maintainer: Matthew A. Birk <matthewabirk@gmail.com>
Description: This is a compilation of functions that I found useful to make. It currently includes a unit of measurement conversion function, a Q10 calculator for temperature dependence of chemical and biological rates, and some miscellaneous wrapper functions to make R code shorter and faster to write.
Description: This is a compilation of functions that I found useful to make.
It currently includes a couple of functions to work with converting units of
measurement, and some miscellaneous wrapper functions to make R code shorter and
faster to write.
Imports: grDevices, stats
License: GPL-3
Encoding: UTF-8
Packaged: 2015-02-01 02:12:11 UTC; matthewbirk
RoxygenNote: 5.0.1
NeedsCompilation: no
Packaged: 2016-01-18 00:04:16 UTC; matthewbirk
Repository: CRAN
Date/Publication: 2015-02-01 09:04:56
Date/Publication: 2016-01-18 07:41:13
34 changes: 19 additions & 15 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
e65b1a3129ac43f1aa7fed62048579b8 *DESCRIPTION
bf6af06f78e7e92d821709253cc20a3e *NAMESPACE
29de0133c11c26a5c3aa43235268a402 *NEWS
a65f5de5ce2529d3c053837985d99dbd *R/Q10calc.R
67aee325beaccc7bef59abd6356ffa69 *R/birk.R
a551d5be1e4507c22a18dc0e963a9180 *R/conv_unit.R
483e12dfb56104842ddf87a6fa46a014 *DESCRIPTION
c9ef2e0d0bee6ebb31c6fcf4c64a86c5 *NAMESPACE
580c7e170d47c1a8832e2ef20d8bb489 *NEWS
c18a5e0c60f9416a1f9dbfd8604eb457 *R/birk.R
db58e6c07968995c3eccbade670406cd *R/conv_dim.R
d92d4b5bd8cea8f0a7f10d9c88ae434d *R/conv_unit.R
be26cf1afd16b4917aafb8cf50e9d2f7 *R/geom_mean.R
f31d4ef0d4c25d04340c6e5039cc339d *R/range_seq.R
d9abffe3c019fdc5e09e40b198c1bf0f *R/se.R
e2a3943a76393f9f68138cb9b5c80443 *man/Q10calc.Rd
534489aa1544580c1edc789c0d5df86c *man/birk.Rd
058ec1c8fbe1352da6e36bfcc069d83b *man/conv_unit.Rd
4738ed4a62813e6315fbd13390ec12b5 *man/conv_unit_options.Rd
9a618b3f940cbc15432e2cd3d680f82b *man/geom_mean.Rd
0f4b1f8a1ff7c9797d34ef803b4c7741 *man/range_seq.Rd
c3550918bf71ed7a4e5ec9c7dd1365b4 *man/se.Rd
321fd9f823b99b48b2607ff38ccad74f *R/range_seq.R
7e685855005667b99ac5d85fc01774e6 *R/se.R
19f111854e073dda4592b18fc05e6f3b *R/summ_stat.R
006e0a4b5a567ee516845a16ca4f2d62 *R/which.closest.R
abdea43caa5771cb1148bd889899610e *man/birk.Rd
e49847a5ab3651e0c33c20fed2c619db *man/conv_dim.Rd
225578f615da4addcc3c4a742c31f2f7 *man/conv_unit.Rd
b50b5d286baaa5edd9db82a04e095a05 *man/conv_unit_options.Rd
1fef6a9d9af61ebb0a9a8b34b6ab3e9d *man/geom_mean.Rd
9ec74a79441360817d28f82bcf72fb40 *man/range_seq.Rd
f36845143a7eae16d1a21cd28bcdd7f7 *man/se.Rd
d8deb1a574773b9e517bf2d6b0e40be7 *man/summ_stat.Rd
b10fc8f0bbb7aa1b046814ff5aa4d3b3 *man/which.closest.Rd
8 changes: 6 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Generated by roxygen2 (4.1.0): do not edit by hand
# Generated by roxygen2: do not edit by hand

export(Q10calc)
export(conv_dim)
export(conv_unit)
export(conv_unit_options)
export(geom_mean)
export(range_seq)
export(se)
export(summ_stat)
export(which.closest)
import(grDevices)
import(stats)
20 changes: 19 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
-------------------------------------------------
version 2.0.0, 2016-01-17
- conv_dim(): new function

- conv_unit(): MAJOR CHANGE: added functionality to accept objects passing character strings for unit parameters (from and to) at the cost of losing ability to use unquoted arguments
- conv_unit(): added unit options: mph_per_sec and kph_per_sec (acceleration), kJ (energy), Sv (flow), fathom and parsec (length), Pg (mass), km_per_day and mi_per_day (speed), km3, mi3, and imp_cup (volume)
- conv_unit(): removed "lb" ("lbs" remains) and the mis-spelled "hectacre" ("hectare" remains)

- Q10calc(): removed function to clarify focus of the package

- summ_stat(): new function

- which.closest(): new function
-------------------------------------------------
version 1.3.0, 2015-01-31
- conv_unit(): added unit options: angstrom and au (length), light and mach (speed), ul (volume)
- conv_unit(): added lbs as a synonym for “lb” (mass)
- conv_unit(): added "lbs" as a synonym for "lb" (mass)
- conv_unit(): increased efficiency and speed of coordinate unit conversions

- Q10calc(): new function

- range_seq(): new function
-------------------------------------------------
version 1.2, 2014-11-07
- conv_unit(): added dimensions: angle, coordinate
- conv_unit(): added unit options: hectare (area), R (temperature), dm3 and dl (volume)

- geom_mean(): new function

- minor modifications to conv_unit help page

-------------------------------------------------
Expand All @@ -19,4 +36,5 @@ version 1.1, 2014-08-29
-------------------------------------------------
version 1.0, 2014-06-25
- conv_unit(): new function

- se(): new function
54 changes: 0 additions & 54 deletions R/Q10calc.R

This file was deleted.

6 changes: 3 additions & 3 deletions R/birk.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' MA Birks Functions
#' MA Birk's Functions
#'
#' This is a compilation of functions that I found useful to make. It currently includes a unit of measurement conversion function, a Q10 calculator for temperature dependence of chemical and biological rates, and some miscellaneous wrapper functions to make R code shorter and faster to write.
#' This is a compilation of functions that I found useful to make. It currently includes a couple of functions to work with converting units of measurement, and some miscellaneous wrapper functions to make R code shorter and faster to write.
#'
#' @author Matthew A. Birk, \email{matthewabirk@@gmail.com}
#' @docType package
Expand Down Expand Up @@ -32,7 +32,7 @@ NULL
#'
#' @examples
#' conv_unit_options
#' conv_unit_options['Pressure']
#' conv_unit_options$pressure
#'
#' @docType data
#' @keywords datasets
Expand Down
105 changes: 105 additions & 0 deletions R/conv_dim.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Created by Matthew A. Birk
# Converts between dimensions given a transition value
# Last updated: Jun 2015

#' Convert Dimensions of Measurement
#'
#' Converts between dimensions of measurement given a transition dimension (the dimension that "bridges" \code{x} and \code{y}, e.g. liters per second, lbs per acre). Note that 2 of the 3 measurements (\code{x}, \code{y}, or \code{trans}) must be defined to calculate the 3rd. See \code{\link{conv_unit_options}} for all options.
#'
#' This function supports all dimensions in \code{conv_unit_options} except for coordinates. The conversion values have been defined based primarily from international weight and measurement authorities (e.g. General Conference on Weights and Measures, International Committee for Weights and Measures, etc.). While much effort was made to make conversions as accurate as possible, you should check the accuracy of conversions to ensure that conversions are precise enough for your applications.
#'
#' @param x a numeric vector giving the measurement value in the first dimension.
#' @param x_unit the unit in which \code{x} was measured.
#' @param trans a numeric vector giving the measurement value in the transition dimension.
#' @param trans_unit the unit in which \code{trans} was measured.
#' @param y a numeric vector giving the measurement value in the second dimension.
#' @param y_unit the unit in which \code{y} was measured.
#'
#' @author Matthew A. Birk, \email{matthewabirk@@gmail.com}
#' @note \describe{
#' \item{Duration}{Years are defined as 365.25 days and months are defined as 1/12 a year.}
#' \item{Energy}{cal is a thermochemical calorie (4.184 J) and Cal is 1000 cal (kcal or 4184 J).}
#' \item{Flow}{All gallon-based units are US gallons.}
#' \item{Mass}{All non-metric units are based on the avoirdupois system.}
#' \item{Power}{hp is mechanical horsepower, or 745.69 W.}
#' \item{Speed}{mach is calculated at sea level at 15 °C.}
#' }
#' @seealso \code{\link{conv_unit_options}}, \code{\link{conv_unit}}
#'
#' @examples
#' # How many minutes does it take to travel 100 meters at 3 feet per second?
#' conv_dim(x = 100, x_unit = "m", trans = 3, trans_unit = "ft_per_sec", y_unit = "min")
#'
#' # How many degrees does the temperature increase with an increase in 4 kPa given 0.8 Celcius
#' # increase per psi?
#' conv_dim(x_unit = "C", trans = 0.8, trans_unit = "C_per_psi", y = 4, y_unit = "kPa")
#'
#' # Find the densities given volume and mass measurements.
#' conv_dim(x = c(60, 80), x_unit = "ft3", trans_unit = "kg_per_l", y = c(6e6, 4e6), y_unit = "g")
#'
#' @encoding UTF-8
#' @export

conv_dim = function(x, x_unit, trans, trans_unit, y, y_unit){

if(trans_unit == 'grav'){
orig_trans_unit = trans_unit
trans_unit = 'm_per_sec2'
trans = conv_unit(trans,orig_trans_unit,trans_unit)
}
if(trans_unit == 'Sv'){
orig_trans_unit = trans_unit
trans_unit = 'l_per_sec'
trans = conv_unit(trans,orig_trans_unit,trans_unit)
}
if(length(grep('_per_sec2', trans_unit)) == 1) trans_unit = gsub('_per_sec2', '.per.sec_per_sec', trans_unit)
if(trans_unit %in% c('uW', 'mW', 'W', 'kW', 'MW', 'GW', 'hp')){
orig_trans_unit = trans_unit
trans_unit = 'erg_per_sec'
trans = conv_unit(trans, orig_trans_unit, trans_unit)
}
if(trans_unit %in% c('kph', 'mph', 'knot', 'mach', 'light')){
orig_trans_unit = trans_unit
trans_unit = 'm_per_sec'
trans = conv_unit(trans, orig_trans_unit, trans_unit)
}

units = unlist(strsplit(trans_unit, split = '_per_'))
units = gsub('.per.', '_per_', units) # for acceleration only
dims = sapply(units, function(i) names(conv_unit_options)[sapply(conv_unit_options, function(j) i %in% j)])
if(any(sapply(dims, length) == 0)) stop('the \'trans_unit\' argument is not an acceptable unit. It must either be listed in conv_unit_options or a combination of units from conv_unit_options separated by \"_per_\"')
x_dim = names(conv_unit_options)[sapply(conv_unit_options, function(j) x_unit %in% j)]
if(length(x_dim) == 0) stop('the \'x_unit\' argument is not an acceptable unit')
y_dim = names(conv_unit_options)[sapply(conv_unit_options, function(j) y_unit %in% j)]
if(length(y_dim) == 0) stop('the \'y_unit\' argument is not an acceptable unit')
if(!missing('x')) x = conv_unit(x, x_unit, names(which(dims == x_dim)))
if(!missing('y')) y = conv_unit(y, y_unit, names(which(dims == y_dim)))

if(missing(y)){
if(which(dims == x_dim) == 1){
y = x/trans
y = conv_unit(y, names(dims[which(dims == y_dim)]), y_unit)
}else{
y = x*trans
y = conv_unit(y, names(dims[which(dims == y_dim)]), y_unit)
}
return(y)
}

if(missing(trans)){
if(all(c(x_dim, y_dim) == dims)) trans = x/y else trans = y/x
if(exists('orig_trans_unit', inherits = F)) trans = conv_unit(trans, trans_unit, orig_trans_unit)
return(trans)
}

if(missing(x)){
if(which(dims == y_dim) == 1){
x = y/trans
x = conv_unit(x, names(dims[which(dims == x_dim)]), x_unit)
}else{
x = y*trans
x = conv_unit(x, names(dims[which(dims == x_dim)]), x_unit)
}
return(x)
}
}

0 comments on commit fa11fca

Please sign in to comment.