diff --git a/DESCRIPTION b/DESCRIPTION index 7c25255..babe8bd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: srr Title: 'rOpenSci' Review Roclets -Version: 0.1.3.018 +Version: 0.1.3.019 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 d6721d9..a468c16 100644 --- a/R/roclet.R +++ b/R/roclet.R @@ -218,6 +218,31 @@ check_block_title <- function (block, tag) { } } +get_fn_name_from_block <- function (block) { + func_name <- block$object$alias + if (is.null (func_name)) { + pd <- tryCatch ( + utils::getParseData (parse (text = deparse (block$call))), + error = function (e) NULL + ) + if (!is.null (pd)) { + if (nrow (pd) > 0L) { + + pd <- pd [-(which (pd$token == "expr")), ] + if (nrow (pd) >= 3L) { + if (pd$token [1] == "SYMBOL" && + pd$token [2] == "LEFT_ASSIGN" && + pd$token [3] == "FUNCTION") { + func_name <- pd$text [1] + } + } + } + } + } + + return (func_name) +} + #' process_srrstats_tags #' #' @param fn_name Include name of calling function in message? @@ -236,16 +261,7 @@ process_srrstats_tags <- function (tag = "srrstats", block, msg <- paste0 ("[", paste0 (snum, collapse = ", "), "]") if (fn_name) { - func_name <- block$object$alias - if (is.null (func_name)) { - pd <- utils::getParseData (parse (text = deparse (block$call))) - pd <- pd [-(which (pd$token == "expr")), ] - if (pd$token [1] == "SYMBOL" && - pd$token [2] == "LEFT_ASSIGN" && - pd$token [3] == "FUNCTION") { - func_name <- pd$text [1] - } - } + func_name <- get_fn_name_from_block (block) if (!is.null (func_name)) { msg <- paste0 (msg, " in function '", func_name, "()'") } diff --git a/codemeta.json b/codemeta.json index 5db13ae..ef67662 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.018", + "version": "0.1.3.019", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R",