From ce3d6bf0b654e16ff61b5a63f0b851e8bf7290ae Mon Sep 17 00:00:00 2001 From: fawda123 Date: Sun, 12 Apr 2015 14:01:00 -0500 Subject: [PATCH] added feature to setstep for chr input with timestep argument --- .Rbuildignore | 3 ++- DESCRIPTION | 4 ++-- R/swmpr_organize.R | 26 ++++++++++++++++++++++++-- README.Rmd | 2 +- README.html | 2 +- README.md | 2 +- Thumbs.db | Bin 48128 -> 48128 bytes man/setstep.Rd | 2 +- 8 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 98461c0..41f15e4 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,4 +10,5 @@ ^\.Rhistory$ ^appveyor\.yml$ ^cran-comments\.md$ -^swmpr_logo.png \ No newline at end of file +^swmpr_logo.png$ +^Thumbs.db$ \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index c86dd21..f307cdc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: SWMPr Type: Package Title: Retrieving, Organizing, and Analyzing Estuary Monitoring Data -Version: 2.0.0 -Date: 2015-4-1 +Version: 2.0.1 +Date: 2015-4-12 Author: Marcus W. Beck [aut, cre] Maintainer: Marcus W. Beck Description: Tools for retrieving, organizing, and analyzing environmental diff --git a/R/swmpr_organize.R b/R/swmpr_organize.R index 5957c17..1baa4a5 100644 --- a/R/swmpr_organize.R +++ b/R/swmpr_organize.R @@ -447,7 +447,7 @@ subset.swmpr <- function(x, subset = NULL, select = NULL, #' Create a continuous time vector at set time step for a swmpr object #' #' @param swmpr_in input swmpr object -#' @param timestep numeric value of time step to use in minutes +#' @param timestep numeric value of time step to use in minutes. Alternatively, a chr string indicating \code{'years'}, \code{'quarters'}, \code{'months'}, \code{'days'}, or \code{'hours'} can also be used. A character input assumes 365 days in a year and 31 days in a month. #' @param differ numeric value defining buffer for merging time stamps to standardized time series #' @param ... arguments passed to or from other methods #' @@ -489,10 +489,32 @@ setstep.swmpr <- function(swmpr_in, timestep = 15, differ= timestep/2, ...){ # swmpr data and attributes dat <- swmpr_in attrs <- attributes(swmpr_in) + + # convert timestep to numeric if chr input + if(is.character(timestep)){ + + # lookup values + chr_stp <- c('years', 'quarters', 'months', 'weeks', 'days', 'hours') + mul_fac <- c(525600, 131400, 44640, 10080, 1440, 60) + + # stop if chr_stp is wrong + if(!timestep %in% chr_stp){ + + stop(paste( + 'Character input for timestep must be one of of the following:', + paste(chr_stp, collapse = ', ') + )) + + } + + # otherwise lookup + timestep <- mul_fac[which(timestep == chr_stp)] + + } # sanity check if(timestep/2 < differ) - stop('Value for differ must be less than one half of timestep') + stop('Value for differ must be less than or equal to one half of timestep') if('Date' %in% attrs$stamp_class) stop('Cannot use setstep with date class') diff --git a/README.Rmd b/README.Rmd index c848ff1..d892e23 100644 --- a/README.Rmd +++ b/README.Rmd @@ -20,7 +20,7 @@ Windows: [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/g The System Wide Monitoring Program ([SWMP](http://nerrs.noaa.gov/RCDefault.aspx?ID=18)) was implemented by the National Estuarine Research Reserve System ([NERRS](http://nerrs.noaa.gov/)) in 1995 to provide continuous monitoring data at over 300 continuous monitoring stations in 28 estuaries across the United States. SWMPr (pronounced "swamper") is an R package for retrieving, organizing, and analyzing estuary monitoring data from SWMP. Please cite the package as follows: -*Beck MW. 2015. SWMPr: An R package for the National Estuarine Research Reserve System. Version 2.0.0. https://github.com/fawda123/SWMPr* +*Beck MW. 2015. SWMPr: An R package for the National Estuarine Research Reserve System. Version 2.0.1. https://github.com/fawda123/SWMPr* #Installing the package diff --git a/README.html b/README.html index f5f73e5..7109879 100644 --- a/README.html +++ b/README.html @@ -72,7 +72,7 @@

Marcus W. Beck, beck.marcus@epa.gov

Overview

The System Wide Monitoring Program (SWMP) was implemented by the National Estuarine Research Reserve System (NERRS) in 1995 to provide continuous monitoring data at over 300 continuous monitoring stations in 28 estuaries across the United States. SWMPr (pronounced “swamper”) is an R package for retrieving, organizing, and analyzing estuary monitoring data from SWMP. Please cite the package as follows:

-

Beck MW. 2015. SWMPr: An R package for the National Estuarine Research Reserve System. Version 2.0.0. https://github.com/fawda123/SWMPr

+

Beck MW. 2015. SWMPr: An R package for the National Estuarine Research Reserve System. Version 2.0.1. https://github.com/fawda123/SWMPr

Installing the package

diff --git a/README.md b/README.md index 5e5591c..65d507b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Windows: [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/g The System Wide Monitoring Program ([SWMP](http://nerrs.noaa.gov/RCDefault.aspx?ID=18)) was implemented by the National Estuarine Research Reserve System ([NERRS](http://nerrs.noaa.gov/)) in 1995 to provide continuous monitoring data at over 300 continuous monitoring stations in 28 estuaries across the United States. SWMPr (pronounced "swamper") is an R package for retrieving, organizing, and analyzing estuary monitoring data from SWMP. Please cite the package as follows: -*Beck MW. 2015. SWMPr: An R package for the National Estuarine Research Reserve System. Version 2.0.0. https://github.com/fawda123/SWMPr* +*Beck MW. 2015. SWMPr: An R package for the National Estuarine Research Reserve System. Version 2.0.1. https://github.com/fawda123/SWMPr* #Installing the package diff --git a/Thumbs.db b/Thumbs.db index 68eb10a2f7a8bab38e0cd7b3aef2cf433ba70ec0..eabdfd353a9df1efc5a422646e387b3ea8842154 100644 GIT binary patch delta 505 zcmXZZ$xZ@65P;$CNrQ+R?nZ)rEsDQ<)}ab*M)J8sSD0n$dz*w84XRc+nw5Qgl-I(1mXFpcj4cqaOnp#1Mutf>8u81_R?T zF@Z@;VH!b%FoRjlA&dy-#f=aP6pL8GGFGsPHAJzF7&fqpEo>u>9qeKc`#8WMj&O_< zoZ<|*bo~BN#iX>n$`cIh8RygOx6Hpkn}rB4gelG$;gZn|>IB&!C+Ow#6=Rv4cf0&T ilf|zqEY_X!*%jAZzgRyiYJIAYH(krf^o9QHc>e?Hl}FzI delta 75 zcmZqp!PM}BX@U*wzyJULGi-D`&bXO{?FZu|79SR%!2ijNtST%ZsmXz?K9ksZCI_%? Zn4G}s0%4YHHsIL9IEhPQvjoSB%>XzhAVvTH diff --git a/man/setstep.Rd b/man/setstep.Rd index 6920fc0..7f03403 100644 --- a/man/setstep.Rd +++ b/man/setstep.Rd @@ -14,7 +14,7 @@ setstep(swmpr_in, ...) \item{...}{arguments passed to or from other methods} -\item{timestep}{numeric value of time step to use in minutes} +\item{timestep}{numeric value of time step to use in minutes. Alternatively, a chr string indicating \code{'years'}, \code{'quarters'}, \code{'months'}, \code{'days'}, or \code{'hours'} can also be used. A character input assumes 365 days in a year and 31 days in a month.} \item{differ}{numeric value defining buffer for merging time stamps to standardized time series} }