Skip to content

Commit

Permalink
Stop re-wrapping errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Aug 30, 2022
1 parent 37aad00 commit 7a6286c
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions common.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,33 @@ if (knitr::is_latex_output()) {
options(cli.unicode = TRUE)
}

# Make error messages closer to base R
registerS3method("wrap", "error", envir = asNamespace("knitr"),
function(x, options) {
msg <- conditionMessage(x)

call <- conditionCall(x)
if (is.null(call)) {
msg <- paste0("Error: ", msg)
} else {
msg <- paste0("Error in ", deparse(call)[[1]], ": ", msg)
}

msg <- error_wrap(msg)
knitr:::msg_wrap(msg, "error", options)
}
)
# From NEWS of knitr 1.40 (released 2022-08-24)
# The internal function knitr:::wrap() has been removed from this package. If
# you rely on this function, you will have to use the exported function
# knitr::sew() instead.
# 2022-08-30 stopgap solution: stop re-wrapping errors for now

error_wrap <- function(x, width = getOption("width")) {
lines <- strsplit(x, "\n", fixed = TRUE)[[1]]
paste(strwrap(lines, width = width), collapse = "\n")
}
# Make error messages closer to base R
# registerS3method("wrap", "error", envir = asNamespace("knitr"),
# function(x, options) {
# msg <- conditionMessage(x)
#
# call <- conditionCall(x)
# if (is.null(call)) {
# msg <- paste0("Error: ", msg)
# } else {
# msg <- paste0("Error in ", deparse(call)[[1]], ": ", msg)
# }
#
# msg <- error_wrap(msg)
# knitr:::msg_wrap(msg, "error", options)
# }
# )
#
# error_wrap <- function(x, width = getOption("width")) {
# lines <- strsplit(x, "\n", fixed = TRUE)[[1]]
# paste(strwrap(lines, width = width), collapse = "\n")
# }

check_quietly <- purrr::quietly(devtools::check)
install_quietly <- purrr::quietly(devtools::install)
Expand Down

0 comments on commit 7a6286c

Please sign in to comment.