resmush_clean_dir: Remove output files from directories

View source: R/resmush_clean_dir.R

resmush_clean_dirR Documentation

Remove output files from directories

Description

Use with caution. Remove files that match suffix from one or more directories. This is intended to clean output files created by resmush_file() or resmush_dir().

Usage

resmush_clean_dir(dir, suffix = "_resmush", recursive = FALSE)

Arguments

dir

A character vector of directory paths. See the path argument of list.files().

suffix

A character string containing the suffix pattern used to identify files. The value is interpreted as a regular expression. The default is "_resmush", the default suffix used by resmush_file().

recursive

Logical. Should the file search recurse into directories?

Value

An invisible() NULL. Messages list the files selected for removal.

See Also

resmush_file() and resmush_dir() create the suffixed output files that this function removes.

Examples


# Create a temporary file with a suffix to remove.
png_file <- system.file("extimg/example.png", package = "resmush")
suffix <- "_would_be_removed"
tmp_png <- file.path(
  tempdir(),
  paste0("example", suffix, ".png")
)

file.exists(tmp_png)
file.copy(png_file, tmp_png, overwrite = TRUE)

file.exists(tmp_png)

# Run with the default suffix. This should not remove the file.
resmush_clean_dir(tempdir())

file.exists(tmp_png)

# Use the matching suffix to remove the file.
resmush_clean_dir(tempdir(), suffix = suffix)

file.exists(tmp_png)


resmush documentation built on July 2, 2026, 5:07 p.m.