Skip to content

Commit

Permalink
[Fix #456] Remove output from examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vspinu committed Aug 17, 2016
1 parent 310b201 commit 654c8ee
Show file tree
Hide file tree
Showing 53 changed files with 0 additions and 386 deletions.
4 changes: 0 additions & 4 deletions R/accessors-day.r
Expand Up @@ -21,15 +21,11 @@ NULL
#' wday(x) #4
#'
#' wday(ymd(080101))
#' # 3
#' wday(ymd(080101), label = TRUE, abbr = FALSE)
#' # "Tuesday"
#' # Levels: Sunday < Monday < Tuesday < Wednesday < Thursday < Friday < Saturday
#' wday(ymd(080101), label = TRUE, abbr = TRUE)
#' # "Tues"
#' # Levels: Sunday < Monday < Tuesday < Wednesday < Thursday < Friday < Saturday
#' wday(ymd(080101) + days(-2:4), label = TRUE, abbr = TRUE)
#' # "Sun" "Mon" "Tues" "Wed" "Thurs" "Fri" "Sat"
#' # Levels: Sunday < Monday < Tuesday < Wednesday < Thursday < Friday < Saturday
#'
#' x <- as.Date("2009-09-02")
Expand Down
4 changes: 0 additions & 4 deletions R/accessors-month.r
Expand Up @@ -24,13 +24,9 @@ NULL
#' month(x) > 3
#'
#' month(ymd(080101))
#' # 1
#' month(ymd(080101), label = TRUE)
#' # "Jan"
#' month(ymd(080101), label = TRUE, abbr = FALSE)
#' # "January"
#' month(ymd(080101) + months(0:11), label = TRUE)
#' # "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
#' @export
month <- function(x, label = FALSE, abbr = TRUE)
UseMethod("month")
Expand Down
2 changes: 0 additions & 2 deletions R/accessors-quarter.r
Expand Up @@ -17,9 +17,7 @@ NULL
#' @examples
#' x <- ymd(c("2012-03-26", "2012-05-04", "2012-09-23", "2012-12-31"))
#' quarter(x)
#' # 1 2 3 4
#' quarter(x, with_year = TRUE)
#' # 2012.1 2012.2 2012.3 2012.4
#' @export
quarter <- function(x, with_year = FALSE) {
m <- month(x)
Expand Down
25 changes: 0 additions & 25 deletions R/coercion.r
Expand Up @@ -150,16 +150,11 @@ setMethod("reclass_timespan", signature(orig = "Period"), function(new, orig){
#' @keywords classes manip methods chron
#' @examples
#' span <- interval(ymd("2009-01-01"), ymd("2009-08-01")) #interval
#' # "2009-01-01 UTC--2009-08-01 UTC"
#' as.duration(span)
#' # 18316800s (~212 days)
#' as.duration(10) # numeric
#' # 10s
#' dur <- duration(hours = 10, minutes = 6)
#' as.numeric(dur, "hours")
#' # 10.1
#' as.numeric(dur, "minutes")
#' # 606
#' @aliases as.duration,numeric-method as.duration,logical-method as.duration,difftime-method as.duration,Interval-method as.duration,Duration-method as.duration,Period-method
#' @export
as.duration <- function(x) standardGeneric("as.duration")
Expand Down Expand Up @@ -222,24 +217,17 @@ setMethod("as.duration", signature(x = "Period"), function(x){
#' @examples
#' diff <- make_difftime(days = 31) #difftime
#' as.interval(diff, ymd("2009-01-01"))
#' # 2009-01-01 UTC--2009-02-01 UTC
#' as.interval(diff, ymd("2009-02-01"))
#' # 2009-02-01 UTC--2009-03-04 UTC
#'
#' dur <- duration(days = 31) #duration
#' as.interval(dur, ymd("2009-01-01"))
#' # 2009-01-01 UTC--2009-02-01 UTC
#' as.interval(dur, ymd("2009-02-01"))
#' # 2009-02-01 UTC--2009-03-04 UTC
#'
#' per <- period(months = 1) #period
#' as.interval(per, ymd("2009-01-01"))
#' # 2009-01-01 UTC--2009-02-01 UTC
#' as.interval(per, ymd("2009-02-01"))
#' # 2009-02-01 UTC--2009-03-01 UTC
#'
#' as.interval(3600, ymd("2009-01-01")) #numeric
#' # 2009-01-01 UTC--2009-01-01 01:00:00 UTC
#' @aliases as.interval,numeric-method as.interval,difftime-method as.interval,Interval-method as.interval,Duration-method as.interval,Period-method as.interval,POSIXt-method as.interval,logical-method
#' @export
as.interval <- function(x, start, ...) standardGeneric("as.interval")
Expand Down Expand Up @@ -326,29 +314,19 @@ setMethod("as.interval", signature("logical"), function(x, start, ...) {
#' @keywords classes manip methods chron
#' @examples
#' span <- interval(as.POSIXct("2009-01-01"), as.POSIXct("2010-02-02 01:01:01")) #interval
#' # 2009-01-01 CST--2010-02-02 01:01:01 CST
#' as.period(span)
#' # "1y 1m 1d 1H 1M 1S"
#' as.period(span, units = "day")
#' "397d 1H 1M 1S"
#' leap <- interval(ymd("2016-01-01"), ymd("2017-01-01"))
#' # 2016-01-01 UTC--2017-01-01 UTC
#' as.period(leap, unit = "days")
#' # "366d 0H 0M 0S"
#' as.period(leap, unit = "years")
#' # "1y 0m 0d 0H 0M 0S"
#' dst <- interval(ymd("2016-11-06", tz = "America/Chicago"),
#' ymd("2016-11-07", tz = "America/Chicago"))
#' # 2016-11-06 CDT--2016-11-07 CST
#' # as.period(dst, unit = "seconds")
#' # "86400S"
#' as.period(dst, unit = "hours")
#' # "24H 0M 0S"
#' per <- period(hours = 10, minutes = 6)
#' as.numeric(per, "hours")
#' # 10.1
#' as.numeric(per, "minutes")
#' # 606
#' @aliases as.period,numeric-method as.period,difftime-method as.period,Interval-method as.period,Duration-method as.period,Period-method as.period,logical-method
#' @export
as.period <- function(x, unit, ...) standardGeneric("as.period")
Expand Down Expand Up @@ -635,12 +613,9 @@ setMethod("as.character", signature(x = "Interval"), function(x, ...){
#' dt_utc <- ymd_hms("2010-08-03 00:50:50")
#' dt_europe <- ymd_hms("2010-08-03 00:50:50", tz="Europe/London")
#' c(as_date(dt_utc), as.Date(dt_utc))
#' ## [1] "2010-08-03" "2010-08-03"
#' c(as_date(dt_europe), as.Date(dt_europe))
#' ## [1] "2010-08-03" "2010-08-02"
#' ## need not suply origin
#' as_date(10)
#' ## [1] "1970-01-11"
#' @export
setGeneric(name = "as_date",
def = function(x, ...) standardGeneric("as_date"),
Expand Down
1 change: 0 additions & 1 deletion R/difftimes.r
Expand Up @@ -51,7 +51,6 @@ setOldClass("difftime")
#' # Time difference of -1 days
#' make_difftime(120, day = -1, units = "minute")
#' # Time differences in mins
#' # [1] 2 -1440
make_difftime <- function(num = NULL, units = "auto", ...) {
pieces <- list(...)
if(!is.null(num) && length(pieces) > 0){
Expand Down
20 changes: 0 additions & 20 deletions R/durations.r
Expand Up @@ -177,21 +177,14 @@ setMethod("[[<-", signature(x = "Duration"),
#' duration(day = -1)
#' # -86400s (~-1 days)
#' duration(90, "seconds")
#' # 90s
#' duration(1.5, "minutes")
#' # 90s
#' duration(-1, "days")
#' # -86400s (~-1 days)
#' duration(second = 90)
#' # 90s
#' duration(minute = 1.5)
#' # 90s
#' duration(mins = 1.5)
#' # 90s
#' duration(second = 3, minute = 1.5, hour = 2, day = 6, week = 1)
#' # 1130493s (~13.08 days)
#' duration(hour = 1, minute = -60)
#' # 0s
#' @export
duration <- function(num = NULL, units = "seconds", ...){
nums <- list(...)
Expand Down Expand Up @@ -255,37 +248,24 @@ duration <- function(num = NULL, units = "seconds", ...){
#' @keywords chron manip
#' @examples
#' dseconds(1)
#' # 1s
#' dminutes(3.5)
#' # 210s (~3.5 minutes)
#'
#' x <- as.POSIXct("2009-08-03")
#' # "2009-08-03 CDT"
#' x + ddays(1) + dhours(6) + dminutes(30)
#' # "2009-08-04 06:30:00 CDT"
#' x + ddays(100) - dhours(8)
#' # "2009-11-10 15:00:00 CST"
#'
#' class(as.Date("2009-08-09") + ddays(1)) # retains Date class
#' # "Date"
#' as.Date("2009-08-09") + dhours(12)
#' # "2009-08-09 12:00:00 UTC"
#' class(as.Date("2009-08-09") + dhours(12))
#' # "POSIXct" "POSIXt"
#' # converts to POSIXt class to accomodate time units
#'
#' dweeks(1) - ddays(7)
#' # 0s
#' c(1:3) * dhours(1)
#' # 3600s (~1 hours) 7200s (~2 hours) 10800s (~3 hours)
#' #
#' # compare DST handling to durations
#' boundary <- as.POSIXct("2009-03-08 01:59:59")
#' # "2009-03-08 01:59:59 CST"
#' boundary + days(1) # period
#' # "2009-03-09 01:59:59 CDT" (clock time advances by a day)
#' boundary + ddays(1) # duration
#' # "2009-03-09 02:59:59 CDT" (clock time corresponding to 86400 seconds later)
#' @export dseconds dminutes dhours ddays dweeks dyears dmilliseconds dmicroseconds dnanoseconds dpicoseconds
dseconds <- function(x = 1) new("Duration", x)
#' @rdname quick_durations
Expand Down
3 changes: 0 additions & 3 deletions R/instants.r
Expand Up @@ -69,7 +69,6 @@ today <- function(tzone = "") {
#' @keywords data chron
#' @examples
#' origin
#' # "1970-01-01 GMT"
origin <- with_tz(structure(0, class = c("POSIXct", "POSIXt")), "UTC")


Expand All @@ -94,9 +93,7 @@ origin <- with_tz(structure(0, class = c("POSIXct", "POSIXt")), "UTC")
##' @useDynLib lubridate make_dt
##' @examples
##' make_datetime(year = 1999, month = 12, day = 22, sec = 10)
##' ## "1999-12-22 00:00:10 UTC"
##' make_datetime(year = 1999, month = 12, day = 22, sec = c(10, 11))
##' ## "1999-12-22 00:00:10 UTC" "1999-12-22 00:00:11 UTC"
make_datetime <- function(year = 1970L, month = 1L, day = 1L, hour = 0L, min = 0L, sec = 0, tz = "UTC"){
lengths <- vapply(list(year, month, day, hour, min, sec), length, 1, USE.NAMES = FALSE)
if (min(lengths) == 0L){
Expand Down
27 changes: 0 additions & 27 deletions R/intervals.r
Expand Up @@ -207,16 +207,12 @@ unique.Interval <- function(x, ...){
#' @seealso \code{\link{Interval-class}}, \code{\link{as.interval}}
#' @examples
#' interval(ymd(20090201), ymd(20090101))
#' # 2009-02-01 UTC--2009-01-01 UTC
#'
#' date1 <- as.POSIXct("2009-03-08 01:59:59")
#' date2 <- as.POSIXct("2000-02-29 12:00:00")
#' interval(date2, date1)
#' # 2000-02-29 12:00:00 CST--2009-03-08 01:59:59 CST
#' interval(date1, date2)
#' # 2009-03-08 01:59:59 CST--2000-02-29 12:00:00 CST
#' span <- interval(ymd(20090101), ymd(20090201))
#' # 2009-01-01 UTC--2009-02-01 UTC
#'
#' is.interval(period(months= 1, days = 15)) # FALSE
#' is.interval(interval(ymd(20090801), ymd(20090809))) # TRUE
Expand Down Expand Up @@ -261,12 +257,9 @@ is.interval <- function(x) is(x, c("Interval"))
#' \code{\link{int_length}}
#' @examples
#' int <- interval(ymd("2001-01-01"), ymd("2002-01-01"))
#' # 2001-01-01 UTC--2002-01-01 UTC
#' int_start(int)
#' # "2001-01-01 UTC"
#' int_start(int) <- ymd("2001-06-01")
#' int
#' # 2001-06-01 UTC--2002-01-01 UTC
int_start <- function(int) int@start

#' @rdname int_start
Expand All @@ -293,12 +286,9 @@ int_start <- function(int) int@start
#' \code{\link{int_length}}
#' @examples
#' int <- interval(ymd("2001-01-01"), ymd("2002-01-01"))
#' # 2001-01-01 UTC--2002-01-01 UTC
#' int_end(int)
#' # "2002-01-01 UTC"
#' int_end(int) <- ymd("2002-06-01")
#' int
#' # 2001-01-01 UTC--2002-06-01 UTC
int_end <- function(int) int@start + int@.Data

#' @export
Expand All @@ -320,9 +310,7 @@ int_end <- function(int) int@start + int@.Data
#' @seealso \code{\link{int_start}}, \code{\link{int_shift}}, \code{\link{int_flip}}
#' @examples
#' int <- interval(ymd("2001-01-01"), ymd("2002-01-01"))
#' # 2001-01-01 UTC--2002-01-01 UTC
#' int_length(int)
#' # 31536000
int_length <- function(int) int@.Data

#' Flip the direction of an interval
Expand All @@ -338,9 +326,7 @@ int_length <- function(int) int@.Data
#' \code{\link{int_length}}
#' @examples
#' int <- interval(ymd("2001-01-01"), ymd("2002-01-01"))
#' # 2001-01-01 UTC--2002-01-01 UTC
#' int_flip(int)
#' # 2002-01-01 UTC--2001-01-01 UTC
int_flip <- function(int){
new("Interval", -int@.Data, start = int@start + int@.Data, tzone = int@tzone)
}
Expand All @@ -360,11 +346,8 @@ int_flip <- function(int){
#' \code{\link{int_length}}
#' @examples
#' int <- interval(ymd("2001-01-01"), ymd("2002-01-01"))
#' # 2001-01-01 UTC--2002-01-01 UTC
#' int_shift(int, duration(days = 11))
#' # 2001-01-12 UTC--2002-01-12 UTC
#' int_shift(int, duration(hours = -1))
#' # 2000-12-31 23:00:00 UTC--2001-12-31 23:00:00 UTC
int_shift <- function(int, by){
if(!is.timespan(by)) stop("by is not a recognized timespan object")
if(is.interval(by)) stop("an interval cannot be shifted by another interval.
Expand All @@ -381,11 +364,8 @@ int_shift <- function(int, by){
#' @return Logical. TRUE if int1 and int2 overlap by at least one second. FALSE otherwise.
#' @examples
#' int1 <- interval(ymd("2001-01-01"), ymd("2002-01-01"))
#' # 2001-01-01 UTC--2002-01-01 UTC
#' int2 <- interval(ymd("2001-06-01"), ymd("2002-06-01"))
#' # 2001-06-01 UTC--2002-06-01 UTC
#' int3 <- interval(ymd("2003-01-01"), ymd("2004-01-01"))
#' # 2003-01-01 UTC--2004-01-01 UTC
#'
#' int_overlaps(int1, int2) # TRUE
#' int_overlaps(int1, int3) # FALSE
Expand All @@ -405,9 +385,7 @@ int_overlaps <- function(int1, int2){
#' @param int an Interval object
#' @examples
#' int <- interval(ymd("2002-01-01"), ymd("2001-01-01"))
#' # 2002-01-01 UTC--2001-01-01 UTC
#' int_standardize(int)
#' # 2001-01-01 UTC--2002-01-01 UTC
int_standardize <- function(int){
negs <- !is.na(int@.Data) & int@.Data < 0
int[negs] <- int_flip(int[negs])
Expand All @@ -428,11 +406,8 @@ int_standardize <- function(int){
#' @return Logical. TRUE if int1 and int2 begin or end on the same moment. FALSE otherwise.
#' @examples
#' int1 <- interval(ymd("2001-01-01"), ymd("2002-01-01"))
#' # 2001-01-01 UTC--2002-01-01 UTC
#' int2 <- interval(ymd("2001-06-01"), ymd("2002-01-01"))
#' # 2001-06-01 UTC--2002-01-01 UTC
#' int3 <- interval(ymd("2003-01-01"), ymd("2004-01-01"))
#' # 2003-01-01 UTC--2004-01-01 UTC
#'
#' int_aligns(int1, int2) # TRUE
#' int_aligns(int1, int3) # FALSE
Expand Down Expand Up @@ -559,9 +534,7 @@ setMethod("setdiff", signature(x = "Interval", y = "Interval"), function(x,y){
#' @return A logical
#' @examples
#' int <- interval(ymd("2001-01-01"), ymd("2002-01-01"))
#' # 2001-01-01 UTC--2002-01-01 UTC
#' int2 <- interval(ymd("2001-06-01"), ymd("2002-01-01"))
#' # 2001-06-01 UTC--2002-01-01 UTC
#'
#' ymd("2001-05-03") %within% int # TRUE
#' int2 %within% int # TRUE
Expand Down
12 changes: 0 additions & 12 deletions R/ops-%m+%.r
Expand Up @@ -41,19 +41,15 @@ NULL
#' @return A date-time object of class POSIXlt, POSIXct or Date
#' @examples
#' jan <- ymd_hms("2010-01-31 03:04:05")
#' # "2010-01-31 03:04:05 UTC"
#' jan + months(1:3) # Feb 31 and April 31 returned as NA
#' # NA "2010-03-31 03:04:05 UTC" NA
#' jan %m+% months(1:3) # No rollover
#' # "2010-02-28 03:04:05 UTC" "2010-03-31 03:04:05 UTC" "2010-04-30 03:04:05 UTC"
#'
#' leap <- ymd("2012-02-29")
#' "2012-02-29 UTC"
#' leap %m+% years(1)
#' # "2013-02-28 UTC"
#' leap %m+% years(-1)
#' leap %m-% years(1)
#' # "2011-02-28 UTC"
#' @export
"%m+%" <- function(e1,e2) standardGeneric("%m+%")

Expand Down Expand Up @@ -149,24 +145,16 @@ add_with_rollback <- function(e1, e2, roll_to_first = FALSE, preserve_hms = TRUE
#' the month.
#' @examples
#' date <- ymd("2010-03-03")
#' # "2010-03-03 UTC"
#' rollback(date)
#' # "2010-02-28 UTC"
#'
#' dates <- date + months(0:2)
#' # "2010-03-03 UTC" "2010-04-03 UTC" "2010-05-03 UTC"
#' rollback(dates)
#' # "2010-02-28 UTC" "2010-03-31 UTC" "2010-04-30 UTC"
#'
#' date <- ymd_hms("2010-03-03 12:44:22")
#' rollback(date)
#' # "2010-02-28 12:44:22 UTC"
#' rollback(date, roll_to_first = TRUE)
#' # "2010-03-01 12:44:22 UTC"
#' rollback(date, preserve_hms = FALSE)
#' # "2010-02-28 UTC"
#' rollback(date, roll_to_first = TRUE, preserve_hms = FALSE)
#' # "2010-03-01 UTC"
rollback <- function(dates, roll_to_first = FALSE, preserve_hms = TRUE) {
if (length(dates) == 0)
return(dates)
Expand Down

0 comments on commit 654c8ee

Please sign in to comment.