Skip to contents

This function builds a mapping between local files and their target paths in repositories, supporting both individual file mapping and bulk directory processing.

Usage

file_mapping(
  ...,
  dir = NULL,
  pattern = NULL,
  target_prefix = "",
  preserve_structure = FALSE,
  quiet = FALSE
)

Arguments

...

Named arguments where names are local file paths and values are repository paths

dir

Character string specifying a directory to search for files. Default is NULL.

pattern

Character string with a regular expression pattern to match files in dir. Default is NULL.

target_prefix

Character string to prefix to all target paths. Default is "".

preserve_structure

Logical indicating whether to preserve directory structure in target. Default is FALSE.

quiet

Logical; if TRUE, suppresses information messages. Default is FALSE.

Value

Returns an object of class "file_mapping" (which is just a marked up "list") containing:

  • A named list where each entry maps a local file path (name) to a target repository path (value)

  • Each key is the full path to a local file

  • Each value is the corresponding path where the file should be placed in repositories

Details

The dir argument requires a valid directory path currently on the local filesystem. This directory is scanned for files matching the pattern regular expression, and each file is mapped to a target path in repositories. If the directory is not found, an error is thrown.

See also

print.file_mapping() to display the mapping in a formatted way.

Examples

# Map individual files with explicit source-to-target paths
mapping <- file_mapping(
  "local/path/ci.yml" = ".github/workflows/ci.yml",
  "local/path/lint.R" = ".lintr"
)
#> ! Local file does not exist: local/path/ci.yml
#> ! Local file does not exist: local/path/lint.R
#>  Created file mapping with 2 files

# Automatically map all R files from a directory to backup/R2/
workflow_mapping <- file_mapping(
  dir = system.file(package = "multideploy"),
  pattern = "\\.R$",
  target_prefix = "backup/R2/"
)
#> ! No files found in directory /home/runner/work/_temp/Library/multideploy

# Preserve directory structure when mapping files
template_mapping <- file_mapping(
  dir = system.file(package = "multideploy"),
  preserve_structure = TRUE
)
#>  Created file mapping with 20 files

# Combine explicit mappings with directory-based mappings
combined_mapping <- file_mapping(
  "specific/file.R" = "R/functions.R",
  dir = system.file(package = "multideploy"),
  target_prefix = ".github/"
)
#> ! Local file does not exist: specific/file.R
#>  Created file mapping with 21 files