
Detect Lost Glue Brace in glue and cli Expressions
Source: R/14A_package_lost_glue_brace.R, R/14_detect_lost_glue_brace.R
detect_lost_glue_brace.RdCheck whether { and } are balanced in all glue() / glue_data()
and cli_*() string arguments within R source files. Each file is parsed
into an AST, then every string literal passed to a target function is checked
with a stack-based brace matcher. Any mismatch is reported with its line
number and a visual caret (^^^^) marker under the problematic region.
Usage
package_lost_glue_brace(
path = NULL,
dirs = c("R", file.path("tests", "testthat")),
test_included = lifecycle::deprecated(),
...
)
detect_lost_glue_brace(path = NULL, verbose = TRUE, ...)Arguments
- path
For
detect_lost_glue_brace(): path to an R file. IfNULLand RStudio is available, the active document path is used.For
package_lost_glue_brace(): path to the root directory of an R package. Defaults to the current directory.- dirs
Character vector of package-relative directories scanned by
package_lost_glue_brace(). Defaults to"R"and"tests/testthat".- test_included
. Logical indicating whether to scan
tests/testthat/in addition toR/. Usedirsinstead. When supplied,FALSEscans onlyR/;TRUEscans both default directories.- ...
Unused.
- verbose
Whether to emit detection results to the console. Package scanning disables this and supplies its own progress and summary output.
Single file vs package scope
detect_lost_glue_brace()Operates on one R file. When
pathisNULLand RStudio is available, the currently active document path is used.package_lost_glue_brace()Scans
.Rfiles under the configured package-relative directories. By default, these areR/andtests/testthat/.
Examples
# \donttest{
file <- tempfile(fileext = ".R")
writeLines('glue("{a")', file)
detect_lost_glue_brace(file)
#> glue("{a")
#> ^^
#> ✖ Found 1 line with mismatched braces: 1
# }