Skip to content

Commit

Permalink
fix nchar limit for function display
Browse files Browse the repository at this point in the history
  • Loading branch information
t-kalinowski committed Oct 16, 2024
1 parent 58a11e3 commit d3c63a1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions R/generic-spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ as_S3_generic <- function(x) {
}
}

stop("`generic` is a function, but not an S3 generic function: ",
deparse1(x, width.cutoff = 100L), call. = FALSE)
stop("`generic` is a function, but not an S3 generic function: \n",
deparse_trunc(x, 100), call. = FALSE)
}

S3_generic <- function(generic, name) {
Expand Down
7 changes: 7 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ modify_list <- function (x, new_vals) {
x
}

deparse_trunc <- function(x, width, collapse = "\n") {
x <- deparse1(x, collapse)
if (nchar(x)> width)
x <- sprintf("%s....", substr(x, 0, width-4))
x
}


# For older versions of R ----------------------------------------------------
deparse1 <- function(expr, collapse = " ", width.cutoff = 500L, ...) {
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/_snaps/generic-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
as_generic(function() { })
Condition
Error:
! `generic` is a function, but not an S3 generic function: function () { }
! `generic` is a function, but not an S3 generic function:
function ()
{
}

---

Expand Down

0 comments on commit d3c63a1

Please sign in to comment.