Skip to contents

Build an object of class fnames.

Usage

get_fnames(
  path = ".",
  re_pattern = NULL,
  recursive = TRUE,
  perl = TRUE,
  invert = FALSE
)

Arguments

path

The location of the files to be listed.

re_pattern

Optional regular expression. If present, then only the filenames that match it are retrieved (unless invert = TRUE, in which case those filenames are excluded). The match is done over the absolute path of the files.

recursive

Boolean value. Should the subdirectories of path also be searched?

perl

Boolean value. Whether re_pattern should be interpreted as a PERL flavor of regular expression.

invert

Boolean value. If TRUE, filenames matching re_pattern are the only ones retrieved. If FALSE, filenames matching re_pattern are excluded.

Value

An object of class fnames, which is a special kind of character vector storing the absolute paths of the corpus files. It has additional attributes and methods such as:

Additional manipulation functions includes fnames_merge() to combine filenames collections and the short_names() family of functions to shorten the names.

Objects of class fnames can be saved to file with write_fnames(); these files can be read with read_fnames().

It is possible to coerce a character vector into an fnames object with as_fnames().

Examples

# \donttest{
cwd_fnames <- get_fnames(recursive = FALSE)
# }
cwd_fnames <- as_fnames(c("file1", "file2", "file3"))
cwd_fnames
#> Filename collection of length 3
#>   filename
#>   --------
#> 1    file1
#> 2    file2
#> 3    file3
print(cwd_fnames)
#> Filename collection of length 3
#>   filename
#>   --------
#> 1    file1
#> 2    file2
#> 3    file3
as_data_frame(cwd_fnames)
#> Warning: `as_data_frame()` was deprecated in tibble 2.0.0.
#> Please use `as_tibble()` instead.
#> The signature and semantics have changed, see `?as_tibble`.
#> # A tibble: 3 × 1
#>   filename
#>   <fnames>
#> 1 file1   
#> 2 file2   
#> 3 file3   
as_tibble(cwd_fnames)
#> # A tibble: 3 × 1
#>   filename
#>   <fnames>
#> 1 file1   
#> 2 file2   
#> 3 file3   

sort(cwd_fnames)
#> Filename collection of length 3
#>   filename
#>   --------
#> 1    file1
#> 2    file2
#> 3    file3

summary(cwd_fnames)
#> Filename collection of length 3