|
14 | 14 | if (length(rfields) > 0L) { |
15 | 15 | ok <- vapply(rfields, function(f) any(f %in% fields), FALSE) |
16 | 16 | if (any(!ok)){ |
17 | | - if (check == 'warn'){ |
18 | | - warning(sprintf(ngettext(sum(!ok), |
19 | | - "A bibentry of bibtype %s has to specify the field: %s", |
| 17 | + key <- attr(x, "key") |
| 18 | + if (is.null(key)) |
| 19 | + key <- "" |
| 20 | + else |
| 21 | + key <- paste0(key, ": ") |
| 22 | + msg <- sprintf(ngettext(sum(!ok), |
| 23 | + "%sA bibentry of bibtype %s has to specify the field: %s", |
20 | 24 | "A bibentry of bibtype %s has to specify the fields: %s"), |
21 | | - sQuote(bibtype), paste(rfields[!ok], collapse = ", ")), |
22 | | - domain = NA) |
| 25 | + key, sQuote(bibtype), paste(rfields[!ok], collapse = ", ")) |
| 26 | + if (check == 'warn'){ |
| 27 | + warning(msg, domain = NA, call. = FALSE) |
23 | 28 | return(NULL) |
24 | | - }else{ |
25 | | - stop(sprintf(ngettext(sum(!ok), |
26 | | - "A bibentry of bibtype %s has to specify the field: %s", |
27 | | - "A bibentry of bibtype %s has to specify the fields: %s"), |
28 | | - sQuote(bibtype), paste(rfields[!ok], collapse = ", ")), |
29 | | - domain = NA) |
30 | | - } |
| 29 | + }else |
| 30 | + stop(msg, domain = NA) |
31 | 31 | } |
32 | 32 | } |
33 | 33 | } |
@@ -940,14 +940,22 @@ MakeBibEntry <- function(x, to.person = TRUE){ |
940 | 940 | if (type != 'set') |
941 | 941 | tdate <- ProcessDates(y) |
942 | 942 |
|
943 | | - tryCatch(BibEntry(bibtype = type, key = key, dateobj = tdate, other = y), |
| 943 | + withCallingHandlers(tryCatch(BibEntry(bibtype = type, key = key, |
| 944 | + dateobj = tdate, other = y), |
944 | 945 | error = function(e){ |
945 | | - message(sprintf("Ignoring entry '%s' %sbecause:\n\t%s\n", |
| 946 | + message(sprintf("Ignoring entry '%s' %sbecause:\n\t%s", |
946 | 947 | key, |
947 | 948 | line.no, |
948 | | - conditionMessage(e))) |
| 949 | + conditionMessage(e)), domain = NA) |
949 | 950 | NULL |
950 | | - }) |
| 951 | + }), |
| 952 | + warning = function(w){ |
| 953 | + warning(sprintf("%s %s:\n\t%s", |
| 954 | + key, |
| 955 | + line.no, |
| 956 | + conditionMessage(w)), domain = NA, call. = FALSE) |
| 957 | + invokeRestart("muffleWarning") |
| 958 | + }) |
951 | 959 | } |
952 | 960 |
|
953 | 961 | #' @keywords internal |
|
0 commit comments