Skip to content

Commit

Permalink
Update to PR tidyverse#504. Use anonymous function instead of compose
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbutuseless committed Mar 4, 2019
1 parent 5ce48b5 commit 74d5f71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 8 additions & 5 deletions R/fill.R
Expand Up @@ -16,20 +16,23 @@ NULL
#' with `x:z`, exclude `y` with `-y`. For more selection options, see the
#' [dplyr::select()] documentation.
#' @param .direction Direction in which to fill missing values. Currently
#' either "down" (the default) or "up".
#' either "down" (the default), "up", "downup" (i.e. first down and then up)
#' or "updown" (first up and then down).
#' @export
#' @examples
#' df <- data.frame(Month = 1:12, Year = c(2000, rep(NA, 11)))
#' df %>% fill(Year)
fill <- function(data, ..., .direction = c("down", "up")) {
fill <- function(data, ..., .direction = c("down", "up", "downup", "updown")) {
UseMethod("fill")
}
#' @export
fill.data.frame <- function(data, ..., .direction = c("down", "up")) {
fill.data.frame <- function(data, ..., .direction = c("down", "up", "downup", "updown")) {
fill_cols <- unname(tidyselect::vars_select(names(data), ...))

.direction <- match.arg(.direction)
fillVector <- switch(.direction, down = fillDown, up = fillUp)
fillVector <- switch(.direction, down = fillDown, up = fillUp,
downup = function(x) {fillUp(fillDown(x))},
updown = function(x) {fillDown(fillUp(x))})

for (col in fill_cols) {
data[[col]] <- fillVector(data[[col]])
Expand All @@ -38,6 +41,6 @@ fill.data.frame <- function(data, ..., .direction = c("down", "up")) {
data
}
#' @export
fill.grouped_df <- function(data, ..., .direction = c("down", "up")) {
fill.grouped_df <- function(data, ..., .direction = c("down", "up", "downup", "updown")) {
dplyr::do(data, fill(., ..., .direction = .direction))
}
3 changes: 2 additions & 1 deletion man/deprecated-se.Rd

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

5 changes: 3 additions & 2 deletions man/fill.Rd

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

0 comments on commit 74d5f71

Please sign in to comment.