check_unused_objects_single_file: Check for objects that are created but never used within a...

View source: R/check_unused_objects_single_file.R

check_unused_objects_single_fileR Documentation

Check for objects that are created but never used within a file

Description

Parses an R script or an R/Quarto document, extracts the R code, and reports symbols that are assigned to but never referenced anywhere else in the same file. Supports .R, .Rmd, and .qmd (R code chunks only for the latter two).

Usage

check_unused_objects_single_file(path)

Arguments

path

Character. Path to a file.

Value

A data frame with one column, unused_objects, listing orphaned objects. Returns an empty data frame if no orphans are found.

Examples

path <- tempfile(fileext = ".R")
writeLines(
  c(
    "df1 <- data.frame(x = 1:3)",
    "df2 <- transform(df1, y = x * 2) # never used",
    "print(df1)"
  ),
  path
)
check_unused_objects_single_file(path)
unlink(path)


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