This function takes a vector of file paths and returns a vector of modified paths
with prefixes and/or suffixes added to the filenames. It's useful for generating
output paths for the convert_files()
and convert_dir()
functions.
files_to_convert()
is useful for generating the input paths
.
Arguments
- paths
A character vector of file paths to modify
- prefix
A character string to add at the beginning of each filename. Default is the empty sting
""
.- suffix
A character string to add at the end of each filename, before the extension. Default is
"_new"
.- dir
An optional character string specifying the output directory. If provided, the modified filenames will be placed in this directory. This is useful if
paths
are relative and a different output directory is required. Default isNULL
.
Value
A character vector of modified file paths with the specified prefixes and suffixes. The original paths are preserved as names of the returned vector.
Examples
# Get all convertible files from examples directory
input_files <- files_to_convert(example_dir())
# Generate output paths with "_converted" suffix
output_paths(input_files, suffix = "_converted")
#> nested/penguins.qmd no_penguins.Rmd
#> "nested/penguins_converted.qmd" "no_penguins_converted.Rmd"
#> penguins.R
#> "penguins_converted.R"
# Add both prefix and suffix and place in a new directory
output_paths(
input_files,
prefix = "base_",
suffix = "_converted",
dir = "~/new_dir"
)
#> nested/penguins.qmd
#> "~/new_dir/nested/base_penguins_converted.qmd"
#> no_penguins.Rmd
#> "~/new_dir/base_no_penguins_converted.Rmd"
#> penguins.R
#> "~/new_dir/base_penguins_converted.R"