From 81ae9da0c82f70f8def1645c8f9638a1fc010dad Mon Sep 17 00:00:00 2001 From: DavisVaughan Date: Mon, 1 May 2023 11:47:30 -0400 Subject: [PATCH 1/2] Only report the first class in `obj_type_friendly()` --- R/standalone-obj-type.R | 7 +++++-- tests/testthat/_snaps/cnd-signal.md | 6 +++--- tests/testthat/test-friendly-type.R | 5 +++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/R/standalone-obj-type.R b/R/standalone-obj-type.R index a9b5c46758..106accce77 100644 --- a/R/standalone-obj-type.R +++ b/R/standalone-obj-type.R @@ -1,13 +1,16 @@ # --- # repo: r-lib/rlang # file: standalone-obj-type.R -# last-updated: 2023-03-30 +# last-updated: 2023-05-01 # license: https://unlicense.org # imports: rlang (>= 1.1.0) # --- # # ## Changelog # +# 2023-05-01: +# - `obj_type_friendly()` now only displays the first class of S3 objects. +# # 2023-03-30: # - `stop_input_type()` now handles `I()` input literally in `arg`. # @@ -64,7 +67,7 @@ obj_type_friendly <- function(x, value = TRUE) { if (inherits(x, "quosure")) { type <- "quosure" } else { - type <- paste(class(x), collapse = "/") + type <- class(x)[[1L]] } return(sprintf("a <%s> object", type)) } diff --git a/tests/testthat/_snaps/cnd-signal.md b/tests/testthat/_snaps/cnd-signal.md index 8942b4d842..94f23d61e8 100644 --- a/tests/testthat/_snaps/cnd-signal.md +++ b/tests/testthat/_snaps/cnd-signal.md @@ -63,19 +63,19 @@ Output Error in `abort()`: - ! `message` must be a character vector, not a object. + ! `message` must be a character vector, not a object. Code (expect_error(inform(error_cnd("foo")))) Output Error in `inform()`: - ! `message` must be a character vector, not a object. + ! `message` must be a character vector, not a object. Code (expect_error(warn(class = error_cnd("foo")))) Output Error in `warn()`: - ! `class` must be a character vector, not a object. + ! `class` must be a character vector, not a object. Code (expect_error(abort("foo", call = base::call))) Output diff --git a/tests/testthat/test-friendly-type.R b/tests/testthat/test-friendly-type.R index 3079ba028d..8123f7d8a2 100644 --- a/tests/testthat/test-friendly-type.R +++ b/tests/testthat/test-friendly-type.R @@ -10,6 +10,11 @@ test_that("obj_type_friendly() supports objects", { )) }) +test_that("obj_type_friendly() only displays the first class of objects", { + x <- structure(1, class = c("subclass", "class")) + expect_identical(obj_type_friendly(x), "a object") +}) + test_that("obj_type_friendly() supports matrices and arrays (#141)", { expect_true(all(friendly_types(matrix(list(1, 2))) == "a list matrix")) expect_true(all(friendly_types(array(list(1, 2, 3), dim = 1:3)) == "a list array")) From 5c3b886c34ce4c2aab6ae8f0f9f32e2cf724c83c Mon Sep 17 00:00:00 2001 From: DavisVaughan Date: Mon, 1 May 2023 11:48:58 -0400 Subject: [PATCH 2/2] NEWS bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index c55ef24123..a6d1cea2fe 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # rlang (development version) +* `obj_type_friendly()` now only displays the first class of S3 objects (#1622). + # rlang 1.1.1 * `englue()` now allows omitting `{{`. This is to make it easier to