[r-cran-isoweek] 01/02: New upstream version 0.6-2

Andreas Tille tille at debian.org
Tue Dec 19 08:40:36 UTC 2017


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository r-cran-isoweek.

commit ef856c6807843662569f0daf71b631c0faf61937
Author: Andreas Tille <tille at debian.org>
Date:   Tue Dec 19 09:36:59 2017 +0100

    New upstream version 0.6-2
---
 DESCRIPTION                        | 21 +++++++++++++++++
 MD5                                | 21 +++++++++++++++++
 NAMESPACE                          |  6 +++++
 NEWS                               | 42 ++++++++++++++++++++++++++++++++++
 R/ISOweek-internal.R               | 39 +++++++++++++++++++++++++++++++
 R/ISOweek.R                        | 39 +++++++++++++++++++++++++++++++
 R/ISOweek2date.R                   | 47 ++++++++++++++++++++++++++++++++++++++
 R/ISOweekday.R                     | 20 ++++++++++++++++
 R/date2ISOweek.R                   | 20 ++++++++++++++++
 inst/tests/test-ISOweek-internal.r | 20 ++++++++++++++++
 inst/tests/test-ISOweek.r          | 42 ++++++++++++++++++++++++++++++++++
 inst/tests/test-ISOweek2date.r     | 44 +++++++++++++++++++++++++++++++++++
 inst/tests/test-ISOweekday.r       | 37 ++++++++++++++++++++++++++++++
 inst/tests/test-date2ISOweek.r     | 42 ++++++++++++++++++++++++++++++++++
 man/ISOweek.Rd                     | 44 +++++++++++++++++++++++++++++++++++
 man/ISOweek2date.Rd                | 39 +++++++++++++++++++++++++++++++
 man/ISOweekday.Rd                  | 31 +++++++++++++++++++++++++
 man/date2ISOweek.Rd                | 38 ++++++++++++++++++++++++++++++
 man/thursday0.Rd                   | 22 ++++++++++++++++++
 man/weekday0.Rd                    | 25 ++++++++++++++++++++
 man/year0.Rd                       | 19 +++++++++++++++
 tests/run-all.R                    |  4 ++++
 22 files changed, 662 insertions(+)

