Skip to content

Format with Air #1591

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

Merged
merged 7 commits into from
Feb 21, 2025
Merged
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
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
^\.github/workflows/R\.yaml$
^\.github/workflows/pr-commands\.yaml$
^CRAN-SUBMISSION$
^air.toml$
^\.vscode$
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"[r]": {
"editor.formatOnSave": true
}
}
29 changes: 21 additions & 8 deletions R/chop.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ col_chop <- function(x, indices) {

#' @export
#' @rdname chop
unchop <- function(data,
cols,
...,
keep_empty = FALSE,
ptype = NULL,
error_call = current_env()) {
unchop <- function(
data,
cols,
...,
keep_empty = FALSE,
ptype = NULL,
error_call = current_env()
) {
check_dots_empty0(...)
check_data_frame(data, call = error_call)
check_required(cols, call = error_call)
Expand Down Expand Up @@ -168,7 +170,13 @@ unchop <- function(data,
# used to slice the data frame `x` was subset from to align it with `val`.
# - `val` the unchopped data frame.

df_unchop <- function(x, ..., ptype = NULL, keep_empty = FALSE, error_call = caller_env()) {
df_unchop <- function(
x,
...,
ptype = NULL,
keep_empty = FALSE,
error_call = caller_env()
) {
check_dots_empty()

ptype <- check_list_of_ptypes(ptype, names = names(x), call = error_call)
Expand Down Expand Up @@ -271,7 +279,12 @@ df_unchop <- function(x, ..., ptype = NULL, keep_empty = FALSE, error_call = cal
col <- unname(col)

row_recycle <- col_sizes != sizes
col[row_recycle] <- map2(col[row_recycle], sizes[row_recycle], vec_recycle, call = error_call)
col[row_recycle] <- map2(
col[row_recycle],
sizes[row_recycle],
vec_recycle,
call = error_call
)

col <- list_unchop(
x = col,
Expand Down
16 changes: 3 additions & 13 deletions R/complete.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,12 @@
#' fill = list(value1 = 0, value2 = 99),
#' explicit = FALSE
#' )
complete <- function(data,
...,
fill = list(),
explicit = TRUE) {

complete <- function(data, ..., fill = list(), explicit = TRUE) {
UseMethod("complete")
}

#' @export
complete.data.frame <- function(data,
...,
fill = list(),
explicit = TRUE) {
complete.data.frame <- function(data, ..., fill = list(), explicit = TRUE) {
check_bool(explicit)

out <- expand(data, ...)
Expand All @@ -100,10 +93,7 @@ complete.data.frame <- function(data,
}

#' @export
complete.grouped_df <- function(data,
...,
fill = list(),
explicit = TRUE) {
complete.grouped_df <- function(data, ..., fill = list(), explicit = TRUE) {
out <- dplyr::reframe(
data,
complete(
Expand Down
1 change: 0 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@
#' (downloaded April 2008)
"billboard"


#' Household data
#'
#' This dataset is based on an example in
Expand Down
4 changes: 3 additions & 1 deletion R/dep-extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#' @keywords internal
#' @export
extract_numeric <- function(x) {
message("extract_numeric() is deprecated: please use readr::parse_number() instead")
message(
"extract_numeric() is deprecated: please use readr::parse_number() instead"
)
as.numeric(gsub("[^0-9.-]+", "", as.character(x)))
}

Expand Down
128 changes: 101 additions & 27 deletions R/dep-lazyeval.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,31 @@ nesting_ <- function(x) {
#' @rdname deprecated-se
#' @inheritParams extract
#' @export
extract_ <- function(data, col, into, regex = "([[:alnum:]]+)", remove = TRUE,
convert = FALSE, ...) {
extract_ <- function(
data,
col,
into,
regex = "([[:alnum:]]+)",
remove = TRUE,
convert = FALSE,
...
) {
lifecycle::deprecate_warn("1.0.0", "extract_()", "extract()", always = TRUE)
UseMethod("extract_")
}
#' @export
extract_.data.frame <- function(data, col, into, regex = "([[:alnum:]]+)",
remove = TRUE, convert = FALSE, ...) {
extract_.data.frame <- function(
data,
col,
into,
regex = "([[:alnum:]]+)",
remove = TRUE,
convert = FALSE,
...
) {
col <- compat_lazy(col, caller_env())
extract(data,
extract(
data,
col = !!col,
into = into,
regex = regex,
Expand All @@ -107,7 +122,11 @@ fill_ <- function(data, fill_cols, .direction = c("down", "up")) {
UseMethod("fill_")
}
#' @export
fill_.data.frame <- function(data, fill_cols, .direction = c("down", "up", "downup", "updown")) {
fill_.data.frame <- function(
data,
fill_cols,
.direction = c("down", "up", "downup", "updown")
) {
vars <- syms(fill_cols)
fill(data, !!!vars, .direction = .direction)
}
Expand All @@ -120,20 +139,34 @@ fill_.data.frame <- function(data, fill_cols, .direction = c("down", "up", "down
#' pair of key-value columns.
#' @keywords internal
#' @export
gather_ <- function(data, key_col, value_col, gather_cols, na.rm = FALSE,
convert = FALSE, factor_key = FALSE) {
gather_ <- function(
data,
key_col,
value_col,
gather_cols,
na.rm = FALSE,
convert = FALSE,
factor_key = FALSE
) {
lifecycle::deprecate_warn("1.2.0", "gather_()", "gather()", always = TRUE)
UseMethod("gather_")
}
#' @export
gather_.data.frame <- function(data, key_col, value_col, gather_cols,
na.rm = FALSE, convert = FALSE,
factor_key = FALSE) {
gather_.data.frame <- function(
data,
key_col,
value_col,
gather_cols,
na.rm = FALSE,
convert = FALSE,
factor_key = FALSE
) {
key_col <- sym(key_col)
value_col <- sym(value_col)
gather_cols <- syms(gather_cols)

gather(data,
gather(
data,
key = !!key_col,
value = !!value_col,
!!!gather_cols,
Expand All @@ -154,32 +187,58 @@ nest_ <- function(...) {
#' @rdname deprecated-se
#' @inheritParams separate_rows
#' @export
separate_rows_ <- function(data, cols, sep = "[^[:alnum:].]+",
convert = FALSE) {
separate_rows_ <- function(
data,
cols,
sep = "[^[:alnum:].]+",
convert = FALSE
) {
lifecycle::deprecate_warn("1.2.0", "separate_rows_()", "separate_rows()")
UseMethod("separate_rows_")
}
#' @export
separate_rows_.data.frame <- function(data, cols, sep = "[^[:alnum:].]+",
convert = FALSE) {
separate_rows_.data.frame <- function(
data,
cols,
sep = "[^[:alnum:].]+",
convert = FALSE
) {
cols <- syms(cols)
separate_rows(data, !!!cols, sep = sep, convert = convert)
}

#' @rdname deprecated-se
#' @inheritParams separate
#' @export
separate_ <- function(data, col, into, sep = "[^[:alnum:]]+", remove = TRUE,
convert = FALSE, extra = "warn", fill = "warn", ...) {
separate_ <- function(
data,
col,
into,
sep = "[^[:alnum:]]+",
remove = TRUE,
convert = FALSE,
extra = "warn",
fill = "warn",
...
) {
lifecycle::deprecate_warn("1.2.0", "separate_()", "separate()", always = TRUE)
UseMethod("separate_")
}
#' @export
separate_.data.frame <- function(data, col, into, sep = "[^[:alnum:]]+",
remove = TRUE, convert = FALSE,
extra = "warn", fill = "warn", ...) {
separate_.data.frame <- function(
data,
col,
into,
sep = "[^[:alnum:]]+",
remove = TRUE,
convert = FALSE,
extra = "warn",
fill = "warn",
...
) {
col <- sym(col)
separate(data,
separate(
data,
col = !!col,
into = into,
sep = sep,
Expand All @@ -194,18 +253,33 @@ separate_.data.frame <- function(data, col, into, sep = "[^[:alnum:]]+",
#' @inheritParams spread
#' @param key_col,value_col Strings giving names of key and value cols.
#' @export
spread_ <- function(data, key_col, value_col, fill = NA, convert = FALSE,
drop = TRUE, sep = NULL) {
spread_ <- function(
data,
key_col,
value_col,
fill = NA,
convert = FALSE,
drop = TRUE,
sep = NULL
) {
lifecycle::deprecate_warn("1.2.0", "spread_()", "spread()", always = TRUE)
UseMethod("spread_")
}
#' @export
spread_.data.frame <- function(data, key_col, value_col, fill = NA,
convert = FALSE, drop = TRUE, sep = NULL) {
spread_.data.frame <- function(
data,
key_col,
value_col,
fill = NA,
convert = FALSE,
drop = TRUE,
sep = NULL
) {
key_col <- sym(key_col)
value_col <- sym(value_col)

spread(data,
spread(
data,
key = !!key_col,
value = !!value_col,
fill = fill,
Expand Down
1 change: 0 additions & 1 deletion R/doc-params.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
#' @name tidyr_data_masking
NULL


#' Argument type: tidy-select
#'
#' @description
Expand Down
6 changes: 5 additions & 1 deletion R/drop-na.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ drop_na.data.frame <- function(data, ...) {
# Use all columns if no `...` are supplied
cols <- data
} else {
vars <- tidyselect::eval_select(expr(c(!!!dots)), data, allow_rename = FALSE)
vars <- tidyselect::eval_select(
expr(c(!!!dots)),
data,
allow_rename = FALSE
)
cols <- data[vars]
}

Expand Down
6 changes: 5 additions & 1 deletion R/expand.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ expand_grid <- function(..., .name_repair = "check_unique", .vary = "slowest") {

# Flattens unnamed data frames after grid expansion
out <- tidyr_new_list(out)
out <- df_list(!!!out, .name_repair = .name_repair, .error_call = current_env())
out <- df_list(
!!!out,
.name_repair = .name_repair,
.error_call = current_env()
)
out <- tibble::new_tibble(out, nrow = size)

out
Expand Down
30 changes: 25 additions & 5 deletions R/extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,28 @@
#'
#' # If no match, NA:
#' df %>% extract(x, c("A", "B"), "([a-d]+)-([a-d]+)")
extract <- function(data, col, into, regex = "([[:alnum:]]+)",
remove = TRUE, convert = FALSE, ...) {
extract <- function(
data,
col,
into,
regex = "([[:alnum:]]+)",
remove = TRUE,
convert = FALSE,
...
) {
check_dots_used()
UseMethod("extract")
}
#' @export
extract.data.frame <- function(data, col, into, regex = "([[:alnum:]]+)",
remove = TRUE, convert = FALSE, ...) {
extract.data.frame <- function(
data,
col,
into,
regex = "([[:alnum:]]+)",
remove = TRUE,
convert = FALSE,
...
) {
check_required(col)

var <- tidyselect::vars_pull(names(data), !!enquo(col))
Expand All @@ -61,7 +75,13 @@ extract.data.frame <- function(data, col, into, regex = "([[:alnum:]]+)",
reconstruct_tibble(data, out, if (remove) var else chr())
}

str_extract <- function(x, into, regex, convert = FALSE, error_call = caller_env()) {
str_extract <- function(
x,
into,
regex,
convert = FALSE,
error_call = caller_env()
) {
check_string(regex, call = error_call)
check_not_stringr_pattern(regex, call = error_call)
check_character(into, call = error_call)
Expand Down
Loading
Loading