latest_file: Get paths of files using file name ordering

View source: R/file_tools.R

latest_fileR Documentation

Get paths of files using file name ordering

Description

Looks for files in a directory path with file name matching pattern. The path of the nth file, ordered alphabetically by file name is returned. "File name" here refers to the part of the path without any directory names i.e. the part following the final "/".

The intended use is with files names with matching structure with well-ordered numeric endings, such as "yyyy-mm-dd" or fixed length numeric ids. Output may not be as intended if comparing files with different structures.

Usage

latest_file(
  path = ".",
  pattern = NULL,
  ext = NULL,
  n = 1L,
  decreasing = TRUE,
  ...
)

Arguments

path

A string path name for the directory to search in.

pattern

A string pattern to filter file names by. The pattern is only applied to the part of the path following the final "/".

ext

An optional string giving a file extension which the returned file name must end in. The supplied extension is checked for an exact match (ignoring case) to the last extension in the file name.

n

Integer. Return the nth file path. This can have length > 1, in which case multiple file paths are returned. An error will be thrown if there are insufficient matches.

decreasing

Logical passed to order(). By default returns the (nth) largest value.

...

Other arguments passed to fs:dir_ls(). The argument type is always set to "file" and so must not be supplied. Arguments regexp or glob are applied to the full file path and so affect output differently than pattern.


jedwards24/edwards documentation built on Sept. 2, 2023, 8:16 a.m.