Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document expand() output with unrealized factor levels #292

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions R/step-subset-expand.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#'
#' @description
#' This is a method for the tidyr `expand()` generic. It is translated to
#' [data.table::CJ()].
#' [data.table::CJ()]. Unlike the data.frame method, this method only retains
#' factor levels present in the data.
#'
#' @param data A [lazy_dt()].
#' @inheritParams tidyr::expand
Expand All @@ -19,12 +20,26 @@
#' weights = rnorm(6, as.numeric(size) + 2)
#' ))
#'
#' # All possible combinations ---------------------------------------
#' # Note that all defined, but not necessarily present, levels of the
#' # factor variable `size` are retained.
#' fruits %>% expand(type)
#' fruits %>% expand(type, size)
#' fruits %>% expand(type, size, year)
#' # Factors ----------------------------------------------------------
#' # When called on `fruits` defined above, the level "L" is not present in
#' # the output of `expand(fruits, size)`, unlike the output of `expand()` when
#' # `fruits` is a data.frame.
#'
#' fruits %>% expand(size) %>% as_tibble()
#' #> # A tibble: 3 × 1
#' #> size
#' #> <fct>
#' #> 1 XS
#' #> 2 S
#' #> 3 M
#' fruits %>% as_tibble() %>% expand(size)
#' #> # A tibble: 4 × 1
#' #> size
#' #> <fct>
#' #> 1 XS
#' #> 2 S
#' #> 3 M
#' #> 4 L
#'
#' # Other uses -------------------------------------------------------
#' fruits %>% expand(type, size, 2010:2012)
Expand Down
29 changes: 22 additions & 7 deletions man/expand.dtplyr_step.Rd

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