Skip to content

styling with styler #1

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

Closed
wants to merge 1 commit 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
24 changes: 12 additions & 12 deletions R/compat-lazyeval.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ compat_lazy <- function(lazy, env = caller_env(), warn = TRUE) {
}

coerce_type(lazy, "a quosure",
formula = as_quosure(lazy, env),
symbol = ,
language = new_quosure(lazy, env),
string = ,
character = {
formula = as_quosure(lazy, env),
symbol =,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add this rlang styling rule that puts a space between = and ,?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in r-lib/styler#150.

language = new_quosure(lazy, env),
string =,
character = {
if (warn) warn_text_se()
parse_quosure(lazy[[1]], env)
},
logical = ,
integer = ,
double = {
logical =,
integer =,
double = {
if (length(lazy) > 1) {
warn("Truncating vector to length 1")
lazy <- lazy[[1]]
}
new_quosure(lazy, env)
},
list =
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about how to continue after },. Do you think it's done right now?

coerce_class(lazy, "a quosure",
lazy = new_quosure(lazy$expr, lazy$env)
)
list =
coerce_class(lazy, "a quosure",
lazy = new_quosure(lazy$expr, lazy$env)
)
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/complete.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ complete_ <- function(data, cols, fill = list(), ...) {
#' @export
complete_.data.frame <- function(data, cols, fill = list(), ...) {
cols <- compat_lazy_dots(cols, caller_env())
complete(data, !!! cols, fill = fill)
complete(data, !!!cols, fill = fill)
}
2 changes: 1 addition & 1 deletion R/drop_na.r
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ drop_na_ <- function(data, vars) {
#' @export
drop_na_.data.frame <- function(data, vars) {
vars <- compat_lazy_dots(vars, caller_env())
drop_na(data, !!! vars)
drop_na(data, !!!vars)
}
15 changes: 7 additions & 8 deletions R/expand.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ expand.data.frame <- function(data, ...) {
}

pieces <- map(dots, eval_tidy, data)
df <- crossing(!!! pieces)
df <- crossing(!!!pieces)

reconstruct_tibble(data, df)
}
#' @export
expand.grouped_df <- function(data, ...) {
dots <- quos(...)
dplyr::do(data, expand(., !!! dots))
dplyr::do(data, expand(., !!!dots))
}

#' @rdname deprecated-se
Expand All @@ -111,7 +111,7 @@ expand_ <- function(data, dots, ...) {
#' @export
expand_.data.frame <- function(data, dots, ...) {
dots <- compat_lazy_dots(dots, caller_env())
expand(data, !!! dots)
expand(data, !!!dots)
}


Expand All @@ -135,7 +135,6 @@ crossing <- function(...) {
"Each element must be either an atomic vector or a data frame.
Problems: {problems}."
))

}

# turn each atomic vector into single column data frame
Expand All @@ -148,7 +147,7 @@ crossing <- function(...) {
cross_df <- function(x, y) {
x_idx <- rep(seq_len(nrow(x)), each = nrow(y))
y_idx <- rep(seq_len(nrow(y)), nrow(x))
dplyr::bind_cols(x[x_idx, , drop = FALSE], y[y_idx, , drop = FALSE])
dplyr::bind_cols(x[x_idx,, drop = FALSE], y[y_idx,, drop = FALSE])
}
drop_empty <- function(x) {
empty <- map_lgl(x, function(x) length(x) == 0)
Expand All @@ -165,7 +164,7 @@ nesting <- function(...) {

df <- as_tibble(x)
df <- dplyr::distinct(df)
df[do.call(order, df), , drop = FALSE]
df[do.call(order, df),, drop = FALSE]
}


Expand All @@ -174,11 +173,11 @@ nesting <- function(...) {
#' @export
crossing_ <- function(x) {
x <- compat_lazy_dots(x, caller_env())
crossing(!!! x)
crossing(!!!x)
}
#' @rdname deprecated-se
#' @export
nesting_ <- function(x) {
x <- compat_lazy_dots(x, caller_env())
nesting(!!! x)
nesting(!!!x)
}
28 changes: 14 additions & 14 deletions R/extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ extract <- function(data, col, into, regex = "([[:alnum:]]+)",
extract.default <- function(data, col, into, regex = "([[:alnum:]]+)",
remove = TRUE, convert = FALSE, ...) {
extract_(data,
col = compat_as_lazy(enquo(col)),
into = into,
regex = regex,
remove = remove,
convert = convert,
...
col = compat_as_lazy(enquo(col)),
into = into,
regex = regex,
remove = remove,
convert = convert,
...
)
}
#' @export
extract.data.frame <- function(data, col, into, regex = "([[:alnum:]]+)",
remove = TRUE, convert = FALSE, ...) {
var <- tidyselect::vars_pull(names(data), !! enquo(col))
var <- tidyselect::vars_pull(names(data), !!enquo(col))
stopifnot(
is_string(regex),
is_character(into)
Expand Down Expand Up @@ -79,19 +79,19 @@ extract.data.frame <- function(data, col, into, regex = "([[:alnum:]]+)",
#' @inheritParams extract
#' @export
extract_ <- function(data, col, into, regex = "([[:alnum:]]+)", remove = TRUE,
convert = FALSE, ...) {
convert = FALSE, ...) {
UseMethod("extract_")
}
#' @export
extract_.data.frame <- function(data, col, into, regex = "([[:alnum:]]+)",
remove = TRUE, convert = FALSE, ...) {
col <- compat_lazy(col, caller_env())
extract(data,
col = !! col,
into = into,
regex = regex,
remove = remove,
convert = convert,
...
col = !!col,
into = into,
regex = regex,
remove = remove,
convert = convert,
...
)
}
2 changes: 1 addition & 1 deletion R/fill.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ fill_ <- function(data, fill_cols, .direction = c("down", "up")) {
#' @export
fill_.data.frame <- function(data, fill_cols, .direction = c("down", "up")) {
vars <- compat_lazy_dots(fill_cols, caller_env())
fill(data, !!! vars, .direction = .direction)
fill(data, !!!vars, .direction = .direction)
}
47 changes: 23 additions & 24 deletions R/gather.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ gather.default <- function(data, key = "key", value = "value", ...,
na.rm = FALSE, convert = FALSE,
factor_key = FALSE) {
gather_(data,
key_col = compat_as_lazy(enquo(key)),
value_col = compat_as_lazy(enquo(value)),
...,
na.rm = na.rm,
convert = convert,
factor_key = factor_key
key_col = compat_as_lazy(enquo(key)),
value_col = compat_as_lazy(enquo(value)),
...,
na.rm = na.rm,
convert = convert,
factor_key = factor_key
)
}
#' @export
Expand All @@ -83,7 +83,7 @@ gather.data.frame <- function(data, key = "key", value = "value", ...,
if (is_empty(quos)) {
gather_vars <- setdiff(names(data), c(key_var, value_var))
} else {
gather_vars <- unname(tidyselect::vars_select(names(data), !!! quos))
gather_vars <- unname(tidyselect::vars_select(names(data), !!!quos))
}
if (is_empty(gather_vars)) {
return(data)
Expand All @@ -101,14 +101,14 @@ gather.data.frame <- function(data, key = "key", value = "value", ...,
valueAsFactor <- "factor" %in% class(args$attr_template)

out <- melt_dataframe(data,
id_idx - 1L,
gather_idx - 1L,
as.character(key_var),
as.character(value_var),
args$attr_template,
args$factorsAsStrings,
as.logical(valueAsFactor),
as.logical(factor_key)
id_idx - 1L,
gather_idx - 1L,
as.character(key_var),
as.character(value_var),
args$attr_template,
args$factorsAsStrings,
as.logical(valueAsFactor),
as.logical(factor_key)
)

if (na.rm && anyNA(out)) {
Expand All @@ -127,10 +127,9 @@ gather.data.frame <- function(data, key = "key", value = "value", ...,

## Get the attributes if common, NULL if not.
normalize_melt_arguments <- function(data, measure.ind, factorsAsStrings) {

measure.attributes <- map(measure.ind, function(i) {
attributes(data[[i]])
})
attributes(data[[i]])
})

## Determine if all measure.attributes are equal
measure.attrs.equal <- all_identical(measure.attributes)
Expand Down Expand Up @@ -193,11 +192,11 @@ gather_.data.frame <- function(data, key_col, value_col, gather_cols,
gather_cols <- compat_lazy_dots(gather_cols, caller_env())

gather(data,
key = !! key_col,
value = !! value_col,
!!! gather_cols,
na.rm = na.rm,
convert = convert,
factor_key = factor_key
key = !!key_col,
value = !!value_col,
!!!gather_cols,
na.rm = na.rm,
convert = convert,
factor_key = factor_key
)
}
8 changes: 4 additions & 4 deletions R/nest.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ nest.data.frame <- function(data, ..., .key = "data") {

data <- dplyr::ungroup(data)
if (is_empty(group_vars)) {
return(tibble(!! key_var := list(data)))
return(tibble(!!key_var := list(data)))
}

out <- dplyr::select(data, !!! syms(group_vars))
out <- dplyr::select(data, !!!syms(group_vars))
out <- dplyr::distinct(out)

idx <- dplyr::group_indices(data, !!! syms(group_vars))
idx <- dplyr::group_indices(data, !!!syms(group_vars))
out[[key_var]] <- unname(split(data[nest_vars], idx))[unique(idx)]

out
Expand All @@ -84,5 +84,5 @@ nest_ <- function(data, key_col, nest_cols = character()) {
nest_.data.frame <- function(data, key_col, nest_cols = character()) {
key_col <- compat_lazy(key_col, caller_env())
nest_cols <- compat_lazy_dots(nest_cols, caller_env())
nest(data, key = !! key_col, !!! nest_cols)
nest(data, key = !!key_col, !!!nest_cols)
}
4 changes: 2 additions & 2 deletions R/separate-rows.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ separate_rows.data.frame <- function(data, ..., sep = "[^[:alnum:].]+",
vars <- unname(tidyselect::vars_select(names(data), ...))

data[vars] <- map(data[vars], stringi::stri_split_regex, sep)
data <- unnest(data, !!! syms(vars))
data <- unnest(data, !!!syms(vars))

if (convert) {
data[vars] <- map(data[vars], type.convert, as.is = TRUE)
Expand All @@ -55,5 +55,5 @@ separate_rows_ <- function(data, cols, sep = "[^[:alnum:].]+",
separate_rows_.data.frame <- function(data, cols, sep = "[^[:alnum:].]+",
convert = FALSE) {
cols <- compat_lazy_dots(cols, caller_env())
separate_rows(data, !!! cols, sep = sep, convert = convert)
separate_rows(data, !!!cols, sep = sep, convert = convert)
}
44 changes: 22 additions & 22 deletions R/separate.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ separate.default <- function(data, col, into, sep = "[^[:alnum:]]+",
extra = "warn", fill = "warn", ...) {
col <- compat_as_lazy(enquo(col))
separate_(data,
col = col,
into = into,
sep = sep,
remove = remove,
convert = convert,
extra = extra,
fill = fill,
...
col = col,
into = into,
sep = sep,
remove = remove,
convert = convert,
extra = extra,
fill = fill,
...
)
}
#' @export
Expand All @@ -77,7 +77,7 @@ separate.data.frame <- function(data, col, into, sep = "[^[:alnum:]]+",
extra = "warn", fill = "warn", ...) {
orig <- data

var <- tidyselect::vars_pull(names(data), !! enquo(col))
var <- tidyselect::vars_pull(names(data), !!enquo(col))
value <- as.character(data[[var]])

if (length(list(...)) != 0) {
Expand Down Expand Up @@ -111,13 +111,13 @@ strsep <- function(x, sep) {

nchar <- stringi::stri_length(x)
pos <- map(sep, function(i) {
if (i >= 0) return(i)
nchar + i + 1
})
if (i >= 0) return(i)
nchar + i + 1
})

map(1:(length(pos) - 1), function(i) {
stringi::stri_sub(x, pos[[i]] + 1, pos[[i + 1]])
})
stringi::stri_sub(x, pos[[i]] + 1, pos[[i + 1]])
})
}
str_split_fixed <- function(value, sep, n, extra = "warn", fill = "warn") {
if (extra == "error") {
Expand Down Expand Up @@ -165,13 +165,13 @@ separate_.data.frame <- function(data, col, into, sep = "[^[:alnum:]]+",
extra = "warn", fill = "warn", ...) {
col <- compat_lazy(col, caller_env())
separate(data,
col = !! col,
into = into,
sep = sep,
remove = remove,
convert = convert,
extra = extra,
fill = fill,
...
col = !!col,
into = into,
sep = sep,
remove = remove,
convert = convert,
extra = extra,
fill = fill,
...
)
}
Loading