Skip to content

Commit

Permalink
Bring @import's and @importFrom's more in line with current conventions
Browse files Browse the repository at this point in the history
Importing all these color functions from crayon is a bit meh, but I assume the UI will get modernized at some point, so I'm letting it ride.
  • Loading branch information
jennybc committed Mar 11, 2023
1 parent 2d4403a commit 7ff9811
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 37 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ export(vroom_progress)
export(vroom_str)
export(vroom_write)
export(vroom_write_lines)
import(rlang)
importFrom(bit64,integer64)
importFrom(crayon,blue)
importFrom(crayon,bold)
importFrom(crayon,col_nchar)
importFrom(crayon,cyan)
importFrom(crayon,green)
importFrom(crayon,reset)
importFrom(crayon,silver)
importFrom(glue,double_quote)
importFrom(glue,glue)
importFrom(lifecycle,deprecate_warn)
importFrom(lifecycle,deprecated)
importFrom(methods,setOldClass)
Expand Down
26 changes: 12 additions & 14 deletions R/col_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#' t3$cols <- c(t1$cols, t2$cols)
#' t3
cols <- function(..., .default = col_guess(), .delim = NULL) {
col_types <- rlang::list2(...)
col_types <- list2(...)
is_character <- vapply(col_types, is.character, logical(1))
col_types[is_character] <- lapply(col_types[is_character], col_concise)

Expand Down Expand Up @@ -199,7 +199,7 @@ format.col_spec <- function(x, n = Inf, condense = NULL, colour = crayon::has_co
delim <- x$delim

if (!is.null(delim) && nzchar(delim)) {
delim <- paste0('.delim = ', double_quote(delim), '')
delim <- paste0('.delim = ', glue::double_quote(delim), '')
}

cols_args <- c(
Expand Down Expand Up @@ -263,11 +263,11 @@ colourise_cols <- function(cols, colourise = crayon::has_color()) {
col_double = ,
col_integer = ,
col_big_integer = ,
col_number = crayon::green(cols[[i]]),
col_number = green(cols[[i]]),

col_date = ,
col_datetime = ,
col_time = crayon::blue(cols[[i]])
col_time = blue(cols[[i]])
)
}
cols
Expand Down Expand Up @@ -346,8 +346,8 @@ col_concise <- function(x) {
}

vroom_enquo <- function(x) {
if (rlang::quo_is_call(x, "c") || rlang::quo_is_call(x, "list")) {
return(rlang::as_quosures(rlang::get_expr(x)[-1], rlang::get_env(x)))
if (quo_is_call(x, "c") || quo_is_call(x, "list")) {
return(as_quosures(get_expr(x)[-1], get_env(x)))
}
x
}
Expand All @@ -359,7 +359,7 @@ vroom_select <- function(x, col_select, id) {
is_null <- vapply(x, is.null, logical(1))
x[is_null] <- NULL
# reorder and rename columns
if (inherits(col_select, "quosures") || !rlang::quo_is_null(col_select)) {
if (inherits(col_select, "quosures") || !quo_is_null(col_select)) {
if (inherits(col_select, "quosures")) {
vars <- tidyselect::vars_select(c(names(spec(x)$cols), id), !!!col_select)
} else {
Expand Down Expand Up @@ -417,7 +417,7 @@ col_types_standardise <- function(spec, num_cols, col_names, col_select, name_re

bad_types <- !(type_names %in% col_names)
if (any(bad_types)) {
rlang::warn(paste0("The following named parsers don't match the column names: ",
warn(paste0("The following named parsers don't match the column names: ",
paste0(type_names[bad_types], collapse = ", ")), class = "vroom_mismatched_column_name")
spec$cols <- spec$cols[!bad_types]
type_names <- type_names[!bad_types]
Expand All @@ -433,7 +433,7 @@ col_types_standardise <- function(spec, num_cols, col_names, col_select, name_re
spec$cols <- spec$cols[col_names]
}

if (inherits(col_select, "quosures") || !rlang::quo_is_null(col_select)) {
if (inherits(col_select, "quosures") || !quo_is_null(col_select)) {
if (inherits(col_select, "quosures")) {
to_keep <- names(spec$cols) %in% tidyselect::vars_select(names(spec$cols), !!!col_select, .strict = FALSE)
} else {
Expand Down Expand Up @@ -535,8 +535,6 @@ collector_value.collector_time <- function(x, ...) { hms::hms() }
#' @export
collector_value.collector_guess <- function(x, ...) { character() }

#' @importFrom crayon silver
#' @importFrom glue double_quote
#' @export
summary.col_spec <- function(object, width = getOption("width"), locale = default_locale(), ...) {
if (length(object$cols) == 0) {
Expand Down Expand Up @@ -571,7 +569,7 @@ summary.col_spec <- function(object, width = getOption("width"), locale = defaul
entries = glue::glue("{format(types)} {counts}: {columns}"),

'
{if (nzchar(delim)) paste(bold("Delimiter:"), double_quote(delim)) else ""}
{if (nzchar(delim)) paste(bold("Delimiter:"), glue::double_quote(delim)) else ""}
{entries*}
Expand Down Expand Up @@ -616,10 +614,10 @@ color_type <- function(type) {
lgl = crayon::yellow(type),
dbl = ,
int = ,
num = crayon::green(type),
num = green(type),
date = ,
dttm = ,
time = crayon::blue(type),
time = blue(type),
"???" = type
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/generator.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ gen_tbl <- function(rows, cols = NULL, col_types = NULL, locale = default_locale

nms <- make_names(names(spec$cols), cols)

specs <- col_types_standardise(spec, length(nms), nms, vroom_enquo(rlang::quo(NULL)), "unique")
specs <- col_types_standardise(spec, length(nms), nms, vroom_enquo(quo(NULL)), "unique")
res <- vector("list", cols)
for (i in seq_len(cols)) {
type <- sub("collector_", "", class(specs$cols[[i]])[[1]])
Expand Down
8 changes: 4 additions & 4 deletions R/path.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ reencode_file <- function(path, encoding) {
}

# These functions adapted from https://github.com/tidyverse/readr/blob/192cb1ca5c445e359f153d2259391e6d324fd0a2/R/source.R
standardise_path <- function(path, user_env = rlang::caller_env(2)) {
standardise_path <- function(path, user_env = caller_env(2)) {
if (is.raw(path)) {
return(list(rawConnection(path, "rb")))
}
Expand Down Expand Up @@ -80,7 +80,7 @@ standardise_one_path <- function (path, write = FALSE) {
if (requireNamespace("curl", quietly = TRUE)) {
con <- curl::curl(path)
} else {
rlang::inform("`curl` package not installed, falling back to using `url()`")
inform("`curl` package not installed, falling back to using `url()`")
con <- url(path)
}
ext <- tolower(tools::file_ext(path))
Expand Down Expand Up @@ -109,7 +109,7 @@ standardise_one_path <- function (path, write = FALSE) {
path <- check_path(path)
}

if (rlang::is_installed("archive")) {
if (is_installed("archive")) {
formats <- archive_formats(p$extension)
extension <- p$extension
while(is.null(formats) && nzchar(extension)) {
Expand Down Expand Up @@ -247,7 +247,7 @@ zipfile <- function(path, open = "r") {
file <- files$Name[[1]]

if (nrow(files) > 1) {
rlang::inform(paste0("Multiple files in zip: reading '", file, "'"))
inform(paste0("Multiple files in zip: reading '", file, "'"))
}

unz(path, file, open = open)
Expand Down
10 changes: 10 additions & 0 deletions R/vroom-package.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#' @keywords internal
#' @aliases vroom-package
#' @useDynLib vroom, .registration = TRUE
"_PACKAGE"

## usethis namespace: start
#' @import rlang
#' @importFrom bit64 integer64
#' @importFrom crayon blue
#' @importFrom crayon bold
#' @importFrom crayon cyan
#' @importFrom crayon green
#' @importFrom crayon reset
#' @importFrom crayon silver
#' @importFrom glue glue
#' @importFrom lifecycle deprecate_warn
#' @importFrom lifecycle deprecated
## usethis namespace: end
Expand Down
13 changes: 4 additions & 9 deletions R/vroom.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#' @useDynLib vroom, .registration = TRUE
#' @importFrom bit64 integer64
NULL

#' Read a delimited file into a tibble
#'
#' @param file Either a path to a file, a connection, or literal data (either a
Expand Down Expand Up @@ -217,7 +213,7 @@ vroom <- function(
delim <- "\x01"
}

if (!rlang::is_missing(altrep_opts)) {
if (!is_missing(altrep_opts)) {
deprecate_warn("1.1.0", "vroom(altrep_opts = )", "vroom(altrep = )")
altrep <- altrep_opts
}
Expand Down Expand Up @@ -249,7 +245,7 @@ vroom <- function(
Sys.setenv("RSTUDIO" = "1")
}

col_select <- vroom_enquo(rlang::enquo(col_select))
col_select <- vroom_enquo(enquo(col_select))

has_col_types <- !is.null(col_types)

Expand Down Expand Up @@ -331,15 +327,14 @@ make_names <- function(x, len) {
#' vroom_progress()
vroom_progress <- function() {
env_to_logical("VROOM_SHOW_PROGRESS", TRUE) &&
rlang::is_interactive() &&
is_interactive() &&
# some analysis re: rstudio.notebook.executing can be found in:
# https://github.com/r-lib/rlang/issues/1031
# TL;DR it's not consulted by is_interactive(), but probably should be
# consulted for progress reporting specifically
!isTRUE(getOption("rstudio.notebook.executing"))
}

#' @importFrom crayon blue cyan green bold reset col_nchar
pb_file_format <- function(filename) {

# Workaround RStudio bug https://github.com/rstudio/rstudio/issues/4777
Expand All @@ -349,7 +344,7 @@ pb_file_format <- function(filename) {
}

pb_width <- function(format) {
ansii_chars <- nchar(format) - col_nchar(format)
ansii_chars <- nchar(format) - crayon::col_nchar(format)
getOption("width", 80L) + ansii_chars
}

Expand Down
6 changes: 3 additions & 3 deletions R/vroom_fwf.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ vroom_fwf <- function(file,

verify_fwf_positions(col_positions)

if (!rlang::is_missing(altrep_opts)) {
lifecycle::deprecate_warn("1.1.0", "vroom_fwf(altrep_opts = )", "vroom_fwf(altrep = )")
if (!is_missing(altrep_opts)) {
deprecate_warn("1.1.0", "vroom_fwf(altrep_opts = )", "vroom_fwf(altrep = )")
altrep <- altrep_opts
}

Expand All @@ -66,7 +66,7 @@ vroom_fwf <- function(file,
guess_max <- -1
}

col_select <- vroom_enquo(rlang::enquo(col_select))
col_select <- vroom_enquo(enquo(col_select))

has_col_types <- !is.null(col_types)

Expand Down
6 changes: 3 additions & 3 deletions R/vroom_lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ vroom_lines <- function(file, n_max = Inf, skip = 0,
altrep_opts = deprecated(), num_threads = vroom_threads(),
progress = vroom_progress()) {

if (!rlang::is_missing(altrep_opts)) {
lifecycle::deprecate_warn("1.1.0", "vroom_lines(altrep_opts = )", "vroom_lines(altrep = )")
if (!is_missing(altrep_opts)) {
deprecate_warn("1.1.0", "vroom_lines(altrep_opts = )", "vroom_lines(altrep = )")
altrep <- altrep_opts
}

Expand All @@ -38,7 +38,7 @@ vroom_lines <- function(file, n_max = Inf, skip = 0,
return(character())
}

col_select <- rlang::quo(NULL)
col_select <- quo(NULL)

# delim = "\1" sets the delimiter to be start of header, which should never
# appear in modern text. This essentially means the only record breaks will
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-problems.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ test_that("can promote vroom parse warning to error", {
withCallingHandlers(
expr = make_warning(),
vroom_parse_issue = function(cnd) {
rlang::abort("oh no")
abort("oh no")
}
)
)
Expand Down

0 comments on commit 7ff9811

Please sign in to comment.