select_by_file_extension function

Select string that end in a particular way (e.g. a certain file extension)

Select string that end in a particular way (e.g. a certain file extension)

Sometimes it makes sense to apply a function to several files in a folder, but only to those of a particular file type. This function can selects all elements in a vector of strings that end in a particular way, e.g. on a common file extension.

select_by_file_extension(strings, file_extension)

Arguments

  • strings: vector of character strings for elements to be extracted from.
  • file_extension: character string specifying the extension of the file type to be selected. This can also be any other trailing string that marks all vector elements to be selected.

Returns

subset of the strings vector that only contains the elements that end on file_extension.

Examples

select_by_file_extension(c("Temp1.csv","Temp1.xls","Temp2.csv","Temp2.xls"),"csv") select_by_file_extension(c("red car","blue car","yellow duck"), "car")

Author(s)

Eike Luedeling

  • Maintainer: Eike Luedeling
  • License: GPL-3
  • Last published: 2024-11-14

Useful links