Skip to content

Commit

Permalink
separate 'get_fn_name_from_block' fn for #44
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Oct 7, 2024
1 parent ead7277 commit b9de713
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand Down
36 changes: 26 additions & 10 deletions R/roclet.R
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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, "()'")
}
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b9de713

Please sign in to comment.