Skip to content

Commit

Permalink
version 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewabirk authored and cran-robot committed Jul 14, 2016
1 parent f5325de commit a0f1567
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 26 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: birk
Type: Package
Title: MA Birk's Functions
Version: 2.1.0
Date: 2016-03-04
Version: 2.1.1
Date: 2016-07-13
Author: Matthew A. Birk
Maintainer: Matthew A. Birk <matthewabirk@gmail.com>
Description: Collection of tools to make R more convenient. Includes tools to
Expand All @@ -13,6 +13,6 @@ License: GPL-3
Encoding: UTF-8
RoxygenNote: 5.0.1
NeedsCompilation: no
Packaged: 2016-03-04 23:47:54 UTC; matthewbirk
Packaged: 2016-07-14 03:08:58 UTC; matthewbirk
Repository: CRAN
Date/Publication: 2016-03-05 09:20:41
Date/Publication: 2016-07-14 07:18:51
10 changes: 5 additions & 5 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
2842b4f352b972dce3a75d64760674d8 *DESCRIPTION
660b5c9a2ab04b942c81e342ade1f10a *DESCRIPTION
c9ef2e0d0bee6ebb31c6fcf4c64a86c5 *NAMESPACE
c664083bf0292af110791e0c364b9b29 *NEWS
34e2667aa9195f0ae06fbc2784b71000 *R/birk.R
c6c9863730128aebfb61bf3401c13bb5 *NEWS
c18a5e0c60f9416a1f9dbfd8604eb457 *R/birk.R
db58e6c07968995c3eccbade670406cd *R/conv_dim.R
507610047ca2292f8223dc71b10c8d28 *R/conv_unit.R
10f3d63d6f63d8ba9b74af5f2db3bfee *R/conv_unit.R
be26cf1afd16b4917aafb8cf50e9d2f7 *R/geom_mean.R
321fd9f823b99b48b2607ff38ccad74f *R/range_seq.R
7e685855005667b99ac5d85fc01774e6 *R/se.R
19f111854e073dda4592b18fc05e6f3b *R/summ_stat.R
006e0a4b5a567ee516845a16ca4f2d62 *R/which.closest.R
c2d793b822a723bae8e8df1192a26a4c *man/birk.Rd
abdea43caa5771cb1148bd889899610e *man/birk.Rd
e49847a5ab3651e0c33c20fed2c619db *man/conv_dim.Rd
500e18e87339270eb83f5a86d8125b6b *man/conv_unit.Rd
b50b5d286baaa5edd9db82a04e095a05 *man/conv_unit_options.Rd
Expand Down
6 changes: 5 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
-------------------------------------------------
version 2.1.1, 2016-07-13
- conv_unit(): fixed a bug where negative coordinate values were not properly converted
- conv_unit(): fixed a bug where NA values were returned as strings containing "NA"s rather than returning NA when converting coordinate units
-------------------------------------------------
version 2.1.0, 2016-03-04
- conv_unit(): added dimension: count
- conv_unit(): added unit options: Ma (duration), point (length), carat (mass)
-------------------------------------------------
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(): MAJOR UPDATE: 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
Expand Down
2 changes: 1 addition & 1 deletion R/birk.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' MA Birk's Functions
#'
#' Collection of tools to make R more convenient. Includes tools to convert between units and dimensions of measurement and to summarize data using statistics not available with base R.
#' 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
33 changes: 19 additions & 14 deletions R/conv_unit.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Created by Matthew A. Birk
# Converts common units for a variety of dimensions
# Last updated: Feb 2016
# Last updated: Jul 2016

.conversions=data.frame(dim = character(0), unit = character(0), std = numeric(0))
.conversions = data.frame(dim = character(0), unit = character(0), std = numeric(0))
.conversions = rbind(.conversions,

data.frame(dim = 'acceleration', unit = 'mm_per_sec2', std = 100),
Expand Down Expand Up @@ -194,7 +194,7 @@
data.frame(dim = 'volume', unit = 'imp_gal', std = 1/4.54609)
)

