From 97dabd690080246b2761a423f1103c5d435dc0ec Mon Sep 17 00:00:00 2001 From: wilsonfreitas Date: Sun, 15 Jun 2014 22:33:14 -0300 Subject: [PATCH] Changed add to add.bizdays The function `add` has been renamed to `add.bizdays`. --- NAMESPACE | 10 ++++----- R/calendar.R | 44 +++++++++++++++++++------------------- inst/tests/test-calendar.R | 14 ++++++------ man/add.Rd | 38 -------------------------------- man/add.bizdays.Rd | 41 +++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 72 deletions(-) delete mode 100644 man/add.Rd create mode 100644 man/add.bizdays.Rd diff --git a/NAMESPACE b/NAMESPACE index 377191a..b8f2b78 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,7 @@ -S3method(add,Date) -S3method(add,POSIXct) -S3method(add,POSIXlt) -S3method(add,character) +S3method(add.bizdays,Date) +S3method(add.bizdays,POSIXct) +S3method(add.bizdays,POSIXlt) +S3method(add.bizdays,character) S3method(adjust.next,Date) S3method(adjust.next,POSIXct) S3method(adjust.next,POSIXlt) @@ -36,7 +36,7 @@ S3method(is.bizday,POSIXlt) S3method(is.bizday,character) S3method(print,Calendar) export(Calendar) -export(add) +export(add.bizdays) export(adjust.next) export(adjust.previous) export(bizdays) diff --git a/R/calendar.R b/R/calendar.R index 6479b37..aa497d4 100644 --- a/R/calendar.R +++ b/R/calendar.R @@ -382,39 +382,39 @@ bizseq.Date <- function(from, to, cal=bizdays.options$get('default.calendar')) { #' @examples #' data(holidaysANBIMA) #' cal <- Calendar(holidaysANBIMA) -#' add("2013-01-02", 5, cal) +#' add.bizdays("2013-01-02", 5, cal) #' dates <- seq(as.Date("2013-01-01"), as.Date("2013-01-05"), by="day") -#' add(dates, 1, cal) -add <- function(dates, n, cal) UseMethod('add') +#' add.bizdays(dates, 1, cal) +add.bizdays <- function(dates, n, cal) UseMethod('add.bizdays') -#' @rdname add -#' @method add character -#' @S3method add character -add.character <- function(dates, n, cal=bizdays.options$get('default.calendar')) { +#' @rdname add.bizdays +#' @method add.bizdays character +#' @S3method add.bizdays character +add.bizdays.character <- function(dates, n, cal=bizdays.options$get('default.calendar')) { dates <- as.Date(dates) - add(dates, n, cal) + add.bizdays(dates, n, cal) } -#' @rdname add -#' @method add POSIXct -#' @S3method add POSIXct -add.POSIXct <- function(dates, n, cal=bizdays.options$get('default.calendar')) { +#' @rdname add.bizdays +#' @method add.bizdays POSIXct +#' @S3method add.bizdays POSIXct +add.bizdays.POSIXct <- function(dates, n, cal=bizdays.options$get('default.calendar')) { dates <- as.Date(dates) - add(dates, n, cal) + add.bizdays(dates, n, cal) } -#' @rdname add -#' @method add POSIXlt -#' @S3method add POSIXlt -add.POSIXlt <- function(dates, n, cal=bizdays.options$get('default.calendar')) { +#' @rdname add.bizdays +#' @method add.bizdays POSIXlt +#' @S3method add.bizdays POSIXlt +add.bizdays.POSIXlt <- function(dates, n, cal=bizdays.options$get('default.calendar')) { dates <- as.Date(dates) - add(dates, n, cal) + add.bizdays(dates, n, cal) } -#' @rdname add -#' @method add Date -#' @S3method add Date -add.Date <- function(dates, n, cal=bizdays.options$get('default.calendar')) { +#' @rdname add.bizdays +#' @method add.bizdays Date +#' @S3method add.bizdays Date +add.bizdays.Date <- function(dates, n, cal=bizdays.options$get('default.calendar')) { if ( ! any(dates >= cal$start.date & dates <= cal$end.date) ) stop('Given date out of range.') dates <- as.integer(dates) diff --git a/inst/tests/test-calendar.R b/inst/tests/test-calendar.R index 7e90b7e..f1d2d31 100644 --- a/inst/tests/test-calendar.R +++ b/inst/tests/test-calendar.R @@ -138,14 +138,14 @@ test_that("it should generate a sequence of bizdays", { context('offset by a number of business days') test_that("it should offset the date by n business days", { - expect_equal(add('2013-01-02', 1, cal), as.Date('2013-01-03')) - expect_equal(add('2013-01-02', 3, cal), as.Date('2013-01-07')) - expect_equal(add('2013-01-02', 0, cal), as.Date('2013-01-02')) - expect_equal(add('2013-01-01', 0, cal), as.Date('2013-01-02')) - expect_equal(add('2013-01-01', -1, cal), as.Date('2012-12-28'), label=add('2013-01-01', -1, cal)) + expect_equal(add.bizdays('2013-01-02', 1, cal), as.Date('2013-01-03')) + expect_equal(add.bizdays('2013-01-02', 3, cal), as.Date('2013-01-07')) + expect_equal(add.bizdays('2013-01-02', 0, cal), as.Date('2013-01-02')) + expect_equal(add.bizdays('2013-01-01', 0, cal), as.Date('2013-01-02')) + expect_equal(add.bizdays('2013-01-01', -1, cal), as.Date('2012-12-28'), label=add.bizdays('2013-01-01', -1, cal)) dates <- c(as.Date('2013-01-01'), as.Date('2013-01-02')) - expect_equal(add(dates, 1, cal), c(as.Date('2013-01-03'), as.Date('2013-01-03'))) + expect_equal(add.bizdays(dates, 1, cal), c(as.Date('2013-01-03'), as.Date('2013-01-03'))) cal <- Calendar(start.date='2013-01-01', end.date='2013-01-31') - expect_error(add('2013-01-10', 30, cal)) + expect_error(add.bizdays('2013-01-10', 30, cal)) }) diff --git a/man/add.Rd b/man/add.Rd deleted file mode 100644 index 9879443..0000000 --- a/man/add.Rd +++ /dev/null @@ -1,38 +0,0 @@ -\name{add} -\alias{add} -\alias{add.Date} -\alias{add.POSIXct} -\alias{add.POSIXlt} -\alias{add.character} -\title{Adds \code{n} business days to the given \code{dates}.} -\usage{ -add(dates, n, cal) - -\method{add}{character}(dates, n, - cal = bizdays.options$get("default.calendar")) - -\method{add}{POSIXct}(dates, n, cal = bizdays.options$get("default.calendar")) - -\method{add}{POSIXlt}(dates, n, cal = bizdays.options$get("default.calendar")) - -\method{add}{Date}(dates, n, cal = bizdays.options$get("default.calendar")) -} -\arguments{ - \item{dates}{a date or a vector of dates to be offset} - - \item{n}{the amount of business days to add} - - \item{cal}{an instance of Calendar} -} -\description{ -This function returns the given \code{dates} offset by the -given amount of \code{n} business days. -} -\examples{ -data(holidaysANBIMA) -cal <- Calendar(holidaysANBIMA) -add("2013-01-02", 5, cal) -dates <- seq(as.Date("2013-01-01"), as.Date("2013-01-05"), by="day") -add(dates, 1, cal) -} - diff --git a/man/add.bizdays.Rd b/man/add.bizdays.Rd new file mode 100644 index 0000000..f8ce0b6 --- /dev/null +++ b/man/add.bizdays.Rd @@ -0,0 +1,41 @@ +\name{add.bizdays} +\alias{add.bizdays} +\alias{add.bizdays.Date} +\alias{add.bizdays.POSIXct} +\alias{add.bizdays.POSIXlt} +\alias{add.bizdays.character} +\title{Adds \code{n} business days to the given \code{dates}.} +\usage{ +add.bizdays(dates, n, cal) + +\method{add.bizdays}{character}(dates, n, + cal = bizdays.options$get("default.calendar")) + +\method{add.bizdays}{POSIXct}(dates, n, + cal = bizdays.options$get("default.calendar")) + +\method{add.bizdays}{POSIXlt}(dates, n, + cal = bizdays.options$get("default.calendar")) + +\method{add.bizdays}{Date}(dates, n, + cal = bizdays.options$get("default.calendar")) +} +\arguments{ + \item{dates}{a date or a vector of dates to be offset} + + \item{n}{the amount of business days to add} + + \item{cal}{an instance of Calendar} +} +\description{ +This function returns the given \code{dates} offset by the +given amount of \code{n} business days. +} +\examples{ +data(holidaysANBIMA) +cal <- Calendar(holidaysANBIMA) +add.bizdays("2013-01-02", 5, cal) +dates <- seq(as.Date("2013-01-01"), as.Date("2013-01-05"), by="day") +add.bizdays(dates, 1, cal) +} +