From 46942f40261a81301468f7a469c95f2b8260a1cd Mon Sep 17 00:00:00 2001 From: mpadge Date: Tue, 27 Aug 2024 10:09:31 +0200 Subject: [PATCH 1/6] rearrange roclet.R --- DESCRIPTION | 2 +- R/roclet.R | 56 +++++++++++++++++++++++++-------------------------- codemeta.json | 2 +- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8653c0a..45e6cff 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: srr Title: 'rOpenSci' Review Roclets -Version: 0.1.3.005 +Version: 0.1.3.006 Authors@R: person("Mark", "Padgham", , "mark@ropensci.org", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/roclet.R b/R/roclet.R index 58bd539..59a491a 100644 --- a/R/roclet.R +++ b/R/roclet.R @@ -258,34 +258,6 @@ process_srrstats_tags <- function (block, fn_name = TRUE, dir = "R") { return (msg) } -# extract the actual standards numbers from arbitrary text strings, first -# capturing everything inside first "[...]": -extract_standard_numbers <- function (standards) { - - # roxygen parses markdown "**A**" as "\\strong{A}", and the curly braces - # muck up standards ID, so have to be removed here: - g <- gregexpr ("\\\\(strong|emph)\\{[A-Z]+[0-9]+(\\.[0-9]+)?\\}", standards) - m <- lapply (regmatches (standards, g), function (i) { - res <- paste0 (i, collapse = "|") - res <- gsub ("\\\\(strong|emph)", "\\\\\\\\(strong|emph)", res) - res <- gsub ("\\{", "\\\\{", res) - return (gsub ("\\}", "\\\\}", res)) - }) - for (i in seq_along (m)) { - standards [i] <- gsub (m [[i]], "", standards [i]) - } - - # These use regexpr and not gregexpr to only match first '{...}' while - # ignoring all subsequent ones - g_open <- regexpr ("\\{[A-Z]+[0-9]+\\.[0-9]+([a-z]?)", standards) - g_close <- regexpr ("[A-Z]+[0-9]+\\.[0-9]+([a-z]?)\\}", standards) - g_close <- g_close + attr (g_close, "match.length") - 1 - standards <- gsub ("\\{|\\}", "", substring (standards, g_open, g_close)) - standards <- gsub ("\\s*", "", unlist (strsplit (standards, ","))) - - return (standards) -} - #' process_srrstats_NA_tags #' #' @param fn_name Just a dummy here to allow do.call @@ -355,6 +327,34 @@ process_srrstatsTODO_tags <- function (block, fn_name = TRUE, dir = "R") { # nol return (msg) } +# extract the actual standards numbers from arbitrary text strings, first +# capturing everything inside first "[...]": +extract_standard_numbers <- function (standards) { + + # roxygen parses markdown "**A**" as "\\strong{A}", and the curly braces + # muck up standards ID, so have to be removed here: + g <- gregexpr ("\\\\(strong|emph)\\{[A-Z]+[0-9]+(\\.[0-9]+)?\\}", standards) + m <- lapply (regmatches (standards, g), function (i) { + res <- paste0 (i, collapse = "|") + res <- gsub ("\\\\(strong|emph)", "\\\\\\\\(strong|emph)", res) + res <- gsub ("\\{", "\\\\{", res) + return (gsub ("\\}", "\\\\}", res)) + }) + for (i in seq_along (m)) { + standards [i] <- gsub (m [[i]], "", standards [i]) + } + + # These use regexpr and not gregexpr to only match first '{...}' while + # ignoring all subsequent ones + g_open <- regexpr ("\\{[A-Z]+[0-9]+\\.[0-9]+([a-z]?)", standards) + g_close <- regexpr ("[A-Z]+[0-9]+\\.[0-9]+([a-z]?)\\}", standards) + g_close <- g_close + attr (g_close, "match.length") - 1 + standards <- gsub ("\\{|\\}", "", substring (standards, g_open, g_close)) + standards <- gsub ("\\s*", "", unlist (strsplit (standards, ","))) + + return (standards) +} + get_block_backref <- function (block, base_path = NULL) { block_backref <- roxygen2::block_get_tag_value (block, "backref") diff --git a/codemeta.json b/codemeta.json index aeec72e..6eacb00 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/srr", "issueTracker": "https://github.com/ropensci-review-tools/srr/issues", "license": "https://spdx.org/licenses/MIT", - "version": "0.1.3.005", + "version": "0.1.3.006", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", From 4537f115d1ed36ef1b46d3d1230fa3a85e8100bd Mon Sep 17 00:00:00 2001 From: mpadge Date: Tue, 27 Aug 2024 10:13:10 +0200 Subject: [PATCH 2/6] improve 'check_block_title' fn to apply to all tags for #41 --- DESCRIPTION | 2 +- R/roclet.R | 21 +++++++++------------ codemeta.json | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 45e6cff..df0e1e3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: srr Title: 'rOpenSci' Review Roclets -Version: 0.1.3.006 +Version: 0.1.3.007 Authors@R: person("Mark", "Padgham", , "mark@ropensci.org", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/roclet.R b/R/roclet.R index 59a491a..24ff370 100644 --- a/R/roclet.R +++ b/R/roclet.R @@ -204,14 +204,18 @@ check_block_title <- function (block, tag) { block_title <- roxygen2::block_get_tag_value (block, "title") block_title <- ifelse (is.null (block_title), "", block_title) - if (grepl ("^NA\\_st", block_title)) { + if (tag != "srrstatsNA" && grepl ("^NA\\_st", block_title)) { stop (paste0 ( "An NA_standards block should only contain ", "'@srrstatsNA' tags, and no '@", tag, "' tags." )) + } else if (tag == "srrstatsNA" & !block_title == "NA_standards") { + stop ( + "@srrstatsNA tags should only appear in ", + "a block with a title of NA_standards" + ) } - } #' process_srrstats_tags @@ -220,10 +224,10 @@ check_block_title <- function (block, tag) { #' @noRd process_srrstats_tags <- function (block, fn_name = TRUE, dir = "R") { - func_name <- block$object$alias - check_block_title (block, "srrstats") + func_name <- block$object$alias + standards <- roxygen2::block_get_tags (block, "srrstats") standards <- unlist (lapply (standards, function (i) i$val)) @@ -264,14 +268,7 @@ process_srrstats_tags <- function (block, fn_name = TRUE, dir = "R") { #' @noRd process_srrstatsNA_tags <- function (block, fn_name = TRUE, dir = "R") { # nolint - block_title <- roxygen2::block_get_tag_value (block, "title") - block_title <- ifelse (length (block_title) == 0L, "", block_title) - if (!block_title == "NA_standards") { - stop ( - "@srrstatsNA tags should only appear in ", - "a block with a title of NA_standards" - ) - } + check_block_title (block, "srrstatsNA") standards <- roxygen2::block_get_tags (block, "srrstatsNA") standards <- unlist (lapply (standards, function (i) i$val)) diff --git a/codemeta.json b/codemeta.json index 6eacb00..8abaec2 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/srr", "issueTracker": "https://github.com/ropensci-review-tools/srr/issues", "license": "https://spdx.org/licenses/MIT", - "version": "0.1.3.006", + "version": "0.1.3.007", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", From 69e69b9f678792320711024dd13b7524714ebba1 Mon Sep 17 00:00:00 2001 From: mpadge Date: Tue, 27 Aug 2024 10:15:31 +0200 Subject: [PATCH 3/6] consistent error catching for incorrectly formatted stds for all tag types #41 --- DESCRIPTION | 2 +- R/roclet.R | 13 +++---------- codemeta.json | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index df0e1e3..1db6f07 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: srr Title: 'rOpenSci' Review Roclets -Version: 0.1.3.007 +Version: 0.1.3.008 Authors@R: person("Mark", "Padgham", , "mark@ropensci.org", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/roclet.R b/R/roclet.R index 24ff370..92ee318 100644 --- a/R/roclet.R +++ b/R/roclet.R @@ -232,9 +232,6 @@ process_srrstats_tags <- function (block, fn_name = TRUE, dir = "R") { standards <- unlist (lapply (standards, function (i) i$val)) snum <- extract_standard_numbers (standards) - if (length (snum) < 1) { - stop ("srrstats tags found but no correctly-formatted standard numbers") - } block_backref <- get_block_backref (block) block_line <- block$line @@ -245,11 +242,6 @@ process_srrstats_tags <- function (block, fn_name = TRUE, dir = "R") { } ptn <- paste0 ("^.*", dir, "\\/") fpath <- regmatches (block$file, regexpr (ptn, block$file)) - if (length (fpath) == 0L) { - # Mostly only for 'tests/testthat.R' file, which should never have tags - # anyway, so is skipped here. - return (NULL) - } fpath_full <- gsub (fpath, paste0 (dir, "/"), block$file) msg <- paste0 ( @@ -273,7 +265,6 @@ process_srrstatsNA_tags <- function (block, fn_name = TRUE, dir = "R") { # nolin standards <- roxygen2::block_get_tags (block, "srrstatsNA") standards <- unlist (lapply (standards, function (i) i$val)) snum <- extract_standard_numbers (standards) - # standards <- gsub ("\\s.*$", "", standards) block_backref <- get_block_backref (block) block_line <- block$line @@ -303,7 +294,6 @@ process_srrstatsTODO_tags <- function (block, fn_name = TRUE, dir = "R") { # nol standards <- roxygen2::block_get_tags (block, "srrstatsTODO") standards <- unlist (lapply (standards, function (i) i$val)) - # standards <- gsub ("\\s.*$", "", standards) snum <- extract_standard_numbers (standards) block_backref <- get_block_backref (block) @@ -348,6 +338,9 @@ extract_standard_numbers <- function (standards) { g_close <- g_close + attr (g_close, "match.length") - 1 standards <- gsub ("\\{|\\}", "", substring (standards, g_open, g_close)) standards <- gsub ("\\s*", "", unlist (strsplit (standards, ","))) + if (length (standards) < 1) { + stop ("srrstats tags found but no correctly-formatted standard numbers") + } return (standards) } diff --git a/codemeta.json b/codemeta.json index 8abaec2..1f32452 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/srr", "issueTracker": "https://github.com/ropensci-review-tools/srr/issues", "license": "https://spdx.org/licenses/MIT", - "version": "0.1.3.007", + "version": "0.1.3.008", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", From b4297ef3e170ea66f2ba6c543b662e95f104ef57 Mon Sep 17 00:00:00 2001 From: mpadge Date: Tue, 27 Aug 2024 10:22:04 +0200 Subject: [PATCH 4/6] reduce tag-specific 'process' fns to one generic fn for #41 --- DESCRIPTION | 2 +- R/roclet.R | 82 ++++++++------------------------------------------- codemeta.json | 2 +- 3 files changed, 14 insertions(+), 72 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1db6f07..b4da955 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: srr Title: 'rOpenSci' Review Roclets -Version: 0.1.3.008 +Version: 0.1.3.009 Authors@R: person("Mark", "Padgham", , "mark@ropensci.org", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/roclet.R b/R/roclet.R index 92ee318..ab7c4ed 100644 --- a/R/roclet.R +++ b/R/roclet.R @@ -153,14 +153,14 @@ get_verbose_flag <- function (blocks) { parse_one_msg_list <- function (msgs, block, tag, fn_name = TRUE, dir = "R") { if (length (roxygen2::block_get_tags (block, tag)) > 0L) { - call_fn <- paste0 ("process_", tag, "_tags") msgs <- c ( msgs, - do.call (call_fn, list ( + process_srrstats_tags ( + tag = tag, block = block, fn_name = fn_name, dir = dir - )) + ) ) } @@ -222,23 +222,24 @@ check_block_title <- function (block, tag) { #' #' @param fn_name Include name of calling function in message? #' @noRd -process_srrstats_tags <- function (block, fn_name = TRUE, dir = "R") { +process_srrstats_tags <- function (tag = "srrstats", block, + fn_name = TRUE, dir = "R") { - check_block_title (block, "srrstats") + check_block_title (block, tag) - func_name <- block$object$alias - - standards <- roxygen2::block_get_tags (block, "srrstats") + standards <- roxygen2::block_get_tags (block, tag) standards <- unlist (lapply (standards, function (i) i$val)) - snum <- extract_standard_numbers (standards) block_backref <- get_block_backref (block) block_line <- block$line msg <- paste0 ("[", paste0 (snum, collapse = ", "), "]") - if (fn_name && !is.null (func_name)) { - msg <- paste0 (msg, " in function '", func_name, "()'") + if (fn_name) { + func_name <- block$object$alias + if (!is.null (func_name)) { + msg <- paste0 (msg, " in function '", func_name, "()'") + } } ptn <- paste0 ("^.*", dir, "\\/") fpath <- regmatches (block$file, regexpr (ptn, block$file)) @@ -254,65 +255,6 @@ process_srrstats_tags <- function (block, fn_name = TRUE, dir = "R") { return (msg) } -#' process_srrstats_NA_tags -#' -#' @param fn_name Just a dummy here to allow do.call -#' @noRd -process_srrstatsNA_tags <- function (block, fn_name = TRUE, dir = "R") { # nolint - - check_block_title (block, "srrstatsNA") - - standards <- roxygen2::block_get_tags (block, "srrstatsNA") - standards <- unlist (lapply (standards, function (i) i$val)) - snum <- extract_standard_numbers (standards) - - block_backref <- get_block_backref (block) - block_line <- block$line - - ptn <- paste0 ("^.*", dir, "\\/") - fpath <- regmatches (block$file, regexpr (ptn, block$file)) - fpath_full <- gsub (fpath, paste0 (dir, "/"), block$file) - - msg <- paste0 ( - "[", paste0 (snum, collapse = ", "), - "] on line#", block_line, - " of file [", - fpath_full, - "]" - ) - - return (msg) -} - -#' process_srrstats_TODO_tags -#' -#' @param fn_name Just a dummy here to allow do.call -#' @noRd -process_srrstatsTODO_tags <- function (block, fn_name = TRUE, dir = "R") { # nolint - - check_block_title (block, "srrstatsTODO") - - standards <- roxygen2::block_get_tags (block, "srrstatsTODO") - standards <- unlist (lapply (standards, function (i) i$val)) - snum <- extract_standard_numbers (standards) - - block_backref <- get_block_backref (block) - block_line <- block$line - - ptn <- paste0 ("^.*", dir, "\\/") - fpath <- regmatches (block$file, regexpr (ptn, block$file)) - fpath_full <- gsub (fpath, paste0 (dir, "/"), block$file) - - msg <- paste0 ( - "[", paste0 (snum, collapse = ", "), - "] on line#", block_line, - " of file [", - fpath_full, - "]" - ) - - return (msg) -} # extract the actual standards numbers from arbitrary text strings, first # capturing everything inside first "[...]": diff --git a/codemeta.json b/codemeta.json index 1f32452..438a586 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/srr", "issueTracker": "https://github.com/ropensci-review-tools/srr/issues", "license": "https://spdx.org/licenses/MIT", - "version": "0.1.3.008", + "version": "0.1.3.009", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", From 1a3c37a6950fe1564c85b1c7b72081510e7adee5 Mon Sep 17 00:00:00 2001 From: mpadge Date: Tue, 27 Aug 2024 10:54:00 +0200 Subject: [PATCH 5/6] normalizePath at start of report fn for #41 --- DESCRIPTION | 2 +- R/report.R | 1 + codemeta.json | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b4da955..c805ef6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: srr Title: 'rOpenSci' Review Roclets -Version: 0.1.3.009 +Version: 0.1.3.010 Authors@R: person("Mark", "Padgham", , "mark@ropensci.org", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/report.R b/R/report.R index bfd3220..7455162 100644 --- a/R/report.R +++ b/R/report.R @@ -41,6 +41,7 @@ srr_report <- function (path = ".", branch = "", if (path == ".") { path <- here::here () } + path <- normalizePath (path) remote <- get_git_remote (path) branch <- get_git_branch (path, branch) diff --git a/codemeta.json b/codemeta.json index 438a586..4eac039 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/srr", "issueTracker": "https://github.com/ropensci-review-tools/srr/issues", "license": "https://spdx.org/licenses/MIT", - "version": "0.1.3.009", + "version": "0.1.3.010", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", From fa2a8cf01e88d1aeb6b834aabf3a6b14dea624a1 Mon Sep 17 00:00:00 2001 From: mpadge Date: Tue, 27 Aug 2024 10:54:45 +0200 Subject: [PATCH 6/6] fix #41 to allow stds in tests/testthat.R --- DESCRIPTION | 2 +- R/roclet.R | 12 ++++++++++-- codemeta.json | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c805ef6..f6324e3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: srr Title: 'rOpenSci' Review Roclets -Version: 0.1.3.010 +Version: 0.1.3.011 Authors@R: person("Mark", "Padgham", , "mark@ropensci.org", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/roclet.R b/R/roclet.R index ab7c4ed..8472153 100644 --- a/R/roclet.R +++ b/R/roclet.R @@ -242,8 +242,16 @@ process_srrstats_tags <- function (tag = "srrstats", block, } } ptn <- paste0 ("^.*", dir, "\\/") - fpath <- regmatches (block$file, regexpr (ptn, block$file)) - fpath_full <- gsub (fpath, paste0 (dir, "/"), block$file) + if (grepl (ptn, block$file)) { + fpath <- regmatches (block$file, regexpr (ptn, block$file)) + term_ptn <- "/" + } else { + # Generally only 'tests/testthat.R' where 'dir = tests/testthat' + term_ptn <- paste0 ("\\.", tools::file_ext (block$file)) + ptn <- paste0 ("^.*", dir, term_ptn, "$") + fpath <- regmatches (block$file, regexpr (ptn, block$file)) + } + fpath_full <- gsub (fpath, paste0 (dir, term_ptn), block$file) msg <- paste0 ( msg, " on line#", block_line, diff --git a/codemeta.json b/codemeta.json index 4eac039..5f0a5d2 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/srr", "issueTracker": "https://github.com/ropensci-review-tools/srr/issues", "license": "https://spdx.org/licenses/MIT", - "version": "0.1.3.010", + "version": "0.1.3.011", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R",