Skip to content

Commit

Permalink
Don't import glue
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Aug 6, 2024
1 parent 43c9113 commit 0125417
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ S3method(print,waldo_compare)
export(compare)
export(compare_proxy)
import(rlang)
importFrom(glue,glue)
importFrom(methods,.hasSlot)
importFrom(methods,is)
importFrom(methods,slot)
Expand Down
2 changes: 1 addition & 1 deletion R/compare-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ print.waldo_compare <- function(x, n = attr(x, "max_diffs"), ...) {
cli::cat_bullet("No differences", bullet = "tick", bullet_col = "green")
} else {
if (length(x) > n) {
x <- c(x[seq_len(n)], glue("And {length(x) - floor(n)} more differences ..."))
x <- c(x[seq_len(n)], glue::glue("And {length(x) - floor(n)} more differences ..."))
}

cat(paste0(x, collapse = "\n\n"), "\n", sep = "")
Expand Down
22 changes: 11 additions & 11 deletions R/compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ compare_structure <- function(x, y, paths = c("x", "y"), opts = compare_opts())

# Then attributes/slots
if (isS4(x)) {
out <- c(out, compare_character(is(x), is(y), glue("is({paths})")))
out <- c(out, compare_character(is(x), is(y), glue::glue("is({paths})")))
out <- c(out, compare_by_slot(x, y, paths, opts))

# S4 objects can have attributes that are not slots
Expand Down Expand Up @@ -298,7 +298,7 @@ compare_structure <- function(x, y, paths = c("x", "y"), opts = compare_opts())
} else if (is_atomic(x)) {
if (is_character(x) && !opts$ignore_encoding) {
out <- c(out, compare_character(
Encoding(x), Encoding(y), glue("Encoding({paths})"),
Encoding(x), Encoding(y), glue::glue("Encoding({paths})"),
max_diffs = opts$max_diffs
))
}
Expand All @@ -317,7 +317,7 @@ compare_structure <- function(x, y, paths = c("x", "y"), opts = compare_opts())
# in behaviour (they're usually captured incidentally) so we just
# ignore
} else if (!typeof(x) %in% c("S4", "object")) {
abort(glue("{paths[[1]]}: unsupported type '{typeof(x)}'"), call = NULL)
abort(glue::glue("{paths[[1]]}: unsupported type '{typeof(x)}'"), call = NULL)

Check warning on line 320 in R/compare.R

View check run for this annotation

Codecov / codecov/patch

R/compare.R#L320

Added line #L320 was not covered by tests
}

out
Expand Down Expand Up @@ -398,7 +398,7 @@ should_be <- function(x, y) {
"`{paths[[1]]}` is ", x, "\n",
"`{paths[[2]]}` is ", y
)
glue(string, .envir = caller_env(), .trim = FALSE)
glue::glue(string, .envir = caller_env(), .trim = FALSE)
}

# compare_each ------------------------------------------------------------
Expand Down Expand Up @@ -428,36 +428,36 @@ compare_by <- function(index_fun, extract_fun, path_fun) {

index_name <- function(x, y) union(names(x), names(y))
extract_name <- function(x, i) if (has_name(x, i)) .subset2(x, i) else missing_arg()
path_name <- function(path, i) glue("{path}${i}")
path_name <- function(path, i) glue::glue("{path}${i}")
compare_by_name <- compare_by(index_name, extract_name, path_name)

index_pos <- function(x, y) seq_len(max(length(x), length(y)))
extract_pos <- function(x, i) if (i <= length(x)) .subset2(x, i) else missing_arg()
path_pos <- function(path, i) glue("{path}[[{i}]]")
path_pos <- function(path, i) glue::glue("{path}[[{i}]]")
compare_by_pos <- compare_by(index_pos, extract_pos, path_pos)

path_line <- function(path, i) glue("lines({path}[[{i}]])")
path_line <- function(path, i) glue::glue("lines({path}[[{i}]])")
compare_by_line <- compare_by(index_pos, extract_pos, path_line)

path_line1 <- function(path, i) glue("lines({path})")
path_line1 <- function(path, i) glue::glue("lines({path})")
compare_by_line1 <- compare_by(index_pos, extract_pos, path_line1)

path_attr <- function(path, i) {
# from ?attributes, excluding row.names() because it's not a simple accessor
funs <- c("comment", "class", "dim", "dimnames", "levels", "names", "tsp")
ifelse(i %in% funs, glue("{i}({path})"), glue("attr({path}, '{i}')"))
ifelse(i %in% funs, glue::glue("{i}({path})"), glue::glue("attr({path}, '{i}')"))
}
compare_by_attr <- compare_by(index_name, extract_name, path_attr)

#' @importFrom methods slotNames .hasSlot slot is
index_slot <- function(x, y) union(slotNames(x), slotNames(y))
extract_slot <- function(x, i) if (.hasSlot(x, i)) slot(x, i) else missing_arg()
path_slot <- function(path, i) glue("{path}@{i}")
path_slot <- function(path, i) glue::glue("{path}@{i}")
compare_by_slot <- compare_by(index_slot, extract_slot, path_slot)

extract_fun <- function(x, i) switch(i, fn_body(x), fn_fmls(x), fn_env(x))
path_fun <- function(path, i) {
fun <- unname(c("body", "formals", "environment")[i])
glue("{fun}({path})")
glue::glue("{fun}({path})")
}
compare_by_fun <- compare_by(function(x, y) 1:3, extract_fun, path_fun)
1 change: 0 additions & 1 deletion R/waldo-package.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#' @keywords internal
#' @import rlang
#' @importFrom glue glue
"_PACKAGE"

# The following block is used by usethis to automatically manage
Expand Down

0 comments on commit 0125417

Please sign in to comment.