Skip to contents

The functions build a subset of an object of class fnames based on a vector of characters, either including them (with keep_fnames(invert = FALSE)) or excluding them (with keep_fnames(invert = FALSE) or drop_fnames()).

Usage

keep_fnames(x, y, invert = FALSE, ...)

drop_fnames(x, y, ...)

Arguments

x

An object of class fnames, to be filtered.

y

An object of class fnames or class types or a character vector. This is the filtering criterion.

invert

Boolean value. If TRUE, the elements in y are excluded rather than kept (and keep_fnames() behaves like drop_fnames())

...

Additional arguments.

Value

An object of class fnames.

Examples

all_fnames <- as_fnames(c("file1", "file2", "file3",
                          "file4", "file5", "file6"))

unwanted_fnames <- as_fnames(c("file1", "file4"))
keep_fnames(all_fnames, unwanted_fnames, invert = TRUE)
#> Filename collection of length 4
#>   filename
#>   --------
#> 1    file2
#> 2    file3
#> 3    file5
#> 4    file6
drop_fnames(all_fnames, unwanted_fnames)
#> Filename collection of length 4
#>   filename
#>   --------
#> 1    file2
#> 2    file3
#> 3    file5
#> 4    file6

wanted_fnames <- as_fnames(c("file3", "file5"))
keep_fnames(all_fnames, wanted_fnames)
#> Filename collection of length 2
#>   filename
#>   --------
#> 1    file3
#> 2    file5