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

Fix some lints #1746

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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: 1 addition & 1 deletion R/attr.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ is_dictionaryish <- function(x) {
return(!is.null(x))
}

is_named(x) && !any(duplicated(names(x)))
is_named(x) && !anyDuplicated(names(x)) > 0
}


Expand Down
2 changes: 1 addition & 1 deletion R/env.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ env <- function(...) {
if (length(dots$unnamed)) {
parent <- dots$unnamed[[1]]
} else {
parent = caller_env()
parent <- caller_env()
}

env <- new.env(parent = parent)
Expand Down
4 changes: 2 additions & 2 deletions R/standalone-lazyeval.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ compat_lazy <- function(lazy, env = caller_env(), warn = TRUE) {
},
list =
if (inherits(lazy, "lazy")) {
lazy = new_quosure(lazy$expr, lazy$env)
lazy <- new_quosure(lazy$expr, lazy$env)
}
)

Expand Down Expand Up @@ -83,7 +83,7 @@ compat_lazy_dots <- function(dots, env, ..., .named = FALSE) {
}

named <- have_name(dots)
if (.named && any(!named)) {
if (.named && !all(named)) {
nms <- vapply(dots[!named], function(x) expr_text(get_expr(x)), character(1))
names(dots)[!named] <- nms
}
Expand Down
2 changes: 1 addition & 1 deletion R/standalone-purrr.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pmap <- function(.l, .f, ...) {
))
}
.rlang_purrr_args_recycle <- function(args) {
lengths <- map_int(args, length)
lengths <- lengths(args)
n <- max(lengths)

stopifnot(all(lengths == 1L | lengths == n))
Expand Down
2 changes: 1 addition & 1 deletion R/standalone-types-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ check_character <- function(x,

if (!missing(x)) {
if (is_character(x)) {
if (!allow_na && any(is.na(x))) {
if (!allow_na && anyNA(x)) {
abort(
sprintf("`%s` can't contain NA values.", arg),
arg = arg,
Expand Down
2 changes: 1 addition & 1 deletion R/standalone-vctrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ vec_cast <- function(x, to) {

lgl_cast <- function(x, to) {
lgl_cast_from_num <- function(x) {
if (any(!x %in% c(0L, 1L))) {
if (!all(x %in% c(0L, 1L))) {
stop_incompatible_cast(x, to)
}
as.logical(x)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-attr.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("names2() fails for environments", {
test_that("names2<- doesn't add missing values (#1301)", {
x <- 1:3
names2(x)[1:2] <- "foo"
expect_equal(names(x), c("foo", "foo", ""))
expect_named(x, c("foo", "foo", ""))
})

test_that("inputs must be valid", {
Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test-c-api.R
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ test_that("r_lgl_which() propagates names", {
})

test_that("r_lgl_which() handles `NA` when propagation is disabled (#750)", {
expect_identical(r_lgl_which(lgl(TRUE, FALSE, NA), FALSE), int(1))
expect_identical(r_lgl_which(lgl(TRUE, FALSE, NA), FALSE), 1L)
expect_identical(r_lgl_which(lgl(TRUE, FALSE, NA, TRUE), FALSE), int(1, 4))
expect_identical(r_lgl_which(lgl(TRUE, NA, FALSE, NA, TRUE, FALSE, TRUE), FALSE), int(1, 5, 7))
})
Expand Down Expand Up @@ -761,19 +761,19 @@ test_that("alloc_data_frame() creates data frame", {
expect_equal(nrow(df), 2)
expect_equal(ncol(df), 3)
expect_equal(class(df), "data.frame")
expect_equal(names(df), c("a", "b", "c"))
expect_named(df, c("a", "b", "c"))
expect_equal(lapply(df, typeof), list(a = "integer", b = "double", c = "character"))
expect_equal(lapply(df, length), list(a = 2, b = 2, c = 2))

df <- alloc_data_frame(0L, chr(), int())
expect_equal(nrow(df), 0)
expect_equal(ncol(df), 0)
expect_equal(names(df), chr())
expect_named(df, chr())

df <- alloc_data_frame(3L, chr(), int())
expect_equal(nrow(df), 3)
expect_equal(ncol(df), 0)
expect_equal(names(df), chr())
expect_named(df, chr())
})

test_that("r_list_compact() compacts lists", {
Expand Down Expand Up @@ -1007,10 +1007,10 @@ test_that("can get, push, and poke elements", {
arr <- new_dyn_vector("logical", 3)
dyn_push_back(arr, TRUE)
dyn_lgl_push_back(arr, TRUE)
expect_equal(dyn_lgl_get(arr, 0L), TRUE)
expect_equal(dyn_lgl_get(arr, 1L), TRUE)
expect_true(dyn_lgl_get(arr, 0L))
expect_true(dyn_lgl_get(arr, 1L))
dyn_lgl_poke(arr, 0L, FALSE)
expect_equal(dyn_lgl_get(arr, 0L), FALSE)
expect_false(dyn_lgl_get(arr, 0L))

arr <- new_dyn_vector("integer", 3)
dyn_push_back(arr, 1L)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-cnd-entrace.R
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ test_that("warnings are resignalled", {
)

expect_s3_class(cnd, "rlang_warning")
expect_true(!is_null(cnd$trace))
expect_false(is_null(cnd$trace))
})

test_that("can call `global_entrace()` in knitted documents", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-deparse.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ test_that("line_push() strips ANSI codes before computing overflow", {
if (!has_ansi()) {
skip("test needs cli")
}
expect_identical(length(line_push("foo", open_blue(), width = 3L)), 2L)
expect_identical(length(line_push("foo", open_blue(), width = 3L, has_colour = TRUE)), 1L)
expect_length(line_push("foo", open_blue(), width = 3L), 2L)
expect_length(line_push("foo", open_blue(), width = 3L, has_colour = TRUE), 1L)
})

test_that("can push several lines (useful for default base deparser)", {
Expand Down Expand Up @@ -364,7 +364,7 @@ test_that("expr_text() deparses empty arguments", {
test_that("expr_name() deparses empty arguments", {
expect_identical(expr_name(expr()), "")
expect_identical(quo_name(quo()), "")
expect_identical(names(quos_auto_name(quos(, ))), "<empty>")
expect_named(quos_auto_name(quos(, )), "<empty>")
expect_identical(as_label(expr()), "<empty>")
})

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ test_that("names are preserved", {

nms <- as.character(1:3)
x <- set_names(1:3, nms)
expect_identical(names(as_double(x)), nms)
expect_identical(names(as_list(x)), nms)
expect_named(as_double(x), nms)
expect_named(as_list(x), nms)
})

test_that("as_character() support logical NA", {
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-dots.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test_that("can take forced dots with `allowForced = FALSE`", {
test_that("captured dots are only named if names were supplied", {
fn <- function(...) captureDots()
expect_null(names(fn(1, 2)))
expect_identical(names(fn(a = 1, 2)), c("a", ""))
expect_named(fn(a = 1, 2), c("a", ""))
})

test_that("dots_values() handles forced dots", {
Expand Down Expand Up @@ -380,11 +380,11 @@ test_that("names are not mutated after splice box early exit", {
xs <- list(1)

dots_list(!!!xs, .named = FALSE)
expect_equal(names(xs), NULL)
expect_null(names(xs))

dots_list(!!!xs, .named = TRUE)
expect_equal(names(xs), NULL)
expect_null(names(xs))

dots_list(!!!xs, .named = NULL)
expect_equal(names(xs), NULL)
expect_null(names(xs))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-encoding.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ test_that("dots names are converted to and from UTF-8 (#1218)", {
names(call)[[2]] <- x
out <- eval(as.call(call))

expect_equal(names(out), x)
expect_named(out, x)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-env-binding.R
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ test_that("env_poke() doesn't warn when unrepresentable characters are serialise

test_that("new_environment() supports non-list data", {
env <- new_environment(c(a = 1))
expect_equal(typeof(env), "environment")
expect_type(env, "environment")
expect_equal(env$a, 1)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-env-special.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test_that("search_envs() includes the global and base env", {
})

test_that("search_envs() returns named environments", {
expect_identical(names(search_envs()), c("global", search()[-1]))
expect_named(search_envs(), c("global", search()[-1]))
})

test_that("search_envs() returns an rlang_envs object", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-env.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ test_that("new_environment() creates a child of the empty env", {
})

test_that("new_environment() accepts empty vectors", {
expect_identical(length(new_environment()), 0L)
expect_identical(length(new_environment(dbl())), 0L)
expect_length(new_environment(), 0L)
expect_length(new_environment(dbl()), 0L)
})

test_that("env_tail() detects sentinel", {
Expand Down Expand Up @@ -223,7 +223,7 @@ test_that("env_parents() stops at the sentinel if supplied", {

test_that("env_parents() returns a named list", {
env <- env(structure(env(base_env()), name = "foobar"))
expect_identical(names(env_parents(env)), c("foobar", "package:base", "empty"))
expect_named(env_parents(env), c("foobar", "package:base", "empty"))
})

test_that("can lock environments", {
Expand Down
34 changes: 17 additions & 17 deletions tests/testthat/test-fn.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ test_that("prim_name() extracts names", {
})

test_that("as_closure() returns closure", {
expect_identical(typeof(as_closure(base::list)), "closure")
expect_identical(typeof(as_closure("list")), "closure")
expect_type(as_closure(base::list), "closure")
expect_type(as_closure("list"), "closure")
})

test_that("as_closure() handles primitive functions", {
expect_identical(as_closure(`c`)(1, 3, 5), c(1, 3, 5))
expect_identical(as_closure(is.null)(1), FALSE)
expect_identical(as_closure(is.null)(NULL), TRUE)
expect_false(as_closure(is.null)(1))
expect_true(as_closure(is.null)(NULL))
})

test_that("as_closure() supports base-style and purrr-style arguments to binary operators", {
Expand All @@ -37,17 +37,17 @@ test_that("as_closure() supports base-style and purrr-style arguments to binary
expect_error(and(.x = TRUE, e1 = TRUE), "Can't supply both `e1` and `.x` to binary operator")
expect_error(and(TRUE, .y = TRUE, e2 = TRUE), "Can't supply both `e2` and `.y` to binary operator")

expect_identical(and(FALSE, FALSE), FALSE)
expect_identical(and(TRUE, FALSE), FALSE)
expect_identical(and(FALSE, TRUE), FALSE)
expect_identical(and(TRUE, TRUE), TRUE)
expect_false(and(FALSE, FALSE))
expect_false(and(TRUE, FALSE))
expect_false(and(FALSE, TRUE))
expect_true(and(TRUE, TRUE))

expect_identical(and(.y = FALSE, TRUE), FALSE)
expect_identical(and(e2 = FALSE, TRUE), FALSE)
expect_identical(and(.y = FALSE, e1 = TRUE), FALSE)
expect_identical(and(e2 = FALSE, .x = TRUE), FALSE)
expect_identical(and(.y = FALSE, TRUE), FALSE)
expect_identical(and(e2 = FALSE, TRUE), FALSE)
expect_false(and(.y = FALSE, TRUE))
expect_false(and(e2 = FALSE, TRUE))
expect_false(and(.y = FALSE, e1 = TRUE))
expect_false(and(e2 = FALSE, .x = TRUE))
expect_false(and(.y = FALSE, TRUE))
expect_false(and(e2 = FALSE, TRUE))
})

test_that("as_closure() supports base-style and purrr-style arguments to versatile operators", {
Expand Down Expand Up @@ -80,9 +80,9 @@ test_that("as_closure(`||`) shortcircuits", {
expect_error(or(), "Must supply `e1` or `.x` to binary operator")
expect_error(or(FALSE), "Must supply `e2` or `.y` to binary operator")

expect_identical(or(TRUE), TRUE)
expect_identical(or(.x = TRUE), TRUE)
expect_identical(or(e1 = TRUE), TRUE)
expect_true(or(TRUE))
expect_true(or(.x = TRUE))
expect_true(or(e1 = TRUE))
})

test_that("as_closure() handles operators", {
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-nse-defuse.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test_that("dot names are interpolated", {

test_that("corner cases are handled when interpolating dot names", {
var <- na_chr
expect_identical(names(quos(!!var := NULL)), "NA")
expect_named(quos(!!var := NULL), "NA")

var <- NULL
expect_snapshot({
Expand Down Expand Up @@ -139,7 +139,7 @@ test_that("can capture empty list of dots", {

test_that("quosures are spliced before serialisation", {
quosures <- quos(!! quo(foo(!! quo(bar))), .named = TRUE)
expect_identical(names(quosures), "foo(bar)")
expect_named(quosures, "foo(bar)")
})

test_that("missing arguments are captured", {
Expand Down Expand Up @@ -326,13 +326,13 @@ test_that("endots() requires symbols", {
test_that("endots() returns a named list", {
# enquos()
fn <- function(foo, bar) enquos(foo, bar)
expect_identical(names(fn()), c("", ""))
expect_named(fn(), c("", ""))
fn <- function(arg, ...) enquos(other = arg, ...)
expect_identical(fn(arg = 1, b = 2), quos(other = 1, b = 2))

# enexprs()
fn <- function(foo, bar) enexprs(foo, bar)
expect_identical(names(fn()), c("", ""))
expect_named(fn(), c("", ""))
fn <- function(arg, ...) enexprs(other = arg, ...)
expect_identical(fn(arg = 1, b = 2), exprs(other = 1, b = 2))
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-obj.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_that("poke_type() changes object type", {
out <- withVisible(poke_type(x, "language"))
expect_false(out$visible)
expect_identical(out$value, x)
expect_identical(typeof(x), "language")
expect_type(x, "language")
})

test_that("can access promise properties", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-quo.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ test_that("quo_deparse() indicates quosures with `^`", {

test_that("quosure deparser respects width", {
x <- quo(foo(quo(!!quo(bar))))
expect_identical(length(quo_deparse(x, new_quo_deparser(width = 8L))), 3L)
expect_identical(length(quo_deparse(x, new_quo_deparser(width = 9L))), 2L)
expect_length(quo_deparse(x, new_quo_deparser(width = 8L)), 3L)
expect_length(quo_deparse(x, new_quo_deparser(width = 9L)), 2L)
})

test_that("quosure predicates work", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-s3.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ test_that("can pass additional attributes to boxes", {
test_that("done() boxes values", {
expect_true(is_done_box(done(3)))
expect_identical(unbox(done(3)), 3)
expect_identical(done(3) %@% empty, FALSE)
expect_false(done(3) %@% empty)
})

test_that("done() can be empty", {
Expand All @@ -100,7 +100,7 @@ test_that("done() can be empty", {

expect_true(is_done_box(empty))
expect_s3_class(empty, "rlang_box_done")
expect_identical(empty %@% empty, TRUE)
expect_true(empty %@% empty)

expect_true(is_done_box(empty, empty = TRUE))
expect_false(is_done_box(empty, empty = FALSE))
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-standalone-vctrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,27 @@ test_that("vec_ptype_common() finalises unspecified type", {
})

test_that("safe casts work", {
expect_equal(vec_cast(NULL, logical()), NULL)
expect_equal(vec_cast(TRUE, logical()), TRUE)
expect_equal(vec_cast(1L, logical()), TRUE)
expect_equal(vec_cast(1, logical()), TRUE)
expect_null(vec_cast(NULL, logical()))
expect_true(vec_cast(TRUE, logical()))
expect_true(vec_cast(1L, logical()))
expect_true(vec_cast(1, logical()))

expect_equal(vec_cast(NULL, integer()), NULL)
expect_null(vec_cast(NULL, integer()))
expect_equal(vec_cast(TRUE, integer()), 1L)
expect_equal(vec_cast(1L, integer()), 1L)
expect_equal(vec_cast(1, integer()), 1L)

expect_equal(vec_cast(NULL, double()), NULL)
expect_null(vec_cast(NULL, double()))
expect_equal(vec_cast(TRUE, double()), 1L)
expect_equal(vec_cast(1.5, double()), 1.5)
expect_equal(vec_cast(1.5, double()), 1.5)

expect_equal(vec_cast("", chr()), "")

expect_equal(vec_cast(NULL, character()), NULL)
expect_null(vec_cast(NULL, character()))
expect_equal(vec_cast(NA, character()), NA_character_)

expect_equal(vec_cast(NULL, list()), NULL)
expect_null(vec_cast(NULL, list()))
expect_equal(vec_cast(NA, list()), list(NULL))
expect_equal(vec_cast(list(1L, 2L), list()), list(1L, 2L))
})
Expand Down
Loading
Loading