Build an object of class fnames
.
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 matchingre_pattern
are the only ones retrieved. IfFALSE
, filenames matchingre_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:
base
print()
,as_data_frame()
,sort()
andsummary()
(which returns the number of items and of unique items),an interactive
explore()
method,a function to get the number of items
n_fnames()
,subsetting methods such as
keep_types()
,keep_pos()
, etc. including[]
subsetting (see brackets), as well as the specific functionskeep_fnames()
anddrop_fnames()
.
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