Skip to content

Commit

Permalink
add 'at lines' to the error messages only in csv_options() and yaml_l…
Browse files Browse the repository at this point in the history
…oad()
  • Loading branch information
yihui committed Apr 10, 2024
1 parent 1182e51 commit c84ee0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions R/knitr.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ csv_options = function(x) {
x = one_string(x)
res = handle_error(
eval(parse_only(paste('alist(', quote_label(x), ')'))),
function(e, loc) c(
sprintf('Invalid syntax for chunk options%s:\n', loc), x,
'\nPlease see documentation at https://yihui.org/knitr/options/.\n'
)
function(e, loc) {
if (loc != '') loc = paste(' at lines', loc)
c(
sprintf('Invalid syntax for chunk options%s:\n', loc), x,
'\nPlease see documentation at https://yihui.org/knitr/options/.\n'
)
}
)
idx = which(names(res) == '') # which option is not named?
# remove empty options
Expand Down
1 change: 1 addition & 0 deletions R/yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ yaml_load = function(
m = regmatches(s, regexec(r, s, perl = TRUE))[[1]]
if (length(m) < 3) return()
m = as.integer(m[-1]) # c(row, col)
if (loc != '') loc = paste(' at lines', loc)
c(
sprintf('Failed to parse YAML%s:', loc), '',
append(x, paste0(strrep(' ', m[2]), '^~~~~~'), m[1]), ''
Expand Down

0 comments on commit c84ee0d

Please sign in to comment.