diff --git a/DESCRIPTION b/DESCRIPTION
new file mode 100755
index 0000000..ea2629d
--- /dev/null
+++ b/DESCRIPTION
@@ -0,0 +1,21 @@
+Package: ISOweek
+Type: Package
+Title: Week of the year and weekday according to ISO 8601
+Version: 0.6-2
+Date: 2011-09-07
+Author: Uwe Block <u.block.mz at googlemail.com>, using an algorithm by
+        Hatto von Hatzfeld <hatto at salesianer.de>
+Maintainer: Uwe Block <u.block.mz at googlemail.com>
+Imports: stringr
+Suggests: testthat
+Description: This is an substitute for the %V and %u formats which are
+        not implemented on Windows. In addition, the package offers
+        functions to convert from standard calender format yyyy-mm-dd
+        to and from ISO 8601 week format yyyy-Www-d.
+License: GPL (>= 2)
+LazyLoad: yes
+Collate: 'ISOweek.R' 'ISOweekday.R' 'date2ISOweek.R' 'ISOweek2date.R'
+        'ISOweek-internal.R'
+Packaged: 2011-09-07 06:45:51 UTC; Uwe
+Repository: CRAN
+Date/Publication: 2011-09-07 07:25:10
diff --git a/MD5 b/MD5
new file mode 100644
index 0000000..8d0c456
--- /dev/null
+++ b/MD5
@@ -0,0 +1,21 @@
+45d6f118749fa5becf439be1a74e8a61 *DESCRIPTION
+9b1fcecf65f88ea3f0c420843a32f7fa *NAMESPACE
+519f0c95d03ef916cb513b81d9ebb53f *NEWS
+eb30c9cfbf56bcfd41ef6dac88743eed *R/ISOweek-internal.R
+b1e8100f6ac6c029a85449cf7687861e *R/ISOweek.R
+b87a8d0729d14ced0b0af5cc4d6767b5 *R/ISOweek2date.R
+beaec8387c382319e3354b83aaad102f *R/ISOweekday.R
+fe126cc496d3732e673975c95ee44960 *R/date2ISOweek.R
+fc22fc851b8e8732c9144909f9e1f2c9 *inst/tests/test-ISOweek-internal.r
+0efe09816e6e53c451243588bdb21ba5 *inst/tests/test-ISOweek.r
+61774a79bcd510e3c5809b70f93a906d *inst/tests/test-ISOweek2date.r
+4f1aee9053e0034a0c8a6df94652700f *inst/tests/test-ISOweekday.r
+ecee54021c873024674f539f89fd225b *inst/tests/test-date2ISOweek.r
+d9e79e6dda1d8affba3dc14f793bb2ab *man/ISOweek.Rd
+445ec8a204d6f2c95846c869c0943c72 *man/ISOweek2date.Rd
+ebdcd16e791345121815f4f11b9c2ef1 *man/ISOweekday.Rd
+b51c1b84626cb12a7336945f5b4ea83a *man/date2ISOweek.Rd
+77c899876a85fcb9de73a78e68a54418 *man/thursday0.Rd
+5b74ebb12cd750c53339d6f7a627c8a1 *man/weekday0.Rd
+df69498b0fa045d7d9379d62ce6218b8 *man/year0.Rd
+43cc7deba9991700886c056f4b03775c *tests/run-all.R
diff --git a/NAMESPACE b/NAMESPACE
new file mode 100755
index 0000000..0fffae2
--- /dev/null
+++ b/NAMESPACE
@@ -0,0 +1,6 @@
+export(date2ISOweek)
+export(ISOweek)
+export(ISOweek2date)
+export(ISOweekday)
+importFrom(stringr,str_detect)
+importFrom(stringr,str_match)
diff --git a/NEWS b/NEWS
new file mode 100755
index 0000000..8e1bfb9
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,42 @@
+ISOweek 0.6-2
+-------------
+
+BUG FIX
+
+* Fixed problems when package "lubridate" is loaded.
+  lubridate overrides + and - methods for POSIXt, Date and difftime
+
+
+ISOweek 0.6-1
+-------------
+
+MINOR CHANGES
+
+* Minor corrections to the documentation
+
+* Added one more example to ISOweek2date()
+
+* Moved internal functions to separate file, added keyword internal
+
+* Corrected email address of maintainer
+
+
+ISOweek 0.6.0
+-------------
+
+MAJOR CHANGES
+
+* Added the functions date2ISOweek() and ISOweek2date()
+
+
+ISOweek 0.5
+-----------
+
+MAJOR CHANGES
+
+* Code was restructured and rewritten. Comments and variable names were translated 
+  from German to English.
+
+* Documentation added to R sources using roxygen2
+
+* Test cases added for use by test_that
diff --git a/R/ISOweek-internal.R b/R/ISOweek-internal.R
new file mode 100755
index 0000000..c7bdee9
--- /dev/null
+++ b/R/ISOweek-internal.R
@@ -0,0 +1,39 @@
+#' Weekday as integer number (0-6, Monday is 0) 
+#'
+#' This internal function returns the weekday of a given date.
+#' 
+#' The week starts on Monday and ends on Sunday.
+#'
+#' @param date Vector which can be coerced to class \code{Date}
+#' @return An integer vector of weekdays (0-6, Monday is 0)
+#' @seealso \code{\link{ISOweekday}}
+#' @keywords internal
+weekday0 <- function(date) {
+  return(ISOweekday(date) - 1L)
+}
+
+#' Date of the nearest Thursday of a given date
+#'
+#' This internal function returns the date of the Thursday of the week in which the given date is located.
+#' 
+#' The week starts on Monday and ends on Sunday.
+#'
+#' @param date Vector which can be coerced to class \code{Date}
+#' @return A vector of dates of the nearest Thursdays
+#' @keywords internal
+thursday0 <- function(date) {
+  date <- as.Date(date)
+  return(date - weekday0(date) + 3)
+}
+
+#' Calendar year of a given date
+#'
+#' This internal function returns the year with century as integer.
+#'
+#' @param date Vector which can be coerced to class \code{Date}
+#' @return An integer vector of years
+#' @keywords internal
+year0 <- function(date) {
+  date <- as.Date(date)
+  return(as.integer(format(date, "%Y")))
+}
diff --git a/R/ISOweek.R b/R/ISOweek.R
new file mode 100755
index 0000000..534a9b0
--- /dev/null
+++ b/R/ISOweek.R
@@ -0,0 +1,39 @@
+#' Week of the year according to ISO 8601
+#'
+#' This function returns the year and the week of the year of a given date according to ISO 8601.
+#' It is an substitute for the \code{\%Y-W\%V} format which is not implemented on Windows.
+#'
+#' According to ISO 8601, the year of the week can differ from the calendar year (see the examples).
+#'
+#' @param date Vector which can be coerced to class \code{Date}
+#' @return A character vector of year and week in format "\code{\%Y-W\%V}"
+#' @seealso \code{\link{strptime}} for a description of the date formats and references on ISO 8601. 
+#'   \code{\link[surveillance]{isoWeekYear}} for an alternative implementation.
+#' @export
+#' @author Hatto von Hatzfeld \email{hatto@@salesianer.de}, 
+#'   adopted to \R by Uwe Block \email{u.block.mz@@googlemail.com}
+#' @references \url{http://www.salesianer.de/util/kalwoch.html}
+#' @examples
+#' x <- paste(1999:2011, "-12-31", sep = "")
+#' y <- as.Date(x)
+#' data.frame(date = format(y), week = ISOweek(y))
+#' data.frame(date = x, week = ISOweek(x))
+ISOweek <- function(date) {
+  date <- as.Date(date)
+	nearest_thursday <- thursday0(date)
+	year <- year0(nearest_thursday)   # year of the week can differ from year of the date
+  # first week of the year includes always the 4th of January,
+  # take care of NA dates
+  january04 <- as.Date(ifelse(is.na(year), NA, paste(year, "01", "04", sep="-")))
+  # first thursday of the year
+	first_thursday <- thursday0(january04)
+  # difference in days, use difftime explicitly to avoid problems with package "lubridate"
+  # lubridate overrides + and - methods for POSIXt, Date and difftime
+  diffdays <- difftime(nearest_thursday, first_thursday, units = "days")
+  stopifnot(class(diffdays) == "difftime")
+  # as.integer is required to convert difftime object
+	week <- as.integer(diffdays) %/% 7 + 1
+  # use sprintf to produce leading zeros for the week number
+	return(ifelse(is.na(week), NA_character_, sprintf("%04.0f-W%02.0f", year, week)))
+}
+
diff --git a/R/ISOweek2date.R b/R/ISOweek2date.R
new file mode 100755
index 0000000..c72ed66
--- /dev/null
+++ b/R/ISOweek2date.R
@@ -0,0 +1,47 @@
+#' Converts date from week notation according to ISO 8601 to standard notation
+#'
+#' This function returns the date of a given weekdate (year, week of the year, day of week according to ISO 8601).
+#' It is the inverse function to \code{date2ISOweek}.
+#'
+#' According to ISO 8601, the year of the week can differ from the calendar year (see the examples).
+#'
+#' @param weekdate A character vector of year, week, and weekday in format "\code{\%Y-W\%V-\%u}"
+#' @return A vector of class \code{Date}
+#' @seealso \code{\link{strptime}} for a description of the date formats and references on ISO 8601. 
+#' @export
+#' @importFrom stringr str_detect str_match
+#' @author Uwe Block \email{u.block.mz@@googlemail.com}
+#' @examples
+#' w <- paste("2009-W53", 1:7, sep = "-")
+#' data.frame(weekdate = w, date = ISOweek2date(w))
+#' # convert from calendar date to week date and back to calendar date
+#' x <- paste(1999:2011, "-12-31", sep = "")
+#' w <- date2ISOweek(x)
+#' d <- ISOweek2date(w)
+#' data.frame(date = x, weekdate = w, date2 = d)
+ISOweek2date <- function(weekdate) {
+  kPattern <- "^([0-9]{4})-W([0-9]{2})-([0-9]{1})$"
+  # not used kPattern <- "^([0-9]{4})-W([0][1-9]|[1-4][0-9]|[5][0-3])-([1-7]{1})$"
+  # instead check ranges separately
+  stopifnot(all(is.na(weekdate) | stringr::str_detect(weekdate, kPattern)))
+  wd_ywd <- stringr::str_match(weekdate, kPattern)
+  # take care of all NA input because this will break the split into 4 columns
+  if (all(is.na(weekdate))) {
+    return(rep(as.Date(NA_character_), length.out = length(weekdate)))
+  }
+  stopifnot(ncol(wd_ywd) == 4)
+  year <- wd_ywd[, 2]
+  week <- as.integer(wd_ywd[, 3])
+  weekday <- as.integer(wd_ywd[, 4])
+  stopifnot(all(is.na(week) | (1 <= week & week <= 53)))
+  stopifnot(all(is.na(weekday) | (1 <= weekday & weekday <= 7)))
+  # first week of the year includes always the 4th of January,
+  # take care of NA dates
+  january04 <- as.Date(ifelse(is.na(year), NA, paste(year, "01", "04", sep="-")))
+  # first thursday of the year
+  first_thursday <- thursday0(january04)
+  # advance by week-1 thursdays
+  nearest_thursday <- first_thursday + 7 * (week - 1)
+  # correct for weekday
+  return(nearest_thursday - 4 + weekday)
+}
\ No newline at end of file
diff --git a/R/ISOweekday.R b/R/ISOweekday.R
new file mode 100755
index 0000000..37dffb4
--- /dev/null
+++ b/R/ISOweekday.R
@@ -0,0 +1,20 @@
+#' Day of week according to ISO 8601
+#'
+#' This function returns the weekday of a given date according to ISO 8601.
+#' It is an substitute for the "\code{\%u}" format which is not implemented on Windows.
+#' 
+#' @param date Vector which can be coerced to class \code{Date}
+#' @return An integer vector of weekdays (1-7, Monday is 1)
+#' @author Uwe Block \email{u.block.mz@@googlemail.com}
+#' @seealso \code{\link{strptime}}
+#' @export
+#' @examples
+#' x <- paste(1999:2011, "-12-31", sep = "")
+#' y <- as.Date(x)
+#' data.frame(date = format(y), weekday = ISOweekday(y))
+#' data.frame(date = x, weekday = ISOweekday(x))
+ISOweekday <- function(date) {
+  date <- as.Date(date)
+  return(as.integer((as.integer(format(date, "%w"))+6) %% 7 + 1))
+}
+
diff --git a/R/date2ISOweek.R b/R/date2ISOweek.R
new file mode 100755
index 0000000..bb5576f
--- /dev/null
+++ b/R/date2ISOweek.R
@@ -0,0 +1,20 @@
+#' Converts date from standard notation to week notation according to ISO 8601
+#'
+#' This function returns the year, the week of the year, and the day of week of a given date according to ISO 8601.
+#' It is an substitute for the \code{\%Y-W\%V-\%u} format which is not implemented on Windows.
+#'
+#' According to ISO 8601, the year of the week can differ from the calendar year (see the examples).
+#'
+#' @param date Vector which can be coerced to class \code{Date}
+#' @return A character vector of year, week, and weekday in format "\code{\%Y-W\%V-\%u}"
+#' @seealso \code{\link{strptime}} for a description of the date formats and references on ISO 8601. 
+#' @export
+#' @author Uwe Block \email{u.block.mz@@googlemail.com}
+#' @examples
+#' x <- paste(1999:2011, "-12-31", sep = "")
+#' y <- as.Date(x)
+#' data.frame(date = format(y), weekdate = date2ISOweek(y))
+#' data.frame(date = x, weekdate = date2ISOweek(x))
+date2ISOweek <- function(date) {
+  return(ifelse(is.na(date), NA_character_, paste(ISOweek(date), ISOweekday(date), sep = "-")))
+}
\ No newline at end of file
diff --git a/inst/tests/test-ISOweek-internal.r b/inst/tests/test-ISOweek-internal.r
new file mode 100755
index 0000000..9f86dd1
--- /dev/null
+++ b/inst/tests/test-ISOweek-internal.r
@@ -0,0 +1,20 @@
+context("Internal functions")
+
+test_that("weekday0 returns proper values", {
+  input_chr <- paste(1999:2011, "-12-31", sep="")
+  input_date <- as.Date(input_chr)
+  result_int <- as.integer(c(5, 7, 1, 2, 3, 5, 6, 7, 1, 3, 4, 5, 6)) - 1L
+  expect_that(weekday0(input_date), equals(result_int))
+  expect_that(weekday0(input_chr), equals(result_int))
+})
+
+test_that("thursday0 returns proper values", {
+  expect_that(thursday0(Sys.Date()), is_a("Date"))
+  expect_that(weekday0(thursday0("1999-12-31")), equals(3L))
+  expect_that(abs(difftime(thursday0(Sys.Date()), Sys.Date(), units = "days")) <= 3, is_true())
+})
+
+test_that("year0 returns proper values", {
+  expect_that(year0(Sys.Date()), is_a("integer"))
+  expect_that(year0(c("1999-12-31", "2000-01-01")), equals(c(1999, 2000)))
+})
diff --git a/inst/tests/test-ISOweek.r b/inst/tests/test-ISOweek.r
new file mode 100755
index 0000000..12db4e3
--- /dev/null
+++ b/inst/tests/test-ISOweek.r
@@ -0,0 +1,42 @@
+context("ISOweek")
+
+test_that("ISOweek returns proper format", {
+  expect_that(ISOweek("1999-12-31"), is_a("character"))
+  expect_that(ISOweek("1999-12-31"), matches("[0-9]{4}-W[0-9]{2}"))
+})
+test_that("ISOweek returns proper values", {
+  input_chr <- paste(1999:2011, "-12-31", sep="")
+  input_date <- as.Date(input_chr)
+  result_chr <- c("1999-W52", "2000-W52", "2002-W01", "2003-W01", "2004-W01", 
+                  "2004-W53", "2005-W52", "2006-W52", "2008-W01", "2009-W01",
+                  "2009-W53", "2010-W52", "2011-W52")
+  expect_that(ISOweek(input_date), equals(result_chr))
+  expect_that(ISOweek(input_chr), equals(result_chr))
+})
+test_that("ISOweek handles NAs", {
+  expect_that(ISOweek(NA), equals(NA_character_))
+  expect_that(ISOweek(NA_character_), equals(NA_character_))
+  input_chr <- paste(1999:2011, "-12-31", sep="")
+  result_chr <- c("1999-W52", "2000-W52", "2002-W01", "2003-W01", "2004-W01", 
+                  "2004-W53", "2005-W52", "2006-W52", "2008-W01", "2009-W01",
+                  "2009-W53", "2010-W52", "2011-W52")
+  idx_NA <- seq(from =2, to = length(input_chr), by = 2)
+  input_chr_NA <- input_chr
+  input_chr_NA[idx_NA] <- NA_character_
+  input_date_NA <- as.Date(input_chr_NA)
+  result_chr_NA <- result_chr
+  result_chr_NA[idx_NA] <- NA
+  expect_that(ISOweek(input_date_NA), equals(result_chr_NA))
+  expect_that(ISOweek(input_chr_NA), equals(result_chr_NA))
+})
+test_that("ISOweek handles zero length vectors", {
+  input_date <- as.Date("1999-12-31")
+  expect_that(length(ISOweek(input_date[0])), equals(0))
+})
+test_that("ISOweek stops on invalid parameters", {
+  expect_that(ISOweek(31), throws_error())
+  expect_that(ISOweek(31.1), throws_error())
+  expect_that(ISOweek(FALSE), throws_error())
+  expect_that(ISOweek("31"), throws_error())
+  expect_that(ISOweek("12/31/1999"), throws_error())
+})
diff --git a/inst/tests/test-ISOweek2date.r b/inst/tests/test-ISOweek2date.r
new file mode 100755
index 0000000..2e5c0da
--- /dev/null
+++ b/inst/tests/test-ISOweek2date.r
@@ -0,0 +1,44 @@
+context("ISOweek2date")
+
+test_that("ISOweek2date returns proper format", {
+  expect_that(ISOweek2date("1999-W01-1"), is_a("Date"))
+})
+test_that("ISOweek2date returns proper values", {
+  input_chr <- c("1999-W52-5", "2000-W52-7", "2002-W01-1", "2003-W01-2", "2004-W01-3", 
+                  "2004-W53-5", "2005-W52-6", "2006-W52-7", "2008-W01-1", "2009-W01-3",
+                  "2009-W53-4", "2010-W52-5", "2011-W52-6")
+  result_chr <- paste(1999:2011, "-12-31", sep="")
+  result_date <- as.Date(result_chr)
+  expect_that(ISOweek2date(input_chr), equals(result_date))
+})
+test_that("ISOweek2date handles NAs", {
+  expect_that(ISOweek2date(NA), equals(as.Date(NA)))
+  expect_that(ISOweek2date(NA_character_), equals(as.Date(NA)))
+  input_chr <- c("1999-W52-5", "2000-W52-7", "2002-W01-1", "2003-W01-2", "2004-W01-3", 
+                  "2004-W53-5", "2005-W52-6", "2006-W52-7", "2008-W01-1", "2009-W01-3",
+                  "2009-W53-4", "2010-W52-5", "2011-W52-6")
+  result_chr <- paste(1999:2011, "-12-31", sep="")
+  result_date <- as.Date(result_chr)
+  idx_NA <- seq(from =2, to = length(input_chr), by = 2)
+  input_chr_NA <- input_chr
+  input_chr_NA[idx_NA] <- NA_character_
+  result_chr_NA <- result_chr
+  result_chr_NA[idx_NA] <- NA
+  result_date_NA <- as.Date(result_chr_NA)
+  expect_that(ISOweek2date(input_chr_NA), equals(result_date_NA))
+})
+test_that("ISOweek2date handles zero length vectors", {
+  input_chr <- c("1999-W52-5")
+  expect_that(length(ISOweek2date(input_chr[0])), equals(0))
+})
+test_that("ISOweek2date stops on invalid parameters", {
+  expect_that(ISOweek2date(31), throws_error())
+  expect_that(ISOweek2date(31.1), throws_error())
+  expect_that(ISOweek2date(FALSE), throws_error())
+  expect_that(ISOweek2date("31"), throws_error())
+  expect_that(ISOweek2date("12/31/1999"), throws_error())
+  expect_that(ISOweek2date("1999-W00-1"), throws_error())
+  expect_that(ISOweek2date("1999-W54-1"), throws_error())
+  expect_that(ISOweek2date("1999-W01-0"), throws_error())
+  expect_that(ISOweek2date("1999-W01-8"), throws_error())
+})
diff --git a/inst/tests/test-ISOweekday.r b/inst/tests/test-ISOweekday.r
new file mode 100755
index 0000000..f5ed194
--- /dev/null
+++ b/inst/tests/test-ISOweekday.r
@@ -0,0 +1,37 @@
+context("ISOweekday")
+
+test_that("ISOweekday returns integer values", {
+  expect_that(ISOweekday("1999-12-31"), is_a("integer"))
+})
+test_that("ISOweekday returns proper values", {
+  input_chr <- paste(1999:2011, "-12-31", sep="")
+  input_date <- as.Date(input_chr)
+  result_int <- as.integer(c(5, 7, 1, 2, 3, 5, 6, 7, 1, 3, 4, 5, 6))
+  expect_that(ISOweekday(input_date), equals(result_int))
+  expect_that(ISOweekday(input_chr), equals(result_int))
+})
+test_that("ISOweekday handles NAs", {
+  expect_that(ISOweekday(NA), equals(NA_integer_))
+  expect_that(ISOweekday(NA_character_), equals(NA_integer_))
+  input_chr <- paste(1999:2011, "-12-31", sep="")
+  result_int <- as.integer(c(5, 7, 1, 2, 3, 5, 6, 7, 1, 3, 4, 5, 6))
+  idx_NA <- seq(from =2, to = length(input_chr), by = 2)
+  input_chr_NA <- input_chr
+  input_chr_NA[idx_NA] <- NA_character_
+  input_date_NA <- as.Date(input_chr_NA)
+  result_int_NA <- result_int
+  result_int_NA[idx_NA] <- NA
+  expect_that(ISOweekday(input_date_NA), equals(result_int_NA))
+  expect_that(ISOweekday(input_chr_NA), equals(result_int_NA))
+})
+test_that("ISOweekday handles zero length vectors", {
+  input_date <- as.Date("1999-12-31")
+  expect_that(length(ISOweekday(input_date[0])), equals(0))
+})
+test_that("ISOweekday stops on invalid parameters", {
+  expect_that(ISOweekday(31), throws_error())
+  expect_that(ISOweekday(31.1), throws_error())
+  expect_that(ISOweekday(FALSE), throws_error())
+  expect_that(ISOweekday("31"), throws_error())
+  expect_that(ISOweekday("12/31/1999"), throws_error())
+})
diff --git a/inst/tests/test-date2ISOweek.r b/inst/tests/test-date2ISOweek.r
new file mode 100755
index 0000000..a649296
--- /dev/null
+++ b/inst/tests/test-date2ISOweek.r
@@ -0,0 +1,42 @@
+context("date2ISOweek")
+
+test_that("date2ISOweek returns proper format", {
+  expect_that(date2ISOweek("1999-12-31"), is_a("character"))
+  expect_that(date2ISOweek("1999-12-31"), matches("[0-9]{4}-W[0-9]{2}-[0-9]{1}"))
+})
+test_that("date2ISOweek returns proper values", {
+  input_chr <- paste(1999:2011, "-12-31", sep="")
+  input_date <- as.Date(input_chr)
+  result_chr <- c("1999-W52-5", "2000-W52-7", "2002-W01-1", "2003-W01-2", "2004-W01-3", 
+                  "2004-W53-5", "2005-W52-6", "2006-W52-7", "2008-W01-1", "2009-W01-3",
+                  "2009-W53-4", "2010-W52-5", "2011-W52-6")
+  expect_that(date2ISOweek(input_date), equals(result_chr))
+  expect_that(date2ISOweek(input_chr), equals(result_chr))
+})
+test_that("date2ISOweek handles NAs", {
+  expect_that(date2ISOweek(NA), equals(NA_character_))
+  expect_that(date2ISOweek(NA_character_), equals(NA_character_))
+  input_chr <- paste(1999:2011, "-12-31", sep="")
+  result_chr <- c("1999-W52-5", "2000-W52-7", "2002-W01-1", "2003-W01-2", "2004-W01-3", 
+                  "2004-W53-5", "2005-W52-6", "2006-W52-7", "2008-W01-1", "2009-W01-3",
+                  "2009-W53-4", "2010-W52-5", "2011-W52-6")
+  idx_NA <- seq(from =2, to = length(input_chr), by = 2)
+  input_chr_NA <- input_chr
+  input_chr_NA[idx_NA] <- NA_character_
+  input_date_NA <- as.Date(input_chr_NA)
+  result_chr_NA <- result_chr
+  result_chr_NA[idx_NA] <- NA
+  expect_that(date2ISOweek(input_date_NA), equals(result_chr_NA))
+  expect_that(date2ISOweek(input_chr_NA), equals(result_chr_NA))
+})
+test_that("date2ISOweek handles zero length vectors", {
+  input_date <- as.Date("1999-12-31")
+  expect_that(length(date2ISOweek(input_date[0])), equals(0))
+})
+test_that("date2ISOweek stops on invalid parameters", {
+  expect_that(date2ISOweek(31), throws_error())
+  expect_that(date2ISOweek(31.1), throws_error())
+  expect_that(date2ISOweek(FALSE), throws_error())
+  expect_that(date2ISOweek("31"), throws_error())
+  expect_that(date2ISOweek("12/31/1999"), throws_error())
+})
diff --git a/man/ISOweek.Rd b/man/ISOweek.Rd
new file mode 100755
index 0000000..30b7200
--- /dev/null
+++ b/man/ISOweek.Rd
@@ -0,0 +1,44 @@
+\name{ISOweek}
+\alias{ISOweek}
+\title{Week of the year according to ISO 8601}
+\usage{
+  ISOweek(date)
+}
+\arguments{
+  \item{date}{Vector which can be coerced to class
+  \code{Date}}
+}
+\value{
+  A character vector of year and week in format
+  "\code{\%Y-W\%V}"
+}
+\description{
+  This function returns the year and the week of the year
+  of a given date according to ISO 8601. It is an
+  substitute for the \code{\%Y-W\%V} format which is not
+  implemented on Windows.
+}
+\details{
+  According to ISO 8601, the year of the week can differ
+  from the calendar year (see the examples).
+}
+\examples{
+x <- paste(1999:2011, "-12-31", sep = "")
+y <- as.Date(x)
+data.frame(date = format(y), week = ISOweek(y))
+data.frame(date = x, week = ISOweek(x))
+}
+\author{
+  Hatto von Hatzfeld \email{hatto at salesianer.de}, adopted
+  to \R by Uwe Block \email{u.block.mz at googlemail.com}
+}
+\references{
+  \url{http://www.salesianer.de/util/kalwoch.html}
+}
+\seealso{
+  \code{\link{strptime}} for a description of the date
+  formats and references on ISO 8601.
+  \code{\link[surveillance]{isoWeekYear}} for an
+  alternative implementation.
+}
+
diff --git a/man/ISOweek2date.Rd b/man/ISOweek2date.Rd
new file mode 100755
index 0000000..c2cef6f
--- /dev/null
+++ b/man/ISOweek2date.Rd
@@ -0,0 +1,39 @@
+\name{ISOweek2date}
+\alias{ISOweek2date}
+\title{Converts date from week notation according to ISO 8601 to standard notation}
+\usage{
+  ISOweek2date(weekdate)
+}
+\arguments{
+  \item{weekdate}{A character vector of year, week, and
+  weekday in format "\code{\%Y-W\%V-\%u}"}
+}
+\value{
+  A vector of class \code{Date}
+}
+\description{
+  This function returns the date of a given weekdate (year,
+  week of the year, day of week according to ISO 8601). It
+  is the inverse function to \code{date2ISOweek}.
+}
+\details{
+  According to ISO 8601, the year of the week can differ
+  from the calendar year (see the examples).
+}
+\examples{
+w <- paste("2009-W53", 1:7, sep = "-")
+data.frame(weekdate = w, date = ISOweek2date(w))
+# convert from calendar date to week date and back to calendar date
+x <- paste(1999:2011, "-12-31", sep = "")
+w <- date2ISOweek(x)
+d <- ISOweek2date(w)
+data.frame(date = x, weekdate = w, date2 = d)
+}
+\author{
+  Uwe Block \email{u.block.mz at googlemail.com}
+}
+\seealso{
+  \code{\link{strptime}} for a description of the date
+  formats and references on ISO 8601.
+}
+
diff --git a/man/ISOweekday.Rd b/man/ISOweekday.Rd
new file mode 100755
index 0000000..54d3f7a
--- /dev/null
+++ b/man/ISOweekday.Rd
@@ -0,0 +1,31 @@
+\name{ISOweekday}
+\alias{ISOweekday}
+\title{Day of week according to ISO 8601}
+\usage{
+  ISOweekday(date)
+}
+\arguments{
+  \item{date}{Vector which can be coerced to class
+  \code{Date}}
+}
+\value{
+  An integer vector of weekdays (1-7, Monday is 1)
+}
+\description{
+  This function returns the weekday of a given date
+  according to ISO 8601. It is an substitute for the
+  "\code{\%u}" format which is not implemented on Windows.
+}
+\examples{
+x <- paste(1999:2011, "-12-31", sep = "")
+y <- as.Date(x)
+data.frame(date = format(y), weekday = ISOweekday(y))
+data.frame(date = x, weekday = ISOweekday(x))
+}
+\author{
+  Uwe Block \email{u.block.mz at googlemail.com}
+}
+\seealso{
+  \code{\link{strptime}}
+}
+
diff --git a/man/date2ISOweek.Rd b/man/date2ISOweek.Rd
new file mode 100755
index 0000000..614b35e
--- /dev/null
+++ b/man/date2ISOweek.Rd
@@ -0,0 +1,38 @@
+\name{date2ISOweek}
+\alias{date2ISOweek}
+\title{Converts date from standard notation to week notation according to ISO 8601}
+\usage{
+  date2ISOweek(date)
+}
+\arguments{
+  \item{date}{Vector which can be coerced to class
+  \code{Date}}
+}
+\value{
+  A character vector of year, week, and weekday in format
+  "\code{\%Y-W\%V-\%u}"
+}
+\description{
+  This function returns the year, the week of the year, and
+  the day of week of a given date according to ISO 8601. It
+  is an substitute for the \code{\%Y-W\%V-\%u} format which
+  is not implemented on Windows.
+}
+\details{
+  According to ISO 8601, the year of the week can differ
+  from the calendar year (see the examples).
+}
+\examples{
+x <- paste(1999:2011, "-12-31", sep = "")
+y <- as.Date(x)
+data.frame(date = format(y), weekdate = date2ISOweek(y))
+data.frame(date = x, weekdate = date2ISOweek(x))
+}
+\author{
+  Uwe Block \email{u.block.mz at googlemail.com}
+}
+\seealso{
+  \code{\link{strptime}} for a description of the date
+  formats and references on ISO 8601.
+}
+
diff --git a/man/thursday0.Rd b/man/thursday0.Rd
new file mode 100755
index 0000000..1e647d4
--- /dev/null
+++ b/man/thursday0.Rd
@@ -0,0 +1,22 @@
+\name{thursday0}
+\alias{thursday0}
+\title{Date of the nearest Thursday of a given date}
+\usage{
+  thursday0(date)
+}
+\arguments{
+  \item{date}{Vector which can be coerced to class
+  \code{Date}}
+}
+\value{
+  A vector of dates of the nearest Thursdays
+}
+\description{
+  This internal function returns the date of the Thursday
+  of the week in which the given date is located.
+}
+\details{
+  The week starts on Monday and ends on Sunday.
+}
+\keyword{internal}
+
diff --git a/man/weekday0.Rd b/man/weekday0.Rd
new file mode 100755
index 0000000..1b8fb9d
--- /dev/null
+++ b/man/weekday0.Rd
@@ -0,0 +1,25 @@
+\name{weekday0}
+\alias{weekday0}
+\title{Weekday as integer number (0-6, Monday is 0)}
+\usage{
+  weekday0(date)
+}
+\arguments{
+  \item{date}{Vector which can be coerced to class
+  \code{Date}}
+}
+\value{
+  An integer vector of weekdays (0-6, Monday is 0)
+}
+\description{
+  This internal function returns the weekday of a given
+  date.
+}
+\details{
+  The week starts on Monday and ends on Sunday.
+}
+\seealso{
+  \code{\link{ISOweekday}}
+}
+\keyword{internal}
+
diff --git a/man/year0.Rd b/man/year0.Rd
new file mode 100755
index 0000000..0ba0930
--- /dev/null
+++ b/man/year0.Rd
@@ -0,0 +1,19 @@
+\name{year0}
+\alias{year0}
+\title{Calendar year of a given date}
+\usage{
+  year0(date)
+}
+\arguments{
+  \item{date}{Vector which can be coerced to class
+  \code{Date}}
+}
+\value{
+  An integer vector of years
+}
+\description{
+  This internal function returns the year with century as
+  integer.
+}
+\keyword{internal}
+
diff --git a/tests/run-all.R b/tests/run-all.R
new file mode 100755
index 0000000..11a92fb
--- /dev/null
+++ b/tests/run-all.R
@@ -0,0 +1,4 @@
+library(testthat)
+library(ISOweek)
+
+test_package("ISOweek")
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/r-cran-isoweek.git



More information about the debian-science-commits mailing list