Skip to contents

Use with caution. This removes files from your computer. Clean one or more directories of files created by resmush_file().

Usage

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

Arguments

dir

A character vector of full path names. See the path argument in list.files().

suffix

Character. Defaults to "_resmush". See resmush_file().

recursive

Logical. Should the file search recurse into directories?

Value

Returns an invisible() NULL value and produces messages summarizing the process.

Examples

# \donttest{
# Simple example.

png_file <- system.file("extimg/example.png", package = "resmush")

# Copy to a temporary file with a given suffix.
suffix <- "_would_be_removed"
tmp_png <- file.path(
  tempdir(),
  paste0("example", suffix, ".png")
)

file.exists(tmp_png)
#> [1] FALSE
file.copy(png_file, tmp_png, overwrite = TRUE)
#> [1] TRUE

file.exists(tmp_png)
#> [1] TRUE

# Run with the default suffix. This should not remove the file.
resmush_clean_dir(tempdir())
#>  No files to clean in /tmp/Rtmpae8Dwc with suffix "_resmush".

file.exists(tmp_png)
#> [1] TRUE

# Use the matching suffix to remove the file.
resmush_clean_dir(tempdir(), suffix = suffix)
#>  Removing 1 file:
#> → /tmp/Rtmpae8Dwc/example_would_be_removed.png

file.exists(tmp_png)
#> [1] FALSE
# }