Skip to contents

Flags print() / cat() calls not guarded by an enclosing if(), for(), or while(). The check uses the ancestor axis, so guard detection is robust regardless of formatting. Calls inside S3 print.* and format.* methods are exempt, since cat() is the required idiom there (base R's own print.default() / print.lm() use it).

Usage

lab_print_cat_usage(path = ".", verbose = TRUE, parsed = NULL)

Arguments

path

Character. Path to package directory.

verbose

Logical. Print diagnostic messages.

parsed

Internal. Pre-parsed source cache; if NULL, files are read from path on demand.

Value

checktor_check_result() with passed, issues, message.

Source

The CRAN Cookbook covers this under Using print()/cat(). Diagnostic output belongs in message() or warning(), which a user can suppress, rather than in cat() or print(), which they cannot. Neither the Repository Policy nor Writing R Extensions states this, but reviewers ask for it consistently. See vignette("check-sources", package = "checktor") for how every check maps to its source.

Examples

pkg <- example_diagnose_scenario("code_examples/print_cat_bad.R",
                                 show_content = FALSE)
lab_print_cat_usage(pkg, verbose = FALSE)$issues
#> [1] "print_cat_bad.R:6"  "print_cat_bad.R:9"  "print_cat_bad.R:14"
#> [4] "print_cat_bad.R:21" "print_cat_bad.R:24" "print_cat_bad.R:26"
unlink(pkg, recursive = TRUE)