From c84ee0d31fe7277542dbaeffa26c0258d84c9f44 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Tue, 9 Apr 2024 21:50:15 -0500 Subject: [PATCH] add 'at lines' to the error messages only in csv_options() and yaml_load() --- R/knitr.R | 11 +++++++---- R/yaml.R | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/R/knitr.R b/R/knitr.R index 6379261..f1708ad 100644 --- a/R/knitr.R +++ b/R/knitr.R @@ -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 diff --git a/R/yaml.R b/R/yaml.R index 23a8d7f..6ec32fc 100644 --- a/R/yaml.R +++ b/R/yaml.R @@ -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]), ''