diff --git a/R/chop.R b/R/chop.R index 9341751e8..5b32de318 100644 --- a/R/chop.R +++ b/R/chop.R @@ -141,17 +141,17 @@ unchop <- function(data, cols, keep_empty = FALSE, ptype = NULL) { # used to slice the data frame `x` was subset from to align it with `val`. # - `val` the unchopped data frame. -df_unchop <- function(x, ..., ptype = NULL, keep_empty = FALSE) { +df_unchop <- function(x, ..., ptype = NULL, keep_empty = FALSE, error_call = caller_env()) { check_dots_empty() if (!is.data.frame(x)) { - abort("`x` must be a data frame.") + abort("`x` must be a data frame.", call = error_call) } if (!is_bool(keep_empty)) { - abort("`keep_empty` must be a single `TRUE` or `FALSE`.") + abort("`keep_empty` must be a single `TRUE` or `FALSE`.", call = error_call) } - ptype <- check_list_of_ptypes(ptype, names = names(x), arg = "ptype") + ptype <- check_list_of_ptypes(ptype, names = names(x), arg = "ptype", call = error_call) size <- vec_size(x) @@ -201,7 +201,7 @@ df_unchop <- function(x, ..., ptype = NULL, keep_empty = FALSE) { x_nulls[[i]] <- info$null } - sizes <- reduce(x_sizes, unchop_sizes2) + sizes <- reduce(x_sizes, unchop_sizes2, error_call = error_call) info <- unchop_finalize(x, sizes, x_nulls, keep_empty) x <- info$x @@ -221,7 +221,7 @@ df_unchop <- function(x, ..., ptype = NULL, keep_empty = FALSE) { if (!col_is_list) { if (!is_null(col_ptype)) { - col <- vec_cast(col, col_ptype, x_arg = col_name) + col <- vec_cast(col, col_ptype, x_arg = col_name, call = error_call) } out_cols[[i]] <- vec_slice(col, out_loc) next @@ -237,7 +237,7 @@ df_unchop <- function(x, ..., ptype = NULL, keep_empty = FALSE) { col_sizes <- x_sizes[[i]] row_recycle <- col_sizes != sizes - col[row_recycle] <- map2(col[row_recycle], sizes[row_recycle], vec_recycle) + col[row_recycle] <- map2(col[row_recycle], sizes[row_recycle], vec_recycle, call = error_call) col <- list_unchop(col, ptype = col_ptype) @@ -264,7 +264,7 @@ df_unchop <- function(x, ..., ptype = NULL, keep_empty = FALSE) { out } -unchop_sizes2 <- function(x, y) { +unchop_sizes2 <- function(x, y, error_call) { # Standard tidyverse recycling rules, just vectorized. # Recycle `x` values with `y` @@ -286,7 +286,7 @@ unchop_sizes2 <- function(x, y) { row <- which(incompatible)[[1]] x <- x[[row]] y <- y[[row]] - abort(glue("In row {row}, can't recycle input of size {x} to size {y}.")) + abort(glue("In row {row}, can't recycle input of size {x} to size {y}."), call = error_call) } x diff --git a/R/expand.R b/R/expand.R index a13e93fe0..d82ddb842 100644 --- a/R/expand.R +++ b/R/expand.R @@ -194,7 +194,7 @@ expand_grid <- function(..., .name_repair = "check_unique") { } # Flattens unnamed data frames after grid expansion - out <- df_list(!!!out, .name_repair = .name_repair) + out <- df_list(!!!out, .name_repair = .name_repair, .error_call = current_env()) out <- tibble::new_tibble(out, nrow = size) out @@ -228,7 +228,7 @@ fct_unique <- function(x) { factor(out, levels = levels, exclude = NULL, ordered = is.ordered(x)) } -grid_dots <- function(..., `_data` = NULL) { +grid_dots <- function(..., `_data` = NULL, .error_call = caller_env()) { dots <- enquos(...) n_dots <- length(dots) @@ -277,7 +277,7 @@ grid_dots <- function(..., `_data` = NULL) { } arg <- paste0("..", i) - vec_assert(dot, arg = arg) + vec_assert(dot, arg = arg, call = .error_call) out[[i]] <- dot diff --git a/R/extract.R b/R/extract.R index ef951beff..f59627faa 100644 --- a/R/extract.R +++ b/R/extract.R @@ -50,8 +50,8 @@ extract.data.frame <- function(data, col, into, regex = "([[:alnum:]]+)", reconstruct_tibble(data, out, if (remove) var else chr()) } -str_extract <- function(x, into, regex, convert = FALSE) { - check_not_stringr_pattern(regex, "regex") +str_extract <- function(x, into, regex, convert = FALSE, error_call = caller_env()) { + check_not_stringr_pattern(regex, "regex", call = error_call) stopifnot( is_string(regex), @@ -60,9 +60,9 @@ str_extract <- function(x, into, regex, convert = FALSE) { out <- str_match_first(x, regex) if (length(out) != length(into)) { - stop( - "`regex` should define ", length(into), " groups; ", length(out), " found.", - call. = FALSE + abort( + glue("`regex` should define {length(into)} groups; {length(out)} found."), + call = error_call ) } diff --git a/R/hoist.R b/R/hoist.R index aeb4326eb..68795ed91 100644 --- a/R/hoist.R +++ b/R/hoist.R @@ -133,7 +133,7 @@ hoist <- function(.data, out } -check_pluckers <- function(...) { +check_pluckers <- function(..., .call = caller_env()) { pluckers <- list2(...) is_string <- map_lgl(pluckers, ~ is.character(.x) && length(.x) == 1) @@ -144,11 +144,11 @@ check_pluckers <- function(...) { } if (length(pluckers) > 0 && !is_named(pluckers)) { - abort("All elements of `...` must be named.") + abort("All elements of `...` must be named.", call = .call) } if (vec_duplicate_any(names(pluckers))) { - abort("The names of `...` must be unique.") + abort("The names of `...` must be unique.", call = .call) } # Standardize all pluckers to lists for splicing into `pluck()` diff --git a/R/pivot-long.R b/R/pivot-long.R index ded493539..5933febed 100644 --- a/R/pivot-long.R +++ b/R/pivot-long.R @@ -321,7 +321,8 @@ pivot_longer_spec <- function(data, data_cols, keys, vals, - .name_repair = names_repair + .name_repair = names_repair, + .error_call = current_env() )) if (values_drop_na) { diff --git a/R/pivot-wide.R b/R/pivot-wide.R index 54e5908d8..a047df7c9 100644 --- a/R/pivot-wide.R +++ b/R/pivot-wide.R @@ -444,7 +444,8 @@ pivot_wider_spec <- function(data, rows, values, unused, - .name_repair = names_repair + .name_repair = names_repair, + .error_call = current_env() )) reconstruct_tibble(input, out) @@ -525,17 +526,19 @@ build_wider_spec <- function(data, build_wider_id_cols_expr <- function(data, id_cols = NULL, names_from = name, - values_from = value) { + values_from = value, + error_call = caller_env()) { # TODO: Use `allow_rename = FALSE`. # Requires https://github.com/r-lib/tidyselect/issues/225. - names_from_cols <- names(tidyselect::eval_select(enquo(names_from), data)) - values_from_cols <- names(tidyselect::eval_select(enquo(values_from), data)) + names_from_cols <- names(tidyselect::eval_select(enquo(names_from), data, error_call = error_call)) + values_from_cols <- names(tidyselect::eval_select(enquo(values_from), data, error_call = error_call)) out <- select_wider_id_cols( data = data, id_cols = {{ id_cols }}, names_from_cols = names_from_cols, - values_from_cols = values_from_cols + values_from_cols = values_from_cols, + error_call = error_call ) expr(c(!!!out)) @@ -544,7 +547,8 @@ build_wider_id_cols_expr <- function(data, select_wider_id_cols <- function(data, id_cols = NULL, names_from_cols = character(), - values_from_cols = character()) { + values_from_cols = character(), + error_call = caller_env()) { id_cols <- enquo(id_cols) # Remove known non-id-cols so they are never selected @@ -558,16 +562,16 @@ select_wider_id_cols <- function(data, try_fetch( # TODO: Use `allow_rename = FALSE`. # Requires https://github.com/r-lib/tidyselect/issues/225. - id_cols <- tidyselect::eval_select(enquo(id_cols), data), + id_cols <- tidyselect::eval_select(enquo(id_cols), data, error_call = error_call), vctrs_error_subscript_oob = function(cnd) { - rethrow_id_cols_oob(cnd, names_from_cols, values_from_cols) + rethrow_id_cols_oob(cnd, names_from_cols, values_from_cols, error_call) } ) names(id_cols) } -rethrow_id_cols_oob <- function(cnd, names_from_cols, values_from_cols) { +rethrow_id_cols_oob <- function(cnd, names_from_cols, values_from_cols, call) { i <- cnd[["i"]] if (!is_string(i)) { @@ -575,26 +579,26 @@ rethrow_id_cols_oob <- function(cnd, names_from_cols, values_from_cols) { } if (i %in% names_from_cols) { - stop_id_cols_oob(i, "names_from") + stop_id_cols_oob(i, "names_from", call = call) } else if (i %in% values_from_cols) { - stop_id_cols_oob(i, "values_from") + stop_id_cols_oob(i, "values_from", call = call) } else { # Zap this special handler, throw the normal condition zap() } } -stop_id_cols_oob <- function(i, arg) { +stop_id_cols_oob <- function(i, arg, call) { message <- c( glue("`id_cols` can't select a column already selected by `{arg}`."), i = glue("Column `{i}` has already been selected.") ) - abort(message, parent = NA) + abort(message, parent = NA, call = call) } # Helpers ----------------------------------------------------------------- -value_summarize <- function(value, value_locs, value_name, fn, fn_name) { +value_summarize <- function(value, value_locs, value_name, fn, fn_name, error_call = caller_env()) { value <- vec_chop(value, value_locs) if (identical(fn, list)) { @@ -618,7 +622,7 @@ value_summarize <- function(value, value_locs, value_name, fn, fn_name) { x = glue("Applying `{fn_name}` resulted in a value with length {size}.") ) - abort(c(header, bullet)) + abort(c(header, bullet), call = error_call) } value <- vec_c(!!!value) diff --git a/R/pivot.R b/R/pivot.R index 77c6fa481..ed0e2fd84 100644 --- a/R/pivot.R +++ b/R/pivot.R @@ -29,24 +29,24 @@ #' # `.name` and `.value` are forced to be the first two columns #' spec <- tibble(foo = 1, .value = "b", .name = "a") #' check_pivot_spec(spec) -check_pivot_spec <- function(spec) { +check_pivot_spec <- function(spec, error_call = caller_env()) { if (!is.data.frame(spec)) { - abort("`spec` must be a data frame.") + abort("`spec` must be a data frame.", call = error_call) } if (!has_name(spec, ".name") || !has_name(spec, ".value")) { - abort("`spec` must have `.name` and `.value` columns.") + abort("`spec` must have `.name` and `.value` columns.", call = error_call) } if (!is.character(spec$.name)) { - abort("The `.name` column of `spec` must be a character vector.") + abort("The `.name` column of `spec` must be a character vector.", call = error_call) } if (vec_duplicate_any(spec$.name)) { - abort("The `.name` column of `spec` must be unique.") + abort("The `.name` column of `spec` must be unique.", call = error_call) } if (!is.character(spec$.value)) { - abort("The `.value` column of `spec` must be a character vector.") + abort("The `.value` column of `spec` must be a character vector.", call = error_call) } # Ensure `.name` and `.value` come first, in that order diff --git a/R/replace_na.R b/R/replace_na.R index 5a6cf4dfa..37e7504c9 100644 --- a/R/replace_na.R +++ b/R/replace_na.R @@ -77,10 +77,10 @@ replace_na.data.frame <- function(data, replace = list(), ...) { data } -check_replacement <- function(x, var) { +check_replacement <- function(x, var, call = caller_env()) { n <- vec_size(x) if (n != 1) { - abort(glue("Replacement for `{var}` is length {n}, not length 1.")) + abort(glue("Replacement for `{var}` is length {n}, not length 1."), call = call) } } diff --git a/R/separate.R b/R/separate.R index 8e95a1eff..bb56904b0 100644 --- a/R/separate.R +++ b/R/separate.R @@ -86,11 +86,11 @@ separate.data.frame <- function(data, col, into, sep = "[^[:alnum:]]+", reconstruct_tibble(data, out, if (remove) var else NULL) } -str_separate <- function(x, into, sep, convert = FALSE, extra = "warn", fill = "warn") { - check_not_stringr_pattern(sep, "sep") +str_separate <- function(x, into, sep, convert = FALSE, extra = "warn", fill = "warn", error_call = caller_env()) { + check_not_stringr_pattern(sep, "sep", call = error_call) if (!is.character(into)) { - abort("`into` must be a character vector") + abort("`into` must be a character vector.", call = error_call) } if (is.numeric(sep)) { @@ -98,7 +98,7 @@ str_separate <- function(x, into, sep, convert = FALSE, extra = "warn", fill = " } else if (is_character(sep)) { out <- str_split_fixed(x, sep, length(into), extra = extra, fill = fill) } else { - abort("`sep` must be either numeric or character") + abort("`sep` must be either numeric or character.", call = error_call) } names(out) <- as_utf8_character(into) @@ -186,9 +186,9 @@ list_indices <- function(x, max = 20) { paste(x, collapse = ", ") } -check_not_stringr_pattern <- function(x, arg) { +check_not_stringr_pattern <- function(x, arg, call = caller_env()) { if (inherits_any(x, c("pattern", "stringr_pattern"))) { - abort(glue("`{arg}` can't use modifiers from stringr.")) + abort(glue("`{arg}` can't use modifiers from stringr."), call = call) } invisible(x) diff --git a/R/unnest-helper.R b/R/unnest-helper.R index e4992de34..881b362d1 100644 --- a/R/unnest-helper.R +++ b/R/unnest-helper.R @@ -5,11 +5,12 @@ df_simplify <- function(x, ..., ptype = NULL, transform = NULL, - simplify = TRUE) { + simplify = TRUE, + error_call = caller_env()) { check_dots_empty() - ptype <- check_list_of_ptypes(ptype, names(x), "ptype") - transform <- check_list_of_functions(transform, names(x), "transform") + ptype <- check_list_of_ptypes(ptype, names(x), "ptype", call = error_call) + transform <- check_list_of_functions(transform, names(x), "transform", call = error_call) if (is_bool(simplify)) { simplify_default <- simplify @@ -19,13 +20,13 @@ df_simplify <- function(x, } if (!vec_is_list(simplify)) { - abort("`simplify` must be a list or a single `TRUE` or `FALSE`.") + abort("`simplify` must be a list or a single `TRUE` or `FALSE`.", call = error_call) } if (length(simplify) > 0L && !is_named(simplify)) { - abort("All elements of `simplify` must be named.") + abort("All elements of `simplify` must be named.", call = error_call) } if (vec_duplicate_any(names(simplify))) { - abort("The names of `simplify` must be unique.") + abort("The names of `simplify` must be unique.", call = error_call) } x_n <- length(x) @@ -47,7 +48,8 @@ df_simplify <- function(x, x = col, ptype = col_ptype, transform = col_transform, - simplify = col_simplify + simplify = col_simplify, + error_call = error_call ) } @@ -58,7 +60,8 @@ col_simplify <- function(x, ..., ptype = NULL, transform = NULL, - simplify = TRUE) { + simplify = TRUE, + error_call = caller_env()) { check_dots_empty() if (!is.null(transform)) { @@ -70,7 +73,7 @@ col_simplify <- function(x, x <- transform(x) } if (!is.null(ptype)) { - x <- vec_cast(x, ptype) + x <- vec_cast(x, ptype, call = error_call) } return(x) } @@ -82,7 +85,7 @@ col_simplify <- function(x, } if (!is.null(ptype)) { x <- tidyr_new_list(x) - x <- vec_cast_common(!!!x, .to = ptype) + x <- vec_cast_common(!!!x, .to = ptype, .call = error_call) x <- new_list_of(x, ptype = ptype) } diff --git a/R/unnest-longer.R b/R/unnest-longer.R index a1e1e24ac..086fcb62e 100644 --- a/R/unnest-longer.R +++ b/R/unnest-longer.R @@ -149,9 +149,10 @@ col_to_long <- function(col, name, values_to, indices_to, - indices_include) { + indices_include, + error_call = caller_env()) { if (is.null(col)) { - abort(glue("Invalid `NULL` column detected for column `{name}`.")) + abort(glue("Invalid `NULL` column detected for column `{name}`."), call = error_call) } if (!vec_is_list(col)) { @@ -174,7 +175,8 @@ col_to_long <- function(col, name = name, values_to = values_to, indices_to = indices_to, - indices_include = indices_include + indices_include = indices_include, + error_call = error_call ) elt_ptype <- vec_ptype(elt_ptype) @@ -188,7 +190,8 @@ col_to_long <- function(col, name = name, values_to = values_to, indices_to = indices_to, - indices_include = indices_include + indices_include = indices_include, + error_call = error_call ) } @@ -208,7 +211,8 @@ elt_to_long <- function(x, name, values_to, indices_to, - indices_include) { + indices_include, + error_call = caller_env()) { if (is.null(x)) { x <- unspecified(1L) @@ -222,7 +226,7 @@ elt_to_long <- function(x, } if (!vec_is(x)) { - abort(glue("Column `{name}` must contain a list of vectors.")) + abort(glue("Column `{name}` must contain a list of vectors."), call = error_call) } if (indices_include) { diff --git a/R/unnest-wider.R b/R/unnest-wider.R index 4b59e751a..0293ba0e8 100644 --- a/R/unnest-wider.R +++ b/R/unnest-wider.R @@ -129,9 +129,9 @@ unnest_wider <- function(data, } # Converts a column of any type to a `list_of` -col_to_wide <- function(col, name, strict, names_sep) { +col_to_wide <- function(col, name, strict, names_sep, error_call = caller_env()) { if (is.null(col)) { - abort(glue("Invalid `NULL` column detected for column `{name}`.")) + abort(glue("Invalid `NULL` column detected for column `{name}`."), call = error_call) } if (!vec_is_list(col)) { @@ -143,12 +143,12 @@ col_to_wide <- function(col, name, strict, names_sep) { # If we don't have a list_of, then a `NULL` `col_ptype` will get converted to # a 1 row, 0 col tibble for `elt_ptype` col_ptype <- list_of_ptype(col) - elt_ptype <- elt_to_wide(col_ptype, name = name, strict = strict, names_sep = names_sep) + elt_ptype <- elt_to_wide(col_ptype, name = name, strict = strict, names_sep = names_sep, error_call = error_call) elt_ptype <- vec_ptype(elt_ptype) # Avoid expensive dispatch from `[[.list_of` out <- tidyr_new_list(col) - out <- map(out, elt_to_wide, name = name, strict = strict, names_sep = names_sep) + out <- map(out, elt_to_wide, name = name, strict = strict, names_sep = names_sep, error_call = error_call) # In the sole case of a list_of, we can be sure that the # elements of `out` will all be of the same type. Otherwise, @@ -182,13 +182,13 @@ col_to_wide <- function(col, name, strict, names_sep) { # where round tripping a typed empty cell results in an empty `list()` that # won't be able to combine with other typed non-empty cells. However, it # can create inconsistencies with vctrs typing rules. -elt_to_wide <- function(x, name, strict, names_sep) { +elt_to_wide <- function(x, name, strict, names_sep, error_call = caller_env()) { if (is.null(x)) { x <- list() } if (!vec_is(x)) { - abort(glue("Column `{name}` must contain a list of vectors.")) + abort(glue("Column `{name}` must contain a list of vectors."), call = error_call) } if (is.data.frame(x)) { @@ -218,7 +218,7 @@ elt_to_wide <- function(x, name, strict, names_sep) { } if (is.null(names_sep)) { - names(x) <- vec_as_names(names2(x), repair = "unique") + names(x) <- vec_as_names(names2(x), repair = "unique", call = error_call) } else { outer <- name @@ -226,7 +226,7 @@ elt_to_wide <- function(x, name, strict, names_sep) { if (is.null(inner)) { inner <- as.character(seq_along(x)) } else { - inner <- vec_as_names(inner, repair = "unique") + inner <- vec_as_names(inner, repair = "unique", call = error_call) } names(x) <- apply_names_sep(outer, inner, names_sep) diff --git a/R/utils.R b/R/utils.R index 83be6be06..aeffda41b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -193,7 +193,7 @@ vec_paste0 <- function(...) { exec(paste0, !!!args) } -check_list_of_ptypes <- function(x, names, arg) { +check_list_of_ptypes <- function(x, names, arg, call = caller_env()) { if (vec_is(x) && vec_is_empty(x)) { x <- rep_named(names, list(x)) } @@ -203,15 +203,18 @@ check_list_of_ptypes <- function(x, names, arg) { } if (!vec_is_list(x)) { - abort(glue("`{arg}` must be `NULL`, an empty ptype, or a named list of ptypes.")) + abort( + glue("`{arg}` must be `NULL`, an empty ptype, or a named list of ptypes."), + call = call + ) } if (length(x) > 0L && !is_named(x)) { - abort(glue("All elements of `{arg}` must be named.")) + abort(glue("All elements of `{arg}` must be named."), call = call) } if (vec_duplicate_any(names(x))) { - abort(glue("The names of `{arg}` must be unique.")) + abort(glue("The names of `{arg}` must be unique."), call = call) } # Silently drop user supplied names not found in the data @@ -220,7 +223,7 @@ check_list_of_ptypes <- function(x, names, arg) { x } -check_list_of_functions <- function(x, names, arg) { +check_list_of_functions <- function(x, names, arg, call = caller_env()) { if (is.null(x)) { x <- set_names(list(), character()) } @@ -230,14 +233,14 @@ check_list_of_functions <- function(x, names, arg) { } if (length(x) > 0L && !is_named(x)) { - abort(glue("All elements of `{arg}` must be named.")) + abort(glue("All elements of `{arg}` must be named."), call = call) } if (vec_duplicate_any(names(x))) { - abort(glue("The names of `{arg}` must be unique.")) + abort(glue("The names of `{arg}` must be unique."), call = call) } - x <- map(x, as_function) + x <- map(x, as_function, arg = arg, call = call) # Silently drop user supplied names not found in the data x <- x[intersect(names(x), names)] diff --git a/man/check_pivot_spec.Rd b/man/check_pivot_spec.Rd index ae80b4255..9b14bee9f 100644 --- a/man/check_pivot_spec.Rd +++ b/man/check_pivot_spec.Rd @@ -4,7 +4,7 @@ \alias{check_pivot_spec} \title{Check assumptions about a pivot \code{spec}} \usage{ -check_pivot_spec(spec) +check_pivot_spec(spec, error_call = caller_env()) } \arguments{ \item{spec}{A specification data frame. This is useful for more complex diff --git a/tests/testthat/_snaps/chop.md b/tests/testthat/_snaps/chop.md index d16bce649..4d74fe84f 100644 --- a/tests/testthat/_snaps/chop.md +++ b/tests/testthat/_snaps/chop.md @@ -13,7 +13,7 @@ (expect_error(unchop(df, c(x, y)))) Output - Error in `fn()`: + Error in `unchop()`: ! In row 1, can't recycle input of size 2 to size 3. # empty typed inputs are considered in common size, but NULLs aren't @@ -22,6 +22,6 @@ (expect_error(unchop(df, c(x, y)))) Output - Error in `fn()`: + Error in `unchop()`: ! In row 1, can't recycle input of size 0 to size 2. diff --git a/tests/testthat/_snaps/expand.md b/tests/testthat/_snaps/expand.md index 45742878d..3d8c0e249 100644 --- a/tests/testthat/_snaps/expand.md +++ b/tests/testthat/_snaps/expand.md @@ -4,7 +4,7 @@ (expect_error(crossing(x = 1:10, y = quote(a)))) Output - Error in `grid_dots()`: + Error in `crossing()`: ! `..2` must be a vector, not a symbol. # expand() respects `.name_repair` @@ -40,7 +40,7 @@ (expect_error(expand_grid(x = x, x = x))) Output - Error in `df_list()`: + Error in `expand_grid()`: ! Names must be unique. x These names are duplicated: * "x" at locations 1 and 2. @@ -61,6 +61,6 @@ (expect_error(grid_dots(lm(1 ~ 1)))) Output - Error in `grid_dots()`: + Error: ! `..1` must be a vector, not a object. diff --git a/tests/testthat/_snaps/extract.md b/tests/testthat/_snaps/extract.md index c75f2a59e..30754202c 100644 --- a/tests/testthat/_snaps/extract.md +++ b/tests/testthat/_snaps/extract.md @@ -3,11 +3,15 @@ Code (expect_error(extract(df, x, "y", "."))) Output - + + Error in `extract()`: + ! `regex` should define 1 groups; 0 found. Code (expect_error(extract(df, x, c("y", "z"), "."))) Output - + + Error in `extract()`: + ! `regex` should define 2 groups; 0 found. # informative error if using stringr modifier functions (#693) @@ -15,6 +19,6 @@ (expect_error(extract(df, x, "x", regex = regex))) Output - Error in `check_not_stringr_pattern()`: + Error in `extract()`: ! `regex` can't use modifiers from stringr. diff --git a/tests/testthat/_snaps/hoist.md b/tests/testthat/_snaps/hoist.md index 58bc84f87..460e49e35 100644 --- a/tests/testthat/_snaps/hoist.md +++ b/tests/testthat/_snaps/hoist.md @@ -4,7 +4,7 @@ (expect_error(hoist(df, x, "b", .ptype = list(b = double())))) Output - Error in `col_simplify()`: + Error in `hoist()`: ! Can't convert `..1` to . # non-vectors generate a cast error if a ptype is supplied @@ -13,7 +13,7 @@ (expect_error(hoist(df, x, "b", .ptype = list(b = integer())))) Output - Error in `col_simplify()`: + Error in `hoist()`: ! `..1` must be a vector, not a symbol. # input validation catches problems @@ -28,13 +28,13 @@ (expect_error(df %>% hoist(x, 1))) Output - Error in `check_pluckers()`: + Error in `hoist()`: ! All elements of `...` must be named. Code (expect_error(df %>% hoist(x, a = "a", a = "b"))) Output - Error in `check_pluckers()`: + Error in `hoist()`: ! The names of `...` must be unique. # can't hoist() from a data frame column diff --git a/tests/testthat/_snaps/pivot-long.md b/tests/testthat/_snaps/pivot-long.md index af579663a..b645e40e5 100644 --- a/tests/testthat/_snaps/pivot-long.md +++ b/tests/testthat/_snaps/pivot-long.md @@ -24,7 +24,7 @@ (expect_error(pivot_longer(df, y, names_to = "x"))) Output - Error in `vec_cbind()`: + Error in `pivot_longer_spec()`: ! Names must be unique. x These names are duplicated: * "x" at locations 1 and 2. @@ -101,13 +101,13 @@ (expect_error(build_longer_spec(df, x, names_ptypes = 1))) Output - Error in `check_list_of_ptypes()`: + Error in `build_longer_spec()`: ! `names_ptypes` must be `NULL`, an empty ptype, or a named list of ptypes. Code (expect_error(build_longer_spec(df, x, names_ptypes = list(integer())))) Output - Error in `check_list_of_ptypes()`: + Error in `build_longer_spec()`: ! All elements of `names_ptypes` must be named. # `names_transform` is validated @@ -116,13 +116,13 @@ (expect_error(build_longer_spec(df, x, names_transform = 1))) Output - Error in `map()`: - ! Can't convert `.x[[i]]`, a number, to a function. + Error in `build_longer_spec()`: + ! Can't convert `names_transform`, a number, to a function. Code (expect_error(build_longer_spec(df, x, names_transform = list(~.x)))) Output - Error in `check_list_of_functions()`: + Error in `build_longer_spec()`: ! All elements of `names_transform` must be named. # `values_ptypes` is validated @@ -131,13 +131,13 @@ (expect_error(pivot_longer(df, x, values_ptypes = 1))) Output - Error in `check_list_of_ptypes()`: + Error in `pivot_longer_spec()`: ! `values_ptypes` must be `NULL`, an empty ptype, or a named list of ptypes. Code (expect_error(pivot_longer(df, x, values_ptypes = list(integer())))) Output - Error in `check_list_of_ptypes()`: + Error in `pivot_longer_spec()`: ! All elements of `values_ptypes` must be named. # `values_transform` is validated @@ -146,13 +146,13 @@ (expect_error(pivot_longer(df, x, values_transform = 1))) Output - Error in `map()`: - ! Can't convert `.x[[i]]`, a number, to a function. + Error in `pivot_longer_spec()`: + ! Can't convert `values_transform`, a number, to a function. Code (expect_error(pivot_longer(df, x, values_transform = list(~.x)))) Output - Error in `check_list_of_functions()`: + Error in `pivot_longer_spec()`: ! All elements of `values_transform` must be named. # `cols_vary` is validated diff --git a/tests/testthat/_snaps/pivot-wide.md b/tests/testthat/_snaps/pivot-wide.md index 16e374e10..c9e756b7a 100644 --- a/tests/testthat/_snaps/pivot-wide.md +++ b/tests/testthat/_snaps/pivot-wide.md @@ -4,7 +4,7 @@ (expect_error(pivot_wider(df, names_from = key, values_from = val))) Output - Error in `vec_cbind()`: + Error in `pivot_wider_spec()`: ! Names must be unique. x These names are duplicated: * "a" at locations 1 and 2. @@ -65,7 +65,7 @@ (expect_error(pivot_wider(df, values_fn = list(value = ~.x)))) Output - Error in `value_summarize()`: + Error in `pivot_wider_spec()`: ! Applying `values_fn` to `value` must result in a single summary value per key. x Applying `values_fn` resulted in a value with length 2. @@ -106,7 +106,7 @@ ) Output - Error in `select_wider_id_cols()`: + Error in `pivot_wider()`: ! `id_cols` can't select a column already selected by `names_from`. i Column `name` has already been selected. Code @@ -114,7 +114,7 @@ ) Output - Error in `select_wider_id_cols()`: + Error in `pivot_wider()`: ! `id_cols` can't select a column already selected by `values_from`. i Column `value` has already been selected. @@ -124,7 +124,7 @@ (expect_error(pivot_wider(df, id_cols = foo))) Output - Error in `select_wider_id_cols()`: + Error in `pivot_wider()`: ! Can't subset columns that don't exist. x Column `foo` doesn't exist. @@ -219,8 +219,8 @@ (expect_error(pivot_wider(df, values_fn = 1))) Output - Error in `map()`: - ! Can't convert `.x[[i]]`, a number, to a function. + Error in `pivot_wider_spec()`: + ! Can't convert `values_fn`, a number, to a function. # `unused_fn` must result in single summary values @@ -228,7 +228,7 @@ (expect_error(pivot_wider(df, id_cols = id, unused_fn = identity))) Output - Error in `value_summarize()`: + Error in `pivot_wider_spec()`: ! Applying `unused_fn` to `unused` must result in a single summary value per key. x Applying `unused_fn` resulted in a value with length 2. @@ -238,6 +238,6 @@ (expect_error(pivot_wider(df, id_cols = id, unused_fn = 1))) Output - Error in `map()`: - ! Can't convert `.x[[i]]`, a number, to a function. + Error in `pivot_wider_spec()`: + ! Can't convert `unused_fn`, a number, to a function. diff --git a/tests/testthat/_snaps/pivot.md b/tests/testthat/_snaps/pivot.md index 77ab4f229..a8ee673f7 100644 --- a/tests/testthat/_snaps/pivot.md +++ b/tests/testthat/_snaps/pivot.md @@ -4,13 +4,13 @@ (expect_error(check_pivot_spec(1))) Output - Error in `check_pivot_spec()`: + Error: ! `spec` must be a data frame. Code (expect_error(check_pivot_spec(mtcars))) Output - Error in `check_pivot_spec()`: + Error: ! `spec` must have `.name` and `.value` columns. # `.name` column must be a character vector @@ -19,7 +19,7 @@ (expect_error(check_pivot_spec(df))) Output - Error in `check_pivot_spec()`: + Error: ! The `.name` column of `spec` must be a character vector. # `.value` column must be a character vector @@ -28,7 +28,7 @@ (expect_error(check_pivot_spec(df))) Output - Error in `check_pivot_spec()`: + Error: ! The `.value` column of `spec` must be a character vector. # `.name` column must be unique @@ -37,6 +37,6 @@ (expect_error(check_pivot_spec(df))) Output - Error in `check_pivot_spec()`: + Error: ! The `.name` column of `spec` must be unique. diff --git a/tests/testthat/_snaps/replace_na.md b/tests/testthat/_snaps/replace_na.md index c89303c4d..364412150 100644 --- a/tests/testthat/_snaps/replace_na.md +++ b/tests/testthat/_snaps/replace_na.md @@ -4,7 +4,7 @@ (expect_error(replace_na(1, 1:10))) Output - Error in `check_replacement()`: + Error in `replace_na()`: ! Replacement for `data` is length 10, not length 1. # replacement must be castable to `data` diff --git a/tests/testthat/_snaps/separate.md b/tests/testthat/_snaps/separate.md index 60b343b7b..701e4615f 100644 --- a/tests/testthat/_snaps/separate.md +++ b/tests/testthat/_snaps/separate.md @@ -48,14 +48,14 @@ (expect_error(separate(df, x, "x", FALSE))) Output - Error in `str_separate()`: - ! `sep` must be either numeric or character + Error in `separate()`: + ! `sep` must be either numeric or character. Code (expect_error(separate(df, x, FALSE))) Output - Error in `str_separate()`: - ! `into` must be a character vector + Error in `separate()`: + ! `into` must be a character vector. # informative error if using stringr modifier functions (#693) @@ -63,6 +63,6 @@ (expect_error(separate(df, x, sep = sep))) Output - Error in `check_not_stringr_pattern()`: + Error in `separate()`: ! `sep` can't use modifiers from stringr. diff --git a/tests/testthat/_snaps/unnest-helper.md b/tests/testthat/_snaps/unnest-helper.md index e4d72dafb..ba7273936 100644 --- a/tests/testthat/_snaps/unnest-helper.md +++ b/tests/testthat/_snaps/unnest-helper.md @@ -4,31 +4,31 @@ (expect_error(df_simplify(data.frame(), simplify = 1))) Output - Error in `df_simplify()`: + Error: ! `simplify` must be a list or a single `TRUE` or `FALSE`. Code (expect_error(df_simplify(data.frame(), simplify = NA))) Output - Error in `df_simplify()`: + Error: ! `simplify` must be a list or a single `TRUE` or `FALSE`. Code (expect_error(df_simplify(data.frame(), simplify = c(TRUE, FALSE)))) Output - Error in `df_simplify()`: + Error: ! `simplify` must be a list or a single `TRUE` or `FALSE`. Code (expect_error(df_simplify(data.frame(), simplify = list(1)))) Output - Error in `df_simplify()`: + Error: ! All elements of `simplify` must be named. Code (expect_error(df_simplify(data.frame(), simplify = list(x = 1, x = 1)))) Output - Error in `df_simplify()`: + Error: ! The names of `simplify` must be unique. # `ptype` is validated @@ -37,19 +37,19 @@ (expect_error(df_simplify(data.frame(), ptype = 1))) Output - Error in `check_list_of_ptypes()`: + Error: ! `ptype` must be `NULL`, an empty ptype, or a named list of ptypes. Code (expect_error(df_simplify(data.frame(), ptype = list(1)))) Output - Error in `check_list_of_ptypes()`: + Error: ! All elements of `ptype` must be named. Code (expect_error(df_simplify(data.frame(), ptype = list(x = 1, x = 1)))) Output - Error in `check_list_of_ptypes()`: + Error: ! The names of `ptype` must be unique. # `transform` is validated @@ -58,25 +58,25 @@ (expect_error(df_simplify(data.frame(), transform = list(~.x)))) Output - Error in `check_list_of_functions()`: + Error: ! All elements of `transform` must be named. Code (expect_error(df_simplify(data.frame(x = 1), transform = 1))) Output - Error in `map()`: - ! Can't convert `.x[[i]]`, a number, to a function. + Error: + ! Can't convert `transform`, a number, to a function. Code (expect_error(df_simplify(data.frame(), transform = list(x = 1)))) Output - Error in `map()`: - ! Can't convert `.x[[i]]`, a number, to a function. + Error: + ! Can't convert `transform`, a number, to a function. Code (expect_error(df_simplify(data.frame(), transform = list(x = 1, x = 1)))) Output - Error in `check_list_of_functions()`: + Error: ! The names of `transform` must be unique. # ptype is applied after transform @@ -86,7 +86,7 @@ 1.5))) Output - Error in `col_simplify()`: + Error: ! Can't convert from `..1` to due to loss of precision. * Locations: 1 diff --git a/tests/testthat/_snaps/unnest-longer.md b/tests/testthat/_snaps/unnest-longer.md index 863a399e4..85a0e879c 100644 --- a/tests/testthat/_snaps/unnest-longer.md +++ b/tests/testthat/_snaps/unnest-longer.md @@ -4,7 +4,7 @@ (expect_error(unnest_longer(df, y))) Output - Error in `elt_to_long()`: + Error in `unnest_longer()`: ! Column `y` must contain a list of vectors. # can't mix `indices_to` with `indices_include = FALSE` diff --git a/tests/testthat/_snaps/unnest-wider.md b/tests/testthat/_snaps/unnest-wider.md index ba6529dc3..384fc6259 100644 --- a/tests/testthat/_snaps/unnest-wider.md +++ b/tests/testthat/_snaps/unnest-wider.md @@ -4,7 +4,7 @@ (expect_error(unnest_wider(df, y))) Output - Error in `.f()`: + Error in `unnest_wider()`: ! Column `y` must contain a list of vectors. # can unnest a vector with a mix of named/unnamed elements (#1200 comment) diff --git a/tests/testthat/_snaps/unnest.md b/tests/testthat/_snaps/unnest.md index c888f3fd9..571ec0b02 100644 --- a/tests/testthat/_snaps/unnest.md +++ b/tests/testthat/_snaps/unnest.md @@ -13,7 +13,7 @@ (expect_error(unnest(df, c(x, y)))) Output - Error in `fn()`: + Error in `unchop()`: ! In row 1, can't recycle input of size 2 to size 3. --- @@ -22,7 +22,7 @@ (expect_error(unnest(df, c(x, y)))) Output - Error in `fn()`: + Error in `unchop()`: ! In row 1, can't recycle input of size 2 to size 3. # unnesting column of mixed vector / data frame input is an error