8000 Fix some lints by etiennebacher · Pull Request #1325 · ropensci/targets · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix some lints #1325

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 3 commits into from
Aug 29, 2024
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
8000
Diff view
2 changes: 1 addition & 1 deletion R/class_aws.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ store_class_repository.aws <- function(repository, store, format) {
sprintf("tar_aws_%s", format),
"tar_aws",
"tar_cloud",
if_any("tar_external" %in% class(store), character(0), "tar_external"),
if_any(inherits(store, "tar_external"), character(0), "tar_external"),
class(store)
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/class_gcp.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ store_class_repository.gcp <- function(repository, store, format) {
sprintf("tar_gcp_%s", format),
"tar_gcp",
"tar_cloud",
if_any("tar_external" %in% class(store), character(0), "tar_external"),
if_any(inherits(store, "tar_external"), character(0), "tar_external"),
class(store)
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/utils_assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ tar_assert_df <- function(x, msg = NULL) {
#' @export
#' @rdname tar_assert
tar_assert_equal_lengths <- function(x, msg = NULL) {
lengths <- map_int(x, length)
lengths <- lengths(x)
if (length(unique(lengths)) > 1L) {
targets::tar_throw_validate(msg %|||% "x must have equal-length elements.")
}
Expand Down
2 changes: 1 addition & 1 deletion R/utils_imports.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ graph_edges <- function(edges) {
edges_envir <- function(envir) {
names <- fltr(names(envir), ~!is_internal_name(.x, envir))
from <- lapply(names, envir_deps, envir = envir, names = names)
lengths <- map_int(from, length)
lengths <- lengths(from)
to <- lapply(seq_along(names), rep_to, names = names, lengths = lengths)
from <- as.character(unlist(from))
to <- as.character(unlist(to))
Expand Down
20 changes: 10 additions & 10 deletions tests/aws/test-class_aws_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ tar_test("aws file gets stored", {
expect_false(file.exists("example_aws_file.txt"))
unlink("_targets/scratch", recursive = TRUE)
expect_equal(tar_read(y), "x_lines")
expect_equal(length(list.files("_targets/scratch/")), 0L)
expect_length(list.files("_targets/scratch/"), 0L)
expect_false(file.exists("_targets/scratch/x"))
expect_false(file.exists("example_aws_file.txt"))
path <- tar_read(x)
expect_equal(length(list.files("_targets/scratch/")), 0L)
expect_length(list.files("_targets/scratch/"), 0L)
expect_false(file.exists("_targets/scratch/x"))
expect_true(file.exists("example_aws_file.txt"))
expect_equal(readLines("example_aws_file.txt"), "x_lines")
Expand Down Expand Up @@ -96,11 +96,11 @@ tar_test("aws file gets stored with transient memory", {
expect_false(file.exists("example_aws_file.txt"))
unlink("_targets/scratch", recursive = TRUE)
expect_equal(tar_read(y), "x_lines")
expect_equal(length(list.files("_targets/scratch/")), 0L)
expect_length(list.files("_targets/scratch/"), 0L)
expect_false(file.exists("_targets/scratch/x"))
expect_false(file.exists("example_aws_file.txt"))
path <- tar_read(x)
expect_equal(length(list.files("_targets/scratch/")), 0L)
expect_length(list.files("_targets/scratch/"), 0L)
expect_false(file.exists("_targets/scratch/x"))
expect_true(file.exists("example_aws_file.txt"))
expect_equal(readLines("example_aws_file.txt"), "x_lines")
Expand Down Expand Up @@ -231,10 +231,10 @@ tar_test("aws_file format with a custom data store", {
)
)
expect_equal(tar_read(y), "x_lines")
expect_equal(length(list.files("custom_targets_store/scratch/")), 0L)
expect_length(list.files("custom_targets_store/scratch/"), 0L)
expect_false(file.exists("example_aws_file.txt"))
path <- tar_read(x)
expect_equal(length(list.files("custom_targets_store/scratch/")), 0L)
expect_length(list.files("custom_targets_store/scratch/"), 0L)
expect_true(file.exists("example_aws_file.txt"))
expect_equal(readLines("example_aws_file.txt"), "x_lines")
tmp <- tempfile()
Expand Down Expand Up @@ -300,11 +300,11 @@ tar_test("aws_file format file with different region", {
)
unlink("_targets/scratch", recursive = TRUE)
expect_equal(tar_read(y), "x_lines")
expect_equal(length(list.files("_targets/scratch/")), 0L)
expect_length(list.files("_targets/scratch/"), 0L)
expect_false(file.exists("_targets/scratch/x"))
expect_false(file.exists("example_aws_file.txt"))
path <- tar_read(x)
expect_equal(length(list.files("_targets/scratch/")), 0L)
expect_length(list.files("_targets/scratch/"), 0L)
expect_false(file.exists("_targets/scratch/x"))
expect_true(file.exists("example_aws_file.txt"))
expect_equal(readLines("example_aws_file.txt"), "x_lines")
Expand Down Expand Up @@ -371,11 +371,11 @@ tar_test("file_fast gets converted to file", {
expect_false(file.exists("example_aws_file.txt"))
unlink("_targets/scratch", recursive = TRUE)
expect_equal(tar_read(y), "x_lines")
expect_equal(length(list.files("_targets/scratch/")), 0L)
expect_length(list.files("_targets/scratch/"), 0L)
expect_false(file.exists("_targets/scratch/x"))
expect_false(file.exists("example_aws_file.txt"))
path <- tar_read(x)
expect_equal(length(list.files("_targets/scratch/")), 0L)
expect_length(list.files("_targets/scratch/"), 0L)
expect_false(file.exists("_targets/scratch/x"))
expect_true(file.exists("example_aws_file.txt"))
expect_equal(readLines("example_aws_file.txt"), "x_lines")
Expand Down
2 changes: 1 addition & 1 deletion tests/aws/test-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tar_test("migrate meta database", {
data <- as_data_frame(meta$database$read_condensed_data())
expect_false(is.null(data$repository))
data$repository <- NULL
expect_true(is.null(data$repository))
expect_null(data$repository)
data$format[!is.na(data$format)] <- "aws_parquet"
meta$database$overwrite_storage(data)
expect_equal(tar_outdated(callr_function = NULL), character(0))
Expand Down
6 changes: 3 additions & 3 deletions tests/aws/test-utils_aws.R
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,12 @@ tar_test("aws_s3_list_etags()", {
out <- aws_s3_list_etags(prefix = "", bucket = bucket)
out2 <- aws_s3_list_etags(prefix = "", bucket = bucket, page_size = 2L)
expect_equal(out, out2)
expect_equal(length(out), 4L)
expect_length(out, 4L)
expect_equal(sort(names(out)), sort(c("w", "x", "y", "z")))
for (etag in out) {
expect_true(is.character(etag))
expect_true(!anyNA(etag))
expect_equal(length(etag), 1L)
expect_false(anyNA(etag))
expect_length(etag, 1L)
expect_gt(nchar(etag), 10L)
}
})
8 changes: 4 additions & 4 deletions tests/gcp/test-class_gcp_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ tar_test("gcp_file format file gets stored", {
)
unlink("_targets/scratch", recursive = TRUE)
expect_equal(tar_read(y), "x_lines")
expect_equal(length(list.files("_targets/scratch/")), 0L)
expect_length(list.files("_targets/scratch/"), 0L)
expect_false(file.exists("_targets/scratch/x"))
expect_false(file.exists("example_gcp_file.txt"))
path <- tar_read(x)
expect_equal(length(list.files("_targets/scratch/")), 0L)
expect_length(list.files("_targets/scratch/"), 0L)
expect_false(file.exists("_targets/scratch/x"))
expect_true(file.exists("example_gcp_file.txt"))
expect_equal(readLines("example_gcp_file.txt"), "x_lines")
Expand Down Expand Up @@ -179,10 +179,10 @@ tar_test("gcp_file format with a custom data store", {
)
)
expect_equal(tar_read(y), "x_lines")
expect_equal(length(list.files("custom_targets_store/scratch/")), 0L)
expect_length(list.files("custom_targets_store/scratch/"), 0L)
expect_false(file.exists("example_gcp_file.txt"))
path <- tar_read(x)
expect_equal(length(list.files("custom_targets_store/scratch/")), 0L)
expect_length(list.files("custom_targets_store/scratch/"), 0L)
expect_true(file.exists("example_gcp_file.txt"))
expect_equal(readLines("example_gcp_file.txt"), "x_lines")
tmp <- tempfile()
Expand Down
6 changes: 3 additions & 3 deletions tests/gcp/test-utils_gcp.R
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ tar_test("gcp_gcs_list_md5s()", {
)
}
out <- gcp_gcs_list_md5s(prefix = "", bucket = bucket)
expect_equal(length(out), 4L)
expect_length(out, 4L)
expect_equal(sort(names(out)), sort(c("w", "x", "y", "z")))
for (etag in out) {
expect_true(is.character(etag))
expect_true(!anyNA(etag))
expect_equal(length(etag), 1L)
expect_false(anyNA(etag))
expect_length(etag, 1L)
expect_gt(nchar(etag), 10L)
}
})
2 changes: 1 addition & 1 deletion tests/interactive/test-class_url.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tar_test("tar_timestamp() for URLs", {
tar_make(callr_function = NULL)
# correctly parsed posix object
out <- tar_timestamp(abc)
expect_equal(length(out), 1L)
expect_length(out, 1L)
expect_true(inherits(out, "POSIXct"))
expect_false(anyNA(out))
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-class_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tar_test("keep track of seconds", {
build <- build_init(quote(1L + 1L), baseenv())
out <- build$metrics$seconds
expect_true(is.numeric(out))
expect_equal(length(out), 1L)
expect_length(out, 1L)
})

tar_test("run without error", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-class_command.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tar_test("command$hash", {
command <- command_init(quote(a <- b + c))
out <- command$hash
expect_true(is.character(out))
expect_equal(length(out), 1L)
expect_length(out, 1L)
expect_equal(nchar(out), 16L)
})

Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test-class_database.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ tar_test("database$get_data() with list columns", {
out <- algorithm$meta$database$get_data()
expect_true(is.list(out$path))
expect_true(is.list(out$children))
expect_equal(
length(out$children[[which(out$name == "map1")]][[1L]]),
3L
)
expect_length(out$children[[which(out$name == "map1")]][[1L]], 3L)
expect_false(anyNA(out$name))
expect_true(all(nzchar(out$name)))
expect_equal(as.integer(anyDuplicated(out$name)), 0L)
Expand Down
24 changes: 12 additions & 12 deletions tests/testthat/test-class_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ tar_test("file_update_hash()", {
expect_equal(nchar(file$size), 16L)
expect_true(is.numeric(file$bytes))
expect_true(is.finite(file$bytes))
expect_equal(length(file$bytes), 1L)
expect_equal(length(file$time), 1L)
expect_equal(length(file$time), 1L)
expect_length(file$bytes, 1L)
expect_length(file$time, 1L)
expect_length(file$time, 1L)
})

tar_test("file_update_info()", {
Expand All @@ -135,9 +135,9 @@ tar_test("file_update_info()", {
expect_equal(nchar(file$size), 16L)
expect_true(is.numeric(file$bytes))
expect_true(is.finite(file$bytes))
expect_equal(length(file$bytes), 1L)
expect_equal(length(file$time), 1L)
expect_equal(length(file$time), 1L)
expect_length(file$bytes, 1L)
expect_length(file$time, 1L)
expect_length(file$time, 1L)
})

tar_test("file_update_hash() where two files exist", {
Expand All @@ -159,9 +159,9 @@ tar_test("file_update_hash() where two files exist", {
expect_true(is.character(file$size))
expect_equal(nchar(file$size), 16L)
expect_true(is.finite(file$bytes))
expect_equal(length(file$bytes), 1L)
expect_equal(length(file$time), 1L)
expect_equal(length(file$size), 1L)
expect_length(file$bytes, 1L)
expect_length(file$time, 1L)
expect_length(file$size, 1L)
})

tar_test("file_update_hash() where one file does not exist", {
Expand All @@ -182,9 +182,9 @@ tar_test("file_update_hash() where one file does not exist", {
expect_true(is.character(file$size))
expect_equal(nchar(file$size), 16L)
expect_true(is.finite(file$bytes))
expect_equal(length(file$bytes), 1L)
expect_equal(length(file$time), 1L)
expect_equal(length(file$size), 1L)
expect_length(file$bytes, 1L)
expect_length(file$time, 1L)
expect_length(file$size, 1L)
})

tar_test("file_update_hash() where neither file exists", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-class_frames.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ tar_test("frames_clear_objects()", {
out$targets$names,
character(0)
)
expect_equal(names(out$targets$envir), character(0))
expect_named(out$targets$envir, character(0))
expect_identical(
parent.env(out$targets$envir),
out$imports$envir
Expand All @@ -94,7 +94,7 @@ tar_test("target_frames_deps()", {
saveRDS("value", tmp)
file <- x$store$file$path <- tmp
file <- y$store$file$path <- tmp
expect_equal(names(frames_get_envir(frames)), character(0))
expect_named(frames_get_envir(frames), character(0))
x <- pipeline_get_target(pipeline, "abc")
y <- pipeline_get_target(pipeline, "def")
x$value <- value_init(object = "x")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-class_glimpse.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tar_test("glimpse$targets_only", {
skip_if_not_installed("visNetwork")
net <- glimpse_init(pipeline_init(), targets_only = FALSE)
expect_equal(net$targets_only, FALSE)
expect_false(net$targets_only)
net <- glimpse_init(pipeline_init(), targets_only = TRUE)
expect_equal(net$targets_only, TRUE)
expect_true(net$targets_only)
})

tar_test("glimpse$allow", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-class_group.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ tar_test("group branch invalidation (#507)", {
tar_make(callr_function = NULL)
out <- tar_progress()
out <- out$name[out$progress == "completed" & grepl("^y_", out$name)]
expect_equal(length(out), 1L)
expect_length(out, 1L)
})

tar_test("group validate() on a non data frame", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-class_imports.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tar_test("imports_init() idempotence", {
tar_option_set(imports = c("utils", "secretbase"))
imports <- imports_init(imports_new(new.env(parent = emptyenv())))
expect_true(inherits(imports, "tar_imports"))
expect_equal(length(imports), 0L)
expect_length(imports, 0L)
expect_null(imports$head)
})

Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-class_inspection.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tar_test("inspection$targets_only", {
skip_if_not_installed("visNetwork")
net <- inspection_init(pipeline_init(), targets_only = FALSE)
expect_equal(net$targets_only, FALSE)
expect_false(net$targets_only)
net <- inspection_init(pipeline_init(), targets_only = TRUE)
expect_equal(net$targets_only, TRUE)
expect_true(net$targets_only)
})

tar_test("inspection$allow", {
Expand Down Expand Up @@ -37,7 +37,7 @@ tar_test("inspection$progress", {

tar_test("inspection$outdated", {
out <- inspection_init(pipeline_init(), outdated = FALSE)
expect_equal(out$outdated, FALSE)
expect_false(out$outdated)
})

tar_test("vertices and edges of empty imports", {
Expand Down Expand Up @@ -155,8 +155,8 @@ tar_test("same for targets", {
rownames(vertices) <- NULL
rownames(exp) <- NULL
expect_equal(vertices[, colnames(exp)], exp)
expect_false(any(is.na(vertices$seconds)))
expect_false(any(is.na(vertices$bytes)))
expect_false(anyNA(vertices$seconds))
expect_false(anyNA(vertices$bytes))
expect_true(is.numeric(vertices$seconds))
expect_true(is.numeric(vertices$bytes))
expect_true(all(vertices$seconds >= 0))
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-class_memory.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ tar_test("memory_del_objects()", {
expect_equal(sort(out$names), sort(c("a", "b", "c")))
expect_equal(out$count, 3L)
memory_del_objects(out, c("a", "c"))
expect_equal(out$envir$a, NULL)
expect_null(out$envir$a)
expect_equal(out$envir$b, "456")
expect_equal(out$envir$c, NULL)
expect_null(out$envir$c)
expect_equal(out$names, "b")
expect_equal(out$count, 1L)
})
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-class_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ tar_test("meta$produce_depend() empty", {
local$run()
meta <- local$meta
out <- meta$produce_depend(x)
expect_equal(length(out), 1L)
expect_length(out, 1L)
expect_equal(nchar(out), 16L)
})

Expand All @@ -218,7 +218,7 @@ tar_test("meta$produce_depend() nonempty", {
local$run()
meta <- local$meta
out <- meta$produce_depend(y, pipeline)
expect_equal(length(out), 1L)
expect_length(out, 1L)
expect_equal(nchar(out), 16L)
})

Expand All @@ -241,7 +241,7 @@ tar_test("data hash of pattern updates", {
data <- meta_init()$database$read_data()
expect_true("map" %in% data$name)
hash <- data$data[data$name == "map"]
expect_equal(length(hash), 1L)
expect_length(hash, 1L)
expect_false(is.na(hash))
expect_false(hash == hash_null)
pipeline <- pipeline_init(
Expand Down Expand Up @@ -294,7 +294,7 @@ tar_test("migrate meta database", {
data <- as_data_frame(meta$database$read_condensed_data())
expect_false(is.null(data$repository))
data$repository <- NULL
expect_true(is.null(data$repository))
expect_null(data$repository)
meta$database$overwrite_storage(data)
expect_equal(tar_outdated(callr_function = NULL), character(0))
expect_equal(tar_read(x), "value")
Expand Down
Loading
Loading
0