Skip to content

Commit

Permalink
Update for knitr
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Sep 11, 2022
1 parent 718db20 commit e8cf3e5
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions common.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,19 @@ section_strip <- function(path) {
# Errors ------------------------------------------------------------------

# 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)
}
sew.error <- function(x, options) {
msg <- conditionMessage(x)

msg <- error_wrap(msg)
knitr:::msg_wrap(msg, "error", options)
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]]
Expand Down

0 comments on commit e8cf3e5

Please sign in to comment.