Skip to contents

This function lists all files in a directory (and subdirectories) that match the specified file extensions. It can be used as a helper to find files paths to pass to convert_files() and convert_files_inplace(), or to preview which files those functions, as well as convert_dir() and convert_dir_inplace() will look to convert. It can also be used as input to output_paths() to help generate output paths for new files.

Usage

files_to_convert(
  dir,
  full.names = FALSE,
  extensions = c("R", "r", "qmd", "rmd", "Rmd")
)

Arguments

dir

A character string specifying the directory path to search

full.names

Logical. If TRUE, returns full file paths rather than relative paths. Default is FALSE.

extensions

A character vector of file extensions to filter by. Default is c("R", "r", "qmd", "rmd", "Rmd"). If NULL or empty, returns all files.

Value

A character vector of file paths that match the specified extensions.

Examples

example_dir <- example_dir() # Get examples directory
files_to_convert(example_dir)
#> [1] "nested/penguins.qmd" "no_penguins.Rmd"     "penguins.R"         
files_to_convert(example_dir, full.names = TRUE)
#> [1] "/home/runner/work/_temp/Library/basepenguins/extdata/nested/penguins.qmd"
#> [2] "/home/runner/work/_temp/Library/basepenguins/extdata/no_penguins.Rmd"    
#> [3] "/home/runner/work/_temp/Library/basepenguins/extdata/penguins.R"         
files_to_convert(example_dir, extensions = "R")
#> [1] "penguins.R"
files_to_convert(example_dir, extensions = NULL) # all files
#> [1] "nested/not_a_script.md" "nested/penguins.qmd"    "no_penguins.Rmd"       
#> [4] "penguins.R"