Skip to content

Commit

Permalink
style_pkg(scope = "spaces", strict = FALSE) (tidyverse#3261)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzwalthert authored and krlmlr committed Dec 30, 2017
1 parent fce6b00 commit b3837f5
Show file tree
Hide file tree
Showing 32 changed files with 168 additions and 177 deletions.
4 changes: 2 additions & 2 deletions R/compat-dbplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ wrap_dbplyr_obj <- function(obj_name) {
args <- formals()
pass_on <- map(set_names(names(args)), sym)

dbplyr_call <- expr(UQ(dbplyr_sym)(!!!pass_on))
dplyr_call <- expr(UQ(dplyr_sym)(!!!pass_on))
dbplyr_call <- expr(UQ(dbplyr_sym)(!!! pass_on))
dplyr_call <- expr(UQ(dplyr_sym)(!!! pass_on))
} else {
args <- list()

Expand Down
2 changes: 1 addition & 1 deletion R/distinct.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ distinct_vars <- function(.data, vars, group_vars = character(), .keep_all = FAL
#'
#' @noRd
list_cols_error <- function(df, keep_cols) {
if(any(map_lgl(df[keep_cols], is.list)))
if (any(map_lgl(df[keep_cols], is.list)))
stop("distinct() does not support columns of type `list`",
call. = FALSE)
}
Expand Down
2 changes: 1 addition & 1 deletion R/error.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ check_pkg <- function(name, reason, install = TRUE) {
return(invisible(TRUE))

glubort(NULL,
'The {name} package is required to {reason}.',
"The {name} package is required to {reason}.",
if (install) '\nPlease install it with `install.packages("{name}")`' else ""
)
}
Expand Down
3 changes: 1 addition & 2 deletions R/group-by.r
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#' Some tbls will accept functions of variables. Duplicated groups
#' will be silently dropped.
#' @param add When `add = FALSE`, the default, `group_by()` will
#' override existing groups. To add to the existing groups, use
#' override existing groups. To add to the existing groups, use
#' `add = TRUE`.
#' @inheritParams filter
#' @export
Expand Down Expand Up @@ -157,4 +157,3 @@ group_vars <- function(x) {
group_vars.default <- function(x) {
deparse_names(groups(x))
}

2 changes: 1 addition & 1 deletion R/grouped-df.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ grouped_df <- function(data, vars, drop = TRUE) {
}
assert_that(
is.data.frame(data),
(is.list(vars) && all(sapply(vars,is.name))) || is.character(vars),
(is.list(vars) && all(sapply(vars, is.name))) || is.character(vars),
is.flag(drop)
)
if (is.list(vars)) {
Expand Down
2 changes: 1 addition & 1 deletion R/manip.r
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ arrange_ <- function(.data, ..., .dots = list()) {
#' grouped data frames only.
arrange.grouped_df <- function(.data, ..., .by_group = FALSE) {
if (.by_group) {
dots <- quos(!!!groups(.data), ...)
dots <- quos(!!! groups(.data), ...)
} else {
dots <- quos(...)
}
Expand Down
2 changes: 1 addition & 1 deletion R/rank.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ntile <- function(x, n) {
if (len == 0L) {
rep(NA_integer_, length(x))
} else {
as.integer(floor(n * (row_number(x) - 1)/len + 1))
as.integer(floor(n * (row_number(x) - 1) / len + 1))
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/tbl-cube.r
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ as.tbl_cube.data.frame <- function(x, dim_names = NULL, met_name = guess_met(x),
dupe <- unlist(all[dupe_row, dim_names])

bad_args("x", "must be unique in all combinations of dimension variables, ",
'duplicates: {fmt_named(dupe)}'
"duplicates: {fmt_named(dupe)}"
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/utils-expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ switch_expr <- function(.x, ...) {
}

node_walk_replace <- function(node, old, new) {
while(!is_null(node)) {
while (!is_null(node)) {
switch_expr(node_car(node),
language = node_walk_replace(node_cdar(node), old, new),
symbol = if (identical(node_car(node), old)) mut_node_car(node, new)
Expand Down
1 change: 0 additions & 1 deletion R/utils.r
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,3 @@ attr_equal <- function(x, y) {

isTRUE(all.equal(attr_x, attr_y))
}

2 changes: 1 addition & 1 deletion data-raw/starwars.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ library(httr)
get_all <- function(url) {
out <- NULL

while(!is.null(url)) {
while (!is.null(url)) {
message("Getting ", url)
req <- GET(url)
stop_for_status(req)
Expand Down
3 changes: 1 addition & 2 deletions data-raw/storms.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ df_names <- c("date", "time", "record_type", "status", "lat", "long", "wind", "p
storm_dfs <- vector("list", nrow(headers_df))
names(storm_dfs) <- headers_df$name

for(i in seq_along(headers_df$name)) {
for (i in seq_along(headers_df$name)) {
storm_dfs[[i]] <- read_csv("data-raw/hurdat2.txt",
skip = headers_df$skip[i],
n_max = headers_df$n_obs[i],
Expand Down Expand Up @@ -94,4 +94,3 @@ storms <- storms %>%
mutate(name = if_else(str_sub(name, 1, 3) %in% c("AL0", "AL1"), name, str_to_title(name)))

devtools::use_data(storms)

2 changes: 1 addition & 1 deletion tests/testthat/helper-combine.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
combine_pair_test <- function(item_pair, var1, var2, result,
can_combine = TRUE, warning = FALSE) {
can_combine = TRUE, warning = FALSE) {
label_if_fail <- paste0(
"combine(items[c(\"", var1, "\", \"", var2, "\")])"
)
Expand Down
9 changes: 4 additions & 5 deletions tests/testthat/test-arrange.r
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ test_that("arrange fails gracefully on list columns (#1489)", {

test_that("arrange supports raw columns (#1803)", {
df <- data_frame(a = 1:3, b = as.raw(1:3))
expect_identical(arrange(df, a),df)
expect_identical(arrange(df, b),df)
expect_identical(arrange(df, desc(a)),df[3:1,])
expect_identical(arrange(df, desc(b)),df[3:1,])
expect_identical(arrange(df, a), df)
expect_identical(arrange(df, b), df)
expect_identical(arrange(df, desc(a)), df[3:1, ])
expect_identical(arrange(df, desc(b)), df[3:1, ])
})

test_that("arrange fails gracefully on matrix input (#1870)", {
Expand All @@ -187,4 +187,3 @@ test_that("can choose to include grouping vars", {

expect_equal(df1, df2)
})

1 change: 0 additions & 1 deletion tests/testthat/test-binds.R
Original file line number Diff line number Diff line change
Expand Up @@ -608,4 +608,3 @@ test_that("unnamed vectors fail", {
test_that("supports NULL values", {
expect_identical(bind_cols(a = 1, NULL, b = 2, NULL), tibble(a = 1, b = 2))
})

14 changes: 7 additions & 7 deletions tests/testthat/test-combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ test_that("combine works with NA and complex (#2203)", {

test_that("combine works with integer64 (#1092)", {
expect_equal(
combine(bit64::as.integer64(2^34), bit64::as.integer64(2^35)),
bit64::as.integer64(c(2^34, 2^35))
combine(bit64::as.integer64(2 ^ 34), bit64::as.integer64(2 ^ 35)),
bit64::as.integer64(c(2 ^ 34, 2 ^ 35))
)
})

Expand All @@ -188,27 +188,27 @@ test_that("combine works with difftime", {
)
expect_equal(
combine(as.difftime(1, units = "days"), as.difftime(1, units = "secs")),
as.difftime(c(24*60*60, 1), units = "secs")
as.difftime(c(24 * 60 * 60, 1), units = "secs")
)
expect_equal(
combine(as.difftime(2, units = "weeks"), as.difftime(1, units = "secs")),
as.difftime(c(2*7*24*60*60, 1), units = "secs")
as.difftime(c(2 * 7 * 24 * 60 * 60, 1), units = "secs")
)
expect_equal(
combine(as.difftime(2, units = "weeks"), as.difftime(3, units = "weeks")),
as.difftime(c(2,3), units = "weeks")
as.difftime(c(2, 3), units = "weeks")
)

})

test_that("combine works with hms and difftime", {
expect_equal(
combine(as.difftime(2, units = "weeks"), hms::hms(hours = 1)),
as.difftime(c(2*7*24*60*60, 3600), units = "secs")
as.difftime(c(2 * 7 * 24 * 60 * 60, 3600), units = "secs")
)
expect_equal(
combine(hms::hms(hours = 1), as.difftime(2, units = "weeks")),
hms::hms(seconds = c(3600, 2*7*24*60*60))
hms::hms(seconds = c(3600, 2 * 7 * 24 * 60 * 60))
)

})
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-copy_to.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ test_that("src_sqlite() errs if path does not exist", {
fixed = TRUE
)
})

1 change: 0 additions & 1 deletion tests/testthat/test-count-tally.r
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,3 @@ test_that("add_tally can be given a weighting variable", {
out <- df %>% group_by(a) %>% add_tally(wt = w + 1)
expect_equal(out$n, c(4, 4, 12, 12, 12))
})

4 changes: 2 additions & 2 deletions tests/testthat/test-distinct.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ test_that("distinct on a new, mutated variable is equivalent to mutate followed
})

test_that("distinct on a dataframe or tibble with columns of type list throws an error", {
df <- tibble(a = c("1", "1", "2", "2", "3","3"),
df <- tibble(a = c("1", "1", "2", "2", "3", "3"),
b = c(list("A"), list("A"), list("B"), list("B"), list("C"), list("C")))
df2 <- data.frame(x = 1:5, y=I(list(1:3, 1:3, 1:3, 1:3, 1:3)))
df2 <- data.frame(x = 1:5, y = I(list(1:3, 1:3, 1:3, 1:3, 1:3)))

expect_error(df %>% distinct())
expect_error(df2 %>% distinct())
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-equality.r
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ test_that("equality handles data frames with 0 columns (#1506)", {

test_that("equality handle raw columns", {
df <- data_frame(a = 1:3, b = as.raw(1:3))
expect_true( all.equal(df, df) )
expect_true(all.equal(df, df))
})

test_that("equality returns a message for convert = TRUE", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-filter.r
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ test_that("hybrid lag and default value for string columns work (#1403)", {

test_that("filter handles raw vectors (#1803)", {
df <- data_frame(a = 1:3, b = as.raw(1:3))
expect_identical( filter(df, a == 1), data_frame( a = 1L, b = as.raw(1)) )
expect_identical( filter(df, b == 1), data_frame( a = 1L, b = as.raw(1)) )
expect_identical(filter(df, a == 1), data_frame(a = 1L, b = as.raw(1)))
expect_identical(filter(df, b == 1), data_frame(a = 1L, b = as.raw(1)))
})

test_that("`vars` attribute is not added if empty (#2772)", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-group-by.r
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ test_that(paste0("group_by handles encodings for native strings (#1507)"), {

test_that("group_by handles raw columns (#1803)", {
df <- data_frame(a = 1:3, b = as.raw(1:3))
expect_identical( ungroup(group_by(df, a)), df )
expect_identical( ungroup(group_by(df, b)), df )
expect_identical(ungroup(group_by(df, a)), df)
expect_identical(ungroup(group_by(df, b)), df)
})

test_that("rowwise handles raw columns (#1803)", {
df <- data_frame(a = 1:3, b = as.raw(1:3))
expect_is( rowwise(df), "rowwise_df" )
expect_is(rowwise(df), "rowwise_df")
})

test_that("group_by() names pronouns correctly (#2686)", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-hybrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ context("hybrid")
test_that("hybrid evaluation environment is cleaned up (#2358)", {
# Can't use pipe here, f and g should have top-level parent.env()
df <- data_frame(x = 1)
df <- mutate(df, f = list(function(){}))
df <- mutate(df, f = list(function() {}))
df <- mutate(df, g = list(quo(.)))
df <- mutate(df, h = list(~.))

Expand Down
22 changes: 11 additions & 11 deletions tests/testthat/test-joins.r
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ test_that("join handles mix of encodings in data (#1885, #2118, #2271)", {
expect_warning_msg(
expect_equal_df(
anti_join(df1, df2, by = "x"),
data.frame(x = special, y = 1, stringsAsFactors = factor1)[0,]
data.frame(x = special, y = 1, stringsAsFactors = factor1)[0, ]
)
)
}
Expand Down Expand Up @@ -899,27 +899,27 @@ test_that("semi- and anti-joins preserve order (#2964)", {
)
})

test_that( "join handles raw vectors", {
df1 <- data_frame( r = as.raw(1:4), x = 1:4 )
df2 <- data_frame( r = as.raw(3:6), y = 3:6 )
test_that("join handles raw vectors", {
df1 <- data_frame(r = as.raw(1:4), x = 1:4)
df2 <- data_frame(r = as.raw(3:6), y = 3:6)

expect_identical(
left_join( df1, df2, by = "r" ),
data_frame(r = as.raw(1:4), x = 1:4, y = c(NA,NA,3:4))
left_join(df1, df2, by = "r"),
data_frame(r = as.raw(1:4), x = 1:4, y = c(NA, NA, 3:4))
)

expect_identical(
right_join( df1, df2, by = "r" ),
data_frame(r = as.raw(3:6), x = c(3:4,NA,NA), y = c(3:6))
right_join(df1, df2, by = "r"),
data_frame(r = as.raw(3:6), x = c(3:4, NA, NA), y = c(3:6))
)

expect_identical(
full_join( df1, df2, by = "r" ),
data_frame(r = as.raw(1:6), x = c(1:4,NA,NA), y = c(NA,NA,3:6))
full_join(df1, df2, by = "r"),
data_frame(r = as.raw(1:6), x = c(1:4, NA, NA), y = c(NA, NA, 3:6))
)

expect_identical(
inner_join( df1, df2, by = "r" ),
inner_join(df1, df2, by = "r"),
data_frame(r = as.raw(3:4), x = c(3:4), y = c(3:4))
)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-mutate-windowed.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ test_that("lag and lead work on factors inside mutate (#955)", {
is_diff_lag = (test != lag(test)),
is_diff_lead = (test != lead(test))
)
expect_equal(exp_lag , res$is_diff_lag)
expect_equal(exp_lag, res$is_diff_lag)
expect_equal(exp_lead, res$is_diff_lead)

})
Expand Down
Loading

0 comments on commit b3837f5

Please sign in to comment.