Flags bare T / F symbols that should be TRUE / FALSE. Operates on
the parsed syntax tree, so T inside a string or a comment is not reported,
which a plain text search could not tell apart. Named-argument names
(f(T = 1)) and $T / @T extractions are excluded.
Value
checktor_check_result() with passed, issues, message.
Source
No binding rule forbids T and F, though the CRAN Cookbook keeps a recipe for
it under
T/F Instead of TRUE/FALSE.
They are ordinary variables (see ?logical) that R sets to TRUE and FALSE at
startup but that any code can rebind, so a function reading T after something
has run T <- 0 gets the wrong answer. A real risk that no rule makes citable is
why this sits at robustness tier rather than policy. See vignette("check-sources", package = "checktor") for how every
check maps to its source.
Examples
# show_content defaults to TRUE, so the offending file prints first
pkg <- example_diagnose_scenario("code_examples/tf_usage_bad.R")
#> ── Example file: tf_usage_bad.R ────────────────────────────────────────────────
#> # Example file showing T/F usage issues
#> #' Process Data Function
#> #' @param data A data frame
#> #' @return Logical indicating success
#> process_data <- function(data) {
#> if (is.null(data)) {
#> return(F) # Issue: should be FALSE
#> }
#> has_complete_cases <- T # Issue: should be TRUE
#> if (has_complete_cases) {
#> cleaned_data <- data[complete.cases(data), ]
#> return(T) # Issue: should be TRUE
#> }
#> return(F) # Issue: should be FALSE
#> }
#> # Another function with T/F issues
#> validate_input <- function(x, strict = T) {
#> # Issue: should be TRUE
#> if (length(x) == 0) {
#> return(F)
#> } # Issue: should be FALSE
#> valid <- all(is.numeric(x))
#> return(valid && strict == T) # Issue: should be TRUE
#> }
#> ── End of example ──────────────────────────────────────────────────────────────
lab_tf_usage(pkg, verbose = FALSE)$issues
#> [1] "tf_usage_bad.R:8" "tf_usage_bad.R:11" "tf_usage_bad.R:15"
#> [4] "tf_usage_bad.R:18" "tf_usage_bad.R:22" "tf_usage_bad.R:25"
#> [7] "tf_usage_bad.R:29"
unlink(pkg, recursive = TRUE)