Skip to contents

The get_files function generates a list of files (default .csv, can be optionally set to .sav) in the working directory that contain a specified keyword in their names. If no keyword is provided, it returns all files of the specified type.

Usage

get_files(keyword = NULL, filetype = "csv")

Arguments

keyword

A character string. Only files containing this keyword in their names will be included in the returned list. The search is case-sensitive. Default is NULL.

filetype

A character string. Specifies the type of files to be retrieved. Can be "csv" (default) or "sav".

Value

A character vector of file names that matched the criteria.

Details

The function uses the list.files() and grepl() functions to retrieve all files of the specified type in the working directory. If a keyword is provided, it filters the list to include only those files whose names contain the keyword.

References

This function relies on base R functions list.files() and grepl().

Examples

if (FALSE) {
# Assume we have the following files in our working directory:
# "Alcohol_Study1.csv", "Alcohol_Study2.csv", "Other_Study.sav"

# Get all 'Alcohol' related .csv files
get_files("Alcohol")
# This will return: c("Alcohol_Study1.csv", "Alcohol_Study2.csv")

# Get all .sav files
get_files(filetype = "sav")
# This will return: c("Other_Study.sav")
}