diff --git a/R/add.R b/R/add.R index b44c0af99..369842471 100644 --- a/R/add.R +++ b/R/add.R @@ -233,7 +233,7 @@ error_add_rows_to_grouped_df <- function() { error_incompatible_new_rows <- function(names) { tibble_error( - bullets( + problems( "New rows can't add columns:", cnd_message(error_unknown_column_names(names)) ), diff --git a/R/tibble.R b/R/tibble.R index 8e6f18bba..7ff315f39 100644 --- a/R/tibble.R +++ b/R/tibble.R @@ -325,7 +325,7 @@ error_tibble_row_size_one <- function(j, name, size) { desc <- paste0("at position ", j) } - tibble_error(bullets( + tibble_error(problems( "All vectors must be size one, use `list()` to wrap.", paste0("Column ", desc, " is of size ", size, ".") )) @@ -350,9 +350,7 @@ error_incompatible_size <- function(.rows, vars, vars_len, rows_source) { paste0("Size ", x, ": ", pluralise_commas(text, y)) }) - problems <- set_default_name(problems, "") - - tibble_error(problems( + tibble_error(bullets( "Tibble columns must have compatible sizes:", if (!is.null(.rows)) paste0("Size ", .rows, ": ", rows_source), problems, diff --git a/R/tribble.R b/R/tribble.R index 9ce128c86..48ac93f71 100644 --- a/R/tribble.R +++ b/R/tribble.R @@ -209,14 +209,14 @@ error_tribble_named_after_tilde <- function() { } error_tribble_lhs_column_syntax <- function(lhs) { - tibble_error(bullets( + tibble_error(problems( "All column specifications must use the `~name` syntax.", paste0("Found ", expr_label(lhs), " on the left-hand side of `~`.") )) } error_tribble_rhs_column_syntax <- function(rhs) { - tibble_error(bullets( + tibble_error(problems( 'All column specifications must use the `~name` or `~"name"` syntax.', paste0("Found ", expr_label(rhs), " on the right-hand side of `~`.") )) @@ -232,7 +232,7 @@ error_tribble_non_rectangular <- function(cols, cells) { } error_frame_matrix_list <- function(pos) { - tibble_error(bullets( + tibble_error(problems( "All values must be atomic:", pluralise_commas("Found list-valued element(s) at position(s) ", pos, ".") )) diff --git a/R/utils-msg-format.R b/R/utils-msg-format.R index 18c879e0b..8b6327a3a 100644 --- a/R/utils-msg-format.R +++ b/R/utils-msg-format.R @@ -49,7 +49,9 @@ pluralise_n <- function(message, n) { bullets <- function(header, ...) { bullets <- vec_c(..., .name_spec = "{outer}") - bullets <- set_default_name(bullets, "x") + if (packageVersion("rlang") >= "0.4.11.9001") { + bullets <- set_default_name(bullets, "*") + } paste0( ensure_full_stop(header), "\n", @@ -59,6 +61,7 @@ bullets <- function(header, ...) { problems <- function(header, ..., .problem = " problem(s)") { problems <- vec_c(..., .name_spec = "{outer}") + problems <- set_default_name(problems, "x") MAX_BULLETS <- 6L if (length(problems) >= MAX_BULLETS) { n_more <- length(problems) - MAX_BULLETS + 1L @@ -93,12 +96,14 @@ commas <- function(problems) { } ensure_full_stop <- function(x) { - gsub("(?::|([^.?]))$", "\\1.", x) + set_names(gsub("(?::|([^.?]))$", "\\1.", x), names(x)) } set_default_name <- function(x, name) { if (is.null(names(x))) { names(x) <- rep_along(x, name) + } else { + names(x)[names(x) == ""] <- name } x diff --git a/tests/testthat/_snaps/msg.md b/tests/testthat/_snaps/msg.md index 28300feca..dee121ef3 100644 --- a/tests/testthat/_snaps/msg.md +++ b/tests/testthat/_snaps/msg.md @@ -316,9 +316,9 @@ Output Tibble columns must have compatible sizes. - Size 10: Requested with `uvw` argument. - Size 3: Column `c`. - Size 4: Columns `a` and `b`. + * Size 10: Requested with `uvw` argument. + * Size 3: Column `c`. + * Size 4: Columns `a` and `b`. i Only values of size one are recycled. Code error_incompatible_size(10, letters[1:3], c(2, 2, 3), @@ -326,9 +326,9 @@ Output Tibble columns must have compatible sizes. - Size 10: Requested with `xyz` argument. - Size 2: Columns `a` and `b`. - Size 3: Column `c`. + * Size 10: Requested with `xyz` argument. + * Size 2: Columns `a` and `b`. + * Size 3: Column `c`. i Only values of size one are recycled. Code error_incompatible_size(NULL, letters[1:3], c(2, 2, 3), @@ -336,34 +336,34 @@ Output Tibble columns must have compatible sizes. - Size 2: Columns `a` and `b`. - Size 3: Column `c`. + * Size 2: Columns `a` and `b`. + * Size 3: Column `c`. i Only values of size one are recycled. Code error_incompatible_size(10, 1:3, c(4, 4, 3), "Requested with `uvw` argument") Output Tibble columns must have compatible sizes. - Size 10: Requested with `uvw` argument. - Size 3: Column at position 3. - Size 4: Columns at positions 1 and 2. + * Size 10: Requested with `uvw` argument. + * Size 3: Column at position 3. + * Size 4: Columns at positions 1 and 2. i Only values of size one are recycled. Code error_incompatible_size(10, 1:3, c(2, 2, 3), "Requested with `xyz` argument") Output Tibble columns must have compatible sizes. - Size 10: Requested with `xyz` argument. - Size 2: Columns at positions 1 and 2. - Size 3: Column at position 3. + * Size 10: Requested with `xyz` argument. + * Size 2: Columns at positions 1 and 2. + * Size 3: Column at position 3. i Only values of size one are recycled. Code error_incompatible_size(NULL, 1:3, c(2, 2, 3), "Requested with `xyz` argument") Output Tibble columns must have compatible sizes. - Size 2: Columns at positions 1 and 2. - Size 3: Column at position 3. + * Size 2: Columns at positions 1 and 2. + * Size 3: Column at position 3. i Only values of size one are recycled. Code # # tribble @@ -388,8 +388,8 @@ Output Data must be rectangular. - Found 5 columns. - Found 17 cells. + * Found 5 columns. + * Found 17 cells. i 17 is not an integer multiple of 5. Code error_frame_matrix_list(2:4) diff --git a/tests/testthat/_snaps/tibble.md b/tests/testthat/_snaps/tibble.md index 09dc9d77c..3b6b97158 100644 --- a/tests/testthat/_snaps/tibble.md +++ b/tests/testthat/_snaps/tibble.md @@ -14,7 +14,7 @@ tibble(a = 1, b = 2:3, c = 4:6, d = 7:10) Error Tibble columns must have compatible sizes. - Size 2: Existing data. - Size 3: Column `c`. + * Size 2: Existing data. + * Size 3: Column `c`. i Only values of size one are recycled. diff --git a/tests/testthat/_snaps/tribble.md b/tests/testthat/_snaps/tribble.md index a6c392921..ab8db19dc 100644 --- a/tests/testthat/_snaps/tribble.md +++ b/tests/testthat/_snaps/tribble.md @@ -8,8 +8,8 @@ tribble(~a, ~b, 1) Error Data must be rectangular. - Found 2 columns. - Found 1 cells. + * Found 2 columns. + * Found 1 cells. i 1 is not an integer multiple of 2. Code tribble(a ~ b, 1) diff --git a/tests/testthat/_snaps/utils-msg-format.md b/tests/testthat/_snaps/utils-msg-format.md index 5002240bf..545422eba 100644 --- a/tests/testthat/_snaps/utils-msg-format.md +++ b/tests/testthat/_snaps/utils-msg-format.md @@ -1,18 +1,79 @@ # output test + Code + # # Problems + writeLines(problems("header", c("item 1", "item 2"))) + Output + header. + x item 1. + x item 2. + Code + writeLines(problems("header", LETTERS)) + Output + header. + x A. + x B. + x C. + x D. + x E. + x ... and 21 more problems. + Code + writeLines(problems("header", 1:6)) + Output + header. + x 1. + x 2. + x 3. + x 4. + x 5. + x ... and 1 more problem. Code # # Bullets - bullets("header", c("item 1", "item 2")) + writeLines(bullets("header", c("item 1", "item 2"))) Output - [1] "header.\nx item 1.\nx item 2." + header. + * item 1. + * item 2. Code - bullets("header", LETTERS) + writeLines(bullets("header", LETTERS)) Output - [1] "header.\nx A.\nx B.\nx C.\nx D.\nx E.\nx F.\nx G.\nx H.\nx I.\nx J.\nx K.\nx L.\nx M.\nx N.\nx O.\nx P.\nx Q.\nx R.\nx S.\nx T.\nx U.\nx V.\nx W.\nx X.\nx Y.\nx Z." + header. + * A. + * B. + * C. + * D. + * E. + * F. + * G. + * H. + * I. + * J. + * K. + * L. + * M. + * N. + * O. + * P. + * Q. + * R. + * S. + * T. + * U. + * V. + * W. + * X. + * Y. + * Z. Code - bullets("header", 1:6) + writeLines(bullets("header", 1:6)) Output - [1] "header.\n* 1.\n* 2.\n* 3.\n* 4.\n* 5.\n* 6." + header. + * 1. + * 2. + * 3. + * 4. + * 5. + * 6. Code # # Commas commas("1") diff --git a/tests/testthat/test-msg.R b/tests/testthat/test-msg.R index 5413fa8e3..926db50e0 100644 --- a/tests/testthat/test-msg.R +++ b/tests/testthat/test-msg.R @@ -7,7 +7,6 @@ test_that("aborting with class", { }) test_that("output test", { - skip_if_not_installed("rlang", "0.4.11.9001") expect_snapshot({ "# add" error_add_rows_to_grouped_df() diff --git a/tests/testthat/test-tibble.R b/tests/testthat/test-tibble.R index b01c956cf..5884744e8 100644 --- a/tests/testthat/test-tibble.R +++ b/tests/testthat/test-tibble.R @@ -248,7 +248,6 @@ test_that("is_tibble", { }) test_that("output test", { - skip_if_not_installed("rlang", "0.4.11.9001") expect_snapshot_with_error({ tibble(a = 1, a = 1) tibble(a = new_environment()) diff --git a/tests/testthat/test-tribble.R b/tests/testthat/test-tribble.R index 8a9164479..1f3091950 100644 --- a/tests/testthat/test-tribble.R +++ b/tests/testthat/test-tribble.R @@ -226,7 +226,6 @@ test_that("tribble and frame_matrix cannot have named arguments", { }) test_that("output test", { - skip_if_not_installed("rlang", "0.4.11.9001") expect_snapshot_with_error({ tribble(1) tribble(~a, ~b, 1) diff --git a/tests/testthat/test-utils-msg-format.R b/tests/testthat/test-utils-msg-format.R index 80178e863..99e9c9a83 100644 --- a/tests/testthat/test-utils-msg-format.R +++ b/tests/testthat/test-utils-msg-format.R @@ -22,10 +22,15 @@ test_that("pluralise_msg works correctly", { test_that("output test", { expect_snapshot({ + "# Problems" + writeLines(problems("header", c("item 1", "item 2"))) + writeLines(problems("header", LETTERS)) + writeLines(problems("header", 1:6)) + "# Bullets" - bullets("header", c("item 1", "item 2")) - bullets("header", LETTERS) - bullets("header", 1:6) + writeLines(bullets("header", c("item 1", "item 2"))) + writeLines(bullets("header", LETTERS)) + writeLines(bullets("header", 1:6)) "# Commas" commas("1")