-
Notifications
You must be signed in to change notification settings - Fork 13
Add pkgchk_uses_dontrun()
as a watch check
#246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
pkgchk_uses_dontrun()
as a watch check
Thanks @ateucher. Print method will be improved by #247. It's currently off by default unless checks are listed there, but that will make for easier and more sensible default print behaviour. This is also a great test case for #248, because this check should definitely ✖️ if all examples are |
Ah, that's a good idea to have an ✖️ if all are |
However, wouldn't it be nice if all those were covered by |
Been attempting exactly that here, and with that demonstrating that sometimes |
@ateucher What's the status here? Tests and checks fail only because you need to run locally and then
|
R/check-uses-dontrun.R
Outdated
|
||
parsed_rds <- lapply( | ||
rd_files, | ||
tools::parse_Rd, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to be in tryCatch()
, because parse_Rd
can and does error on un-parseable files.
R/check-uses-dontrun.R
Outdated
any(grepl("\\dontrun", rd_char, fixed = TRUE)) | ||
}, | ||
logical(1) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, interesting, parse_Rd
completely strips \dontrun
. Made me curious, so I found the cause here. That also shows that the initial .Rd_get_section()
internal function is the one that grabs everything. And that then leads to this:
get_Rd_section <- utils::getFromNamespace (".Rd_get_section", "tools")
path <- "/<path>/<to>/<repo>/man"
rd_files <- fs::dir_ls (path, type = "file", regexp = "\\.Rd$")
parsed_rds <- lapply (rd_files, tools::parse_Rd)
rd_example_tags <- lapply (parsed_rds, function (e) {
ex <- get_Rd_section (e, "examples")
tags <- vapply (ex, function (exi) attr (exi, "Rd_tag"), character (1L))
setdiff (tags, "RCODE") # Most tags are "RCODE" so remove those
})
That list can then be examined for \\dontrun
, and enables proper counts for each example and overall. And your fn_names
code can also be largely removed, and the code here modified to include function names as well, using Rd_get_section
which works same as Rd_get_metadata
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I discovered .Rd_get_section()
as well, thanks for the snippet!
Sorry for the delay @mpadge. I'll get back to this in the next few days! |
* Use tryCatch when parsing Rd files * Use .Rd_get_section to pull out examples * Different summary if all vs some examples use dontrun
This closes #238 when merged.
I thought it made sense for this to be a "watch" check, since there are valid reasons to use
\dontrun{}
in examples.I didn't add tests as I couldn't see an obvious pattern of how to do it by looking at existing test. I did run this on several of my local packages.
One thing I'm not sure about is the print method - I don't see it getting printed, only the summary, and wasn't sure how to trigger that (i.e., see the list of functions that use
dontrun{}
.Please see my comment on line 37-38 - I was able to extract the
dontrun{}
sections from the Rd files, but the code is much harder to read. Usinggrepl()
on the character representation is clearer and I can't think of a situation where that search would return a false positive or a false negative.Running it on
pkgcheck
gives:Created on 2025-06-21 with reprex v2.1.1