Skip to content

Commit

Permalink
update some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
earowang committed Apr 28, 2019
1 parent ab08c87 commit ab9cae6
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 42 deletions.
10 changes: 5 additions & 5 deletions R/as-tsibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#' @seealso [build_tsibble]
#'
#' @examples
#' # create a tsibble w/o a key ----
#' # create a tsibble w/o a key
#' tsibble(
#' date = as.Date("2017-01-01") + 0:9,
#' value = rnorm(10)
#' )
#'
#' # create a tsibble with one key ----
#' # create a tsibble with one key
#' tsibble(
#' qtr = rep(yearquarter("201001") + 0:9, 3),
#' group = rep(c("x", "y", "z"), each = 10),
Expand Down Expand Up @@ -61,16 +61,16 @@ tsibble <- function(..., key = NULL, index, regular = TRUE, .drop = TRUE) {
#' @seealso [tsibble]
#'
#' @examples
#' # coerce tibble to tsibble w/o a key ----
#' # coerce tibble to tsibble w/o a key
#' tbl1 <- tibble(
#' date = as.Date("2017-01-01") + 0:9,
#' value = rnorm(10)
#' )
#' as_tsibble(tbl1)
#' # specify the index var
#' # supply the index to suppress the message
#' as_tsibble(tbl1, index = date)
#'
#' # coerce tibble to tsibble with one key ----
#' # coerce tibble to tsibble with one key
#' # "date" is automatically considered as the index var, and "group" is the key
#' tbl2 <- tibble(
#' mth = rep(yearmonth("2017-01") + 0:9, 3),
Expand Down
4 changes: 2 additions & 2 deletions R/dplyr-verbs.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' * `unnest()` requires argument `key = NULL` to get back to a tsibble.
#'
#' @param .data A `tbl_ts`.
#' @param ... same arguments accepted as its dplyr generic.
#' @param ... Same arguments accepted as its dplyr generic.
#' @inheritParams dplyr::arrange
#' @details
#' Column-wise verbs, including `select()`, `transmute()`, `summarise()`,
Expand Down Expand Up @@ -164,7 +164,7 @@ transmute.grouped_ts <- function(.data, ...) {

#' @rdname tsibble-tidyverse
#' @examples
#' library(dplyr)
#' library(dplyr, warn.conflicts = FALSE)
#' # Sum over sensors ----
#' pedestrian %>%
#' summarise(Total = sum(Count))
Expand Down
13 changes: 7 additions & 6 deletions R/gaps.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ globalVariables(c(".", ".gaps"))
#' key = fruit, index = year
#' )
#'
#' # gaps as default `NA` ----
#' # gaps as default `NA`
#' fill_gaps(harvest, .full = TRUE)
#' full_harvest <- fill_gaps(harvest, .full = FALSE)
#' full_harvest
Expand All @@ -33,26 +33,26 @@ globalVariables(c(".", ".gaps"))
#' group_by(fruit) %>%
#' tidyr::fill(kilo, .direction = "down")
#'
#' # replace gaps with a specific value ----
#' # replace gaps with a specific value
#' harvest %>%
#' fill_gaps(kilo = 0L)
#'
#' # replace gaps using a function by variable ----
#' # replace gaps using a function by variable
#' harvest %>%
#' fill_gaps(kilo = sum(kilo))
#'
#' # replace gaps using a function for each group ----
#' # replace gaps using a function for each group
#' harvest %>%
#' group_by(fruit) %>%
#' fill_gaps(kilo = sum(kilo))
#'
#' # leaves existing `NA` untouched ----
#' # leaves existing `NA` untouched
#' harvest[2, 3] <- NA
#' harvest %>%
#' group_by(fruit) %>%
#' fill_gaps(kilo = sum(kilo, na.rm = TRUE))
#'
#' # replace NA ----
#' # replace NA
#' pedestrian %>%
#' group_by(Sensor) %>%
#' fill_gaps(Count = as.integer(median(Count)))
Expand Down Expand Up @@ -160,6 +160,7 @@ scan_gaps.tbl_ts <- function(.data, .full = FALSE, ...) {
#' @examples
#' ped_gaps <- pedestrian %>%
#' count_gaps(.full = TRUE)
#' ped_gaps
#' if (!requireNamespace("ggplot2", quietly = TRUE)) {
#' stop("Please install the ggplot2 package to run these following examples.")
#' }
Expand Down
10 changes: 5 additions & 5 deletions R/index-by.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' * [yearweek]: weekly aggregation
#' * [as.Date] or [lubridate::as_date]: daily aggregation
#' * [lubridate::ceiling_date], [lubridate::floor_date], or [lubridate::round_date]:
#' sub-daily aggregation
#' fine-resolution aggregation
#' * other index functions from other packages
#'
#' @details
Expand All @@ -27,8 +27,8 @@
#' @rdname index-by
#' @export
#' @examples
#' # Monthly counts across sensors ----
#' library(dplyr)
#' # Monthly counts across sensors
#' library(dplyr, warn.conflicts = FALSE)
#' monthly_ped <- pedestrian %>%
#' group_by(Sensor) %>%
#' index_by(Year_Month = yearmonth(Date_Time)) %>%
Expand All @@ -39,7 +39,7 @@
#' monthly_ped
#' index(monthly_ped)
#'
#' # Using existing variable ----
#' # Using existing variable
#' pedestrian %>%
#' group_by(Sensor) %>%
#' index_by(Date) %>%
Expand All @@ -54,7 +54,7 @@
#' index_by(Date_Time4 = lubridate::floor_date(Date_Time, "4 hour")) %>%
#' summarise(Total_Count = sum(Count))
#'
#' # Annual trips by Region and State ----
#' # Annual trips by Region and State
#' tourism %>%
#' index_by(Year = lubridate::year(Quarter)) %>%
#' group_by(Region, State) %>%
Expand Down
7 changes: 5 additions & 2 deletions R/period.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,22 @@
#' yearweek(x)
#' yearmonth(x)
#' yearmonth(yearweek(x))
#' yearmonth("2018-07")
#' yearquarter(x)
#'
#' # coerce yearmonths to yearquarter
#' y <- yearmonth(x)
#' yearquarter(y)
#'
#' # parse characters
#' yearmonth(c("2018 Jan", "2018-01", "2018 January"))
#' yearquarter(c("2018 Q1", "2018 Qtr1", "2018 Quarter 1"))
#'
#' # seq() and binary operaters
#' wk1 <- yearweek("2017-11-01")
#' wk2 <- yearweek("2018-04-29")
#' seq(from = wk1, to = wk2, by = 2) # by two weeks
#' wk1 + 0:9
#' mth <- yearmonth("2017-11-01")
#' mth <- yearmonth("2017-11")
#' seq(mth, length.out = 5, by = 1) # by 1 month
#' mth + 0:9
#' seq(yearquarter(mth), length.out = 5, by = 1) # by 1 quarter
Expand Down
2 changes: 1 addition & 1 deletion R/time-wise.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' difference(x, lag = 2)
#' difference(x, differences = 2)
#' # Use order_by if data not already ordered (example from dplyr)
#' library(dplyr)
#' library(dplyr, warn.conflicts = FALSE)
#' tsbl <- tsibble(year = 2000:2005, value = (0:5) ^ 2, index = year)
#' scrambled <- tsbl %>% slice(sample(nrow(tsbl)))
#'
Expand Down
6 changes: 3 additions & 3 deletions man/as-tsibble.Rd

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

1 change: 1 addition & 0 deletions man/count_gaps.Rd

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

2 changes: 1 addition & 1 deletion man/difference.Rd

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

12 changes: 6 additions & 6 deletions man/fill_gaps.Rd

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

10 changes: 5 additions & 5 deletions man/index-by.Rd

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

7 changes: 5 additions & 2 deletions man/period.Rd

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

4 changes: 2 additions & 2 deletions man/tsibble-tidyverse.Rd

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

4 changes: 2 additions & 2 deletions man/tsibble.Rd

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

0 comments on commit ab9cae6

Please sign in to comment.