dir_recent: Find the most recent file in a directory that matches the...

View source: R/dir_recent.R

dir_recentR Documentation

Find the most recent file in a directory that matches the pattern

Description

Use the dir function and utils::tail to get the most recent file in a directory based on the saved name. This is only helpful when files are saved with a sequential naming system, typically this will be a form of the date as it is for PacFIN.Utilities when it saves .RData files.

Usage

dir_recent(dir = getwd(), pattern, casespecific = FALSE, verbose = FALSE)

Arguments

dir

The directory that you would like to search, either a full or relative path will work. The default is your current working directory.

pattern

A character string that you want to search for within dir using grep.

casespecific

A logical value specifying if the call to grep should be case specific. If FALSE, which is the default, then ignore.case = TRUE, i.e., ignore.case = !casespecific.

verbose

A logical value specifying if output should be printed to the console or not. The default is FALSE, which will suppress messages.

Value

A single file path to the most recent file within dir that matches the character string in pattern. The full path will be provided.

Author(s)

Kelli Faye Johnson

Examples

## Not run: 
dir_recent("data-raw", pattern = "Pac.+bds", verbose = TRUE)
dir_recent("data-raw", pattern = "Pac.+ft")

## End(Not run)

iantaylor-NOAA/Lingcod_2021 documentation built on Oct. 30, 2024, 6:42 p.m.