conv_unit_options = lapply(split(.conversions$unit, .conversions$dim, drop = T), as.character)
conv_unit_options = lapply(split(.conversions$unit, .conversions$dim, drop = TRUE), as.character)


#' Convert Units of Measurement
Expand Down Expand Up @@ -251,9 +251,9 @@ conv_unit_options = lapply(split(.conversions$unit, .conversions$dim, drop = T),
#' @encoding UTF-8
#' @export

conv_unit=function(x,from,to)
conv_unit = function(x, from, to)
{
unit=std=NULL
unit = std = NULL
if(nrow(subset(.conversions,unit==from,dim))==0) stop('the \'from\' argument is not an acceptable unit.')
if(nrow(subset(.conversions,unit==to,dim))==0) stop('the \'to\' argument is not an acceptable unit.')
if(subset(.conversions,unit==from,dim)!=subset(.conversions,unit==to,dim)) stop('these units cannot be converted because they are of different dimensions. Try using conv_dim().')
Expand All @@ -274,15 +274,20 @@ conv_unit=function(x,from,to)
prop=(x-get(paste('frz',from,sep='')))/get(paste('range',from,sep=''))
return(prop*get(paste('range',to,sep=''))+get(paste('frz',to,sep='')))
}
if((from=='dec_deg' | from=='deg_dec_min' | from=='deg_min_sec') & (to=='dec_deg' | to=='deg_dec_min' | to=='deg_min_sec'))
if(from %in% c('dec_deg', 'deg_dec_min', 'deg_min_sec') & to %in% c('dec_deg', 'deg_dec_min', 'deg_min_sec'))
{
if(from=='dec_deg') secs=as.numeric(x)*3600
if(from=='deg_dec_min') secs=lapply(split(as.numeric(unlist(strsplit(x,' ')))*c(3600,60),f=rep(1:length(x),each=2)),sum)
if(from=='deg_min_sec') secs=lapply(split(as.numeric(unlist(strsplit(x,' ')))*c(3600,60,1),f=rep(1:length(x),each=3)),sum)
if(to=='dec_deg') return(as.character(lapply(secs,function(y) y/3600)))
if(to=='deg_dec_min') return(paste(lapply(secs,function(y) y%/%3600),lapply(secs,function(y) y%%3600/60)))
if(to=='deg_min_sec') return(paste(lapply(secs,function(y) y%/%3600),lapply(secs,function(y) y%%3600%/%60),lapply(secs,function(y) y%%3600%%60)))
neg = grepl('-', x)
x = gsub('-', '', x)
if(from == 'dec_deg') secs = as.numeric(x) * 3600
if(from == 'deg_dec_min') secs = lapply(split(as.numeric(unlist(strsplit(x, ' '))) * c(3600, 60), f = rep(1:length(x), each = 2)), sum)
if(from == 'deg_min_sec') secs = lapply(split(as.numeric(unlist(strsplit(x ,' '))) * c(3600, 60, 1), f = rep(1:length(x), each = 3)), sum)
if(to == 'dec_deg') inter = as.character(lapply(secs, function(y) y / 3600))
if(to == 'deg_dec_min') inter = paste(lapply(secs, function(y) y %/% 3600), lapply(secs, function(y) y %% 3600 / 60))
if(to == 'deg_min_sec') inter = paste(lapply(secs, function(y) y %/% 3600), lapply(secs, function(y) y %% 3600 %/% 60), lapply(secs, function(y) y %% 3600 %% 60))
inter = paste0(ifelse(neg, '-', ''), inter)
inter[grepl('NA', inter)] = NA
return(inter)
}
value=x/subset(.conversions,unit==from,std,drop=T)
return(value*subset(.conversions,unit==to,std,drop=T))
value = x / subset(.conversions, unit == from, std, drop = TRUE)
return(value * subset(.conversions, unit == to, std, drop = TRUE))
}
2 changes: 1 addition & 1 deletion man/birk.Rd

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

0 comments on commit a0f1567

Please sign in to comment.