Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only report the first class in obj_type_friendly() #1622

Merged
merged 2 commits into from
May 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Only report the first class in obj_type_friendly()
DavisVaughan committed May 1, 2023
commit 81ae9da0c82f70f8def1645c8f9638a1fc010dad
7 changes: 5 additions & 2 deletions R/standalone-obj-type.R
Original file line number Diff line number Diff line change
@@ -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))
}
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/cnd-signal.md
Original file line number Diff line number Diff line change
@@ -63,19 +63,19 @@
Output
<error/rlang_error>
Error in `abort()`:
! `message` must be a character vector, not a <foo/rlang_error/error/condition> object.
! `message` must be a character vector, not a <foo> object.
Code
(expect_error(inform(error_cnd("foo"))))
Output
<error/rlang_error>
Error in `inform()`:
! `message` must be a character vector, not a <foo/rlang_error/error/condition> object.
! `message` must be a character vector, not a <foo> object.
Code
(expect_error(warn(class = error_cnd("foo"))))
Output
<error/rlang_error>
Error in `warn()`:
! `class` must be a character vector, not a <foo/rlang_error/error/condition> object.
! `class` must be a character vector, not a <foo> object.
Code
(expect_error(abort("foo", call = base::call)))
Output
5 changes: 5 additions & 0 deletions tests/testthat/test-friendly-type.R
Original file line number Diff line number Diff line change
@@ -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 <subclass> 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"))