Skip to content

Commit

Permalink
Remove or clean up dead code (#6325)
Browse files Browse the repository at this point in the history
* Move `random_table_name()` to the only place it is used

* Inline `in_travis()` into the deprecated function it is used in

* Remove `named()`

* Inline `fmt_dims()` into the one place it is used

I don't see this being generally useful

* Move `wrap()` close to the deprecated function it is used in

* Remove additional completely dead code
  • Loading branch information
DavisVaughan authored Jul 11, 2022
1 parent 36ef054 commit 971b73f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 82 deletions.
4 changes: 4 additions & 0 deletions R/dbplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ sql_subquery <- function(con, from, name = random_table_name(), ...) {
UseMethod("sql_subquery")
}

random_table_name <- function(n = 10) {
paste0(sample(letters, n, replace = TRUE), collapse = "")
}

#' @rdname backend_dbplyr
#' @export
sql_join <- function(con, x, y, vars, type = "inner", by = NULL, ...) {
Expand Down
4 changes: 3 additions & 1 deletion R/deprec-dbi.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ src_postgres <- function(dbname = NULL, host = NULL, port = NULL,
details = "Please use `tbl()` directly with a database connection"
)

user <- user %||% if (in_travis()) "postgres" else ""
in_travis <- identical(Sys.getenv("TRAVIS"), "true")

user <- user %||% if (in_travis) "postgres" else ""

con <- DBI::dbConnect(
RPostgreSQL::PostgreSQL(),
Expand Down
12 changes: 12 additions & 0 deletions R/deprec-src-local.r
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,15 @@ format.src_local <- function(x, ...) {
wrap("tbls: ", paste0(sort(src_tbls(x)), collapse = ", "))
)
}

wrap <- function(..., indent = 0) {
x <- paste0(..., collapse = "")
wrapped <- strwrap(
x,
indent = indent,
exdent = indent + 2,
width = getOption("width")
)

paste0(wrapped, collapse = "\n")
}
22 changes: 0 additions & 22 deletions R/error.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ fmt_pos_args <- function(x) {
glue("{args} {fmt_comma(x)}")
}

fmt_calls <- function(...) {
x <- parse_named_call(...)
fmt_obj(x)
}

fmt_cols <- function(x) {
cols <- ntext(length(x), "Column", "Columns")
glue("{cols} {fmt_obj(x)}")
Expand All @@ -30,10 +25,6 @@ fmt_classes <- function(x) {
paste(class(x), collapse = "/")
}

fmt_dims <- function(x) {
paste0("[", paste0(x, collapse = " x "), "]")
}

fmt_comma <- function(..., .max = 6) {
x <- paste0(...)
if (length(x) > .max) {
Expand All @@ -44,19 +35,6 @@ fmt_comma <- function(..., .max = 6) {
commas(x)
}

parse_args <- function(x) {
# convert single formula to list of length 1
x <- unlist(list(x), recursive = FALSE)
is_fml <- map_lgl(x, is_formula)
x[is_fml] <- map_chr(map(x[is_fml], "[[", 2), as_string)
unlist(x)
}

parse_named_call <- function(x) {
map_chr(x, quo_text)
}


# From rlang
friendly_type_of <- function(x) {
if (is.object(x)) {
Expand Down
47 changes: 3 additions & 44 deletions R/utils-format.r
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,16 @@ dim_desc <- function(x) {
d2 <- big_mark(d)
d2[is.na(d)] <- "??"

fmt_dims(d2)
paste0("[", paste0(d2, collapse = " x "), "]")
}

wrap <- function(..., indent = 0) {
x <- paste0(..., collapse = "")
wrapped <- strwrap(
x,
indent = indent,
exdent = indent + 2,
width = getOption("width")
)

paste0(wrapped, collapse = "\n")
}

ruler <- function(width = getOption("width")) {
x <- seq_len(width)
y <- case_when(
x %% 10 == 0 ~ as.character((x %/% 10) %% 10),
x %% 5 == 0 ~ "+",
.default = "-"
)
cat(y, "\n", sep = "")
cat(x %% 10, "\n", sep = "")
}

rule <- function(pad = "-", gap = 2L) {
paste0(rep(pad, getOption("width") - gap), collapse = "")
}

named_rule <- function(..., pad = "-") {
if (nargs() == 0) {
title <- ""
} else {
title <- paste0(...)
}
paste0(title, " ", rule(pad = pad, gap = nchar(title) - 1))
}


# function for the thousand separator,
# returns "," unless it's used for the decimal point, in which case returns "."
big_mark <- function(x, ...) {
mark <- if (identical(getOption("OutDec"), ",")) "." else ","
formatC(x, big.mark = mark, ...)
}

paste_line <- function(..., .trailing = FALSE) {
lines <- paste(chr(...), collapse = "\n")
if (.trailing) {
lines <- paste0(lines, "\n")
}
lines
rule <- function(pad = "-", gap = 2L) {
paste0(rep(pad, getOption("width") - gap), collapse = "")
}
15 changes: 0 additions & 15 deletions R/utils.r
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,11 @@ deparse_trunc <- function(x, width = getOption("width")) {

commas <- function(...) paste0(..., collapse = ", ")

in_travis <- function() identical(Sys.getenv("TRAVIS"), "true")

named <- function(...) {
x <- c(...)

missing_names <- names2(x) == ""
names(x)[missing_names] <- x[missing_names]

x
}

is_1d <- function(x) {
# dimension check is for matrices and data.frames
(is_atomic(x) || is.list(x)) && length(dim(x)) <= 1
}

random_table_name <- function(n = 10) {
paste0(sample(letters, n, replace = TRUE), collapse = "")
}

unstructure <- function(x) {
attributes(x) <- NULL
x
Expand Down

0 comments on commit 971b73f

Please sign in to comment.