check_unused_objects: Check all project files for objects that are created but...

View source: R/check_unused_objects.R

check_unused_objectsR Documentation

Check all project files for objects that are created but never used

Description

Recursively searches for R/Quarto files and applies check_unused_objects_single_file() to each, collating results.

Usage

check_unused_objects(
  root = ".",
  patterns = c("\\.R$", "\\.r$", "\\.Rmd$", "\\.rmd$", "\\.qmd$", "\\.Qmd$"),
  exclude_dirs = c(".git", "renv", "_site", "_freeze", ".quarto", "_book", "tools"),
  verbose = FALSE
)

Arguments

root

Character scalar. Directory to search from (default ".").

patterns

Character vector of regexes for file extensions to include. Defaults to common R and Quarto suffixes.

exclude_dirs

Character vector of directory names to skip anywhere in the path (default: c(".git","renv","_site","_freeze",".quarto","_book","tools")).

verbose

Logical; if TRUE, message progress (default FALSE).

Details

Supported extensions: .R, .r, .Rmd, .rmd, .qmd, .Qmd.

Value

A data frame with columns:

file

File path (character).

unused_objects

Name of an object that is created but never used (character).

One row per unused object. If none are found, returns an empty data frame with the two columns.

Examples

project <- file.path(tempdir(), "unused_objects_demo")
dir.create(project)
writeLines(
  c(
    "df1 <- data.frame(x = 1:3)",
    "df2 <- transform(df1, y = x * 2) # never used",
    "print(df1)"
  ),
  file.path(project, "analysis.R")
)
check_unused_objects(project)
unlink(project, recursive = TRUE)


psychdsish documentation built on Nov. 29, 2026, 5:07 p.m.