R/detect_generated_artifacts.R

Defines functions detect_generated_artifacts

Documented in detect_generated_artifacts

#' Detect operationally generated or low-priority artifacts
#'
#' @description
#' Detects generated, transient, synchronized, or operationally
#' low-priority resources commonly encountered in filesystem-based
#' reconstruction and preservation workflows.
#'
#' The function is designed for provenance-aware analytical pipelines
#' where generated artifacts may otherwise:
#'
#' - inflate duplication metrics;
#' - obscure meaningful reconstruction signals;
#' - introduce synchronization noise;
#' - or reduce review efficiency.
#'
#' Typical examples include:
#'
#' - generated website assets;
#' - transient editor files;
#' - synchronization metadata;
#' - cached rendering artifacts;
#' - font and frontend dependencies;
#' - local workspace history files.
#'
#' The function intentionally performs lightweight operational
#' classification rather than authoritative preservation appraisal.
#'
#' It is designed to work together with:
#'
#' - [read_snapshot()]
#' - [snapshot_to_reconstruction_context()]
#' - [classify_operational_file_type()]
#'
#' as part of layered provenance-aware reconstruction workflows.
#'
#' @param x A `data.frame` or tibble containing observed resources.
#'
#' @param filename Character scalar identifying the column containing
#'   filenames.
#'
#' Defaults to `"filename"`.
#'
#' @param extension Character scalar identifying the column containing
#'   file extensions.
#'
#' Defaults to `"extension"`.
#'
#' @param ignored_names Character vector of filenames commonly treated
#'   as generated, synchronized, transient, or operational noise.
#'
#' @param ignored_extensions Character vector of file extensions
#'   commonly associated with generated or low-priority artifacts.
#'
#' @return
#' A logical vector indicating whether each resource is likely to
#' represent a generated or operationally low-priority artifact.
#'
#' @details
#' The function intentionally uses lightweight operational heuristics.
#'
#' It does not:
#'
#' - inspect file contents;
#' - infer preservation value;
#' - determine archival significance;
#' - perform semantic interpretation;
#' - replace curatorial review.
#'
#' Classification is based primarily on:
#'
#' - filename heuristics;
#' - extension heuristics;
#' - operational workflow conventions.
#'
#' Future versions may support:
#'
#' - workflow-specific profiles;
#' - preservation-oriented review vocabularies;
#' - institution-specific ignore registries;
#' - synchronized workspace heuristics.
#'
#' @examples
#' toy_files <- tibble::tibble(
#'   filename = c(
#'     ".Rhistory",
#'     "app.css",
#'     "analysis.R",
#'     "font.woff2"
#'   ),
#'   extension = c(
#'     "",
#'     "css",
#'     "R",
#'     "woff2"
#'   )
#' )
#'
#' detect_generated_artifacts(
#'   toy_files
#' )
#'
#' @importFrom stats setNames
#' @export
detect_generated_artifacts <- function(
  x,
  filename = "filename",
  extension = "extension",
  ignored_names = c(
    ".Rhistory",
    ".RData",
    ".gitignore",
    ".DS_Store",
    "dir.c9r",
    "masterkey.cryptomator",
    "vault.cryptomator"
  ),
  ignored_extensions = c(
    "css",
    "js",
    "map",
    "woff",
    "woff2",
    "ttf",
    "c9r"
  )
) {
  if (!is.data.frame(x)) {
    stop(
      "x must be a data.frame or tibble",
      call. = FALSE
    )
  }

  if (!filename %in% names(x)) {
    stop(
      "Column not found: ",
      filename,
      call. = FALSE
    )
  }

  if (!extension %in% names(x)) {
    stop(
      "Column not found: ",
      extension,
      call. = FALSE
    )
  }

  ext <- tolower(x[[extension]])

  is_noise_name <-
    x[[filename]] %in% ignored_names

  is_generated_extension <-
    ext %in% ignored_extensions

  is_noise_name |
    is_generated_extension
}

Try the fscontext package in your browser

Any scripts or data that you put into this service are public.

fscontext documentation built on Nov. 19, 2026, 5:11 p.m.