Skip to content

Commit

Permalink
add 'rm_global_assign_in_memoise' fn; fixes #167
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Feb 21, 2023
1 parent 9b1cb26 commit 780f4df
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pkgcheck
Title: rOpenSci Package Checks
Version: 0.1.1.011
Version: 0.1.1.012
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265")),
Expand Down
43 changes: 43 additions & 0 deletions R/checks-left-assign.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pkgchk_left_assign <- function (checks) {
)

assigns <- rm_global_assign_in_ref_class (assigns, checks)
assigns <- rm_global_assign_in_memoise (assigns, checks)

assigns <- rowSums (assigns)
# rm `:=`:
Expand Down Expand Up @@ -148,6 +149,48 @@ rm_global_assign_in_ref_class <- function (assigns, checks) {
return (assigns)
}

# Remove any memoise global assigns in `.onLoad` fucntions (#167)
rm_global_assign_in_memoise <- function (assigns, checks) {

global_row <- which (rownames (assigns) == "<<-")
global <- assigns [global_row, ]
global <- global [global > 0]
if (length (global) == 0L) {
return (assigns)
}

global <- data.frame (
file = gsub (checks$pkg$path, "", names (global)),
n = as.integer (global)
)
global$file <- gsub (paste0 ("^", .Platform$file.sep), "", global$file)

loc_stats <- utils::getFromNamespace ("loc_stats", "pkgstats")
get_ctags <- utils::getFromNamespace ("get_ctags", "pkgstats")

loc <- loc_stats (checks$pkg$path)
has_tabs <- any (loc$ntabs > 0L)
tags <- withr::with_dir (checks$pkg$path, get_ctags ("R", has_tabs))
tags <- tags [which (tags$file %in% global$file), ]

for (f in unique (tags$file)) {

f_full <- fs::path (checks$pkg$path, f)
tags_f <- tags [which (tags$file == f), ]
onload_i <- which (tags_f$tag == ".onLoad")
if (length (onload_i == 1L)) {
onload_index <- seq (tags_f$start [onload_i], tags_f$end [onload_i])
tags_in_onload <- tags_f [tags_f$start %in% onload_index, ]
memoise_assign <- grep ("<<\\-\\s?memoise", tags_in_onload$content)
col_num <- match (f_full, colnames (assigns))
assigns [global_row, col_num] <- assigns [global_row, col_num] - length (memoise_assign)
}
}

return (assigns)
}


output_pkgchk_global_assign <- function (checks) {

out <- list (
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/pkgcheck",
"issueTracker": "https://github.com/ropensci-review-tools/pkgcheck/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.1.1.011",
"version": "0.1.1.012",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit 780f4df

Please sign in to comment.