Last active
April 25, 2024 06:43
-
-
Save MichaelChirico/fa98c9826716fb179092739d254f129d to your computer and use it in GitHub Desktop.
Check all Recommended packages for partial matching issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setwd(tempdir()) | |
pmatchRe = "partial( argument)? match" | |
write_strict_profile = function(path = ".Rprofile") { | |
writeLines(con=path, c( | |
"options(warnPartialMatchArgs=TRUE, warnPartialMatchAttr=TRUE, warnPartialMatchDollar=TRUE)", | |
sprintf("globalCallingHandlers(warning=function(c) if (grepl('%s', conditionMessage(c))) stop(c) else warning(c))", pmatchRe) | |
)) | |
} | |
clone_cran_mirror = \(pkg) system2("git", c("clone", "-q", sprintf("https://github.com/cran/%s.git", pkg))) | |
check_tests_for_pmatch = function(pkg = ".") { | |
tests = list.files(file.path(pkg, 'tests'), pattern='[.][rR]$', full.names=TRUE) | |
for (t in tests) local({ | |
system2("R", c("CMD", "BATCH", t)) | |
tmp = paste0(basename(t), "out") | |
on.exit(unlink(tmp)) | |
l = grep(pmatchRe, readLines(tmp), value=TRUE) | |
if (length(l)) message(t, "\n", l) | |
}) | |
} | |
recPkgs = available.packages() |> | |
as.data.frame() |> | |
subset(riority=='recommended') |> | |
rownames() | |
write_strict_profile() | |
for (pkg in recPkgs) { | |
clone_cran_mirror(pkg) | |
check_tests_for_pmatch(pkg) | |
unlink(pkg, recursive=TRUE) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment