R list files with multiple conditions

前端 未结 6 1266
梦谈多话
梦谈多话 2020-12-28 14:03

I want to list all files in a directory that met certain conditions (date and currency). So with only one condition the argument pattern in list.files

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-28 14:51

    If you want to preserve your pattern as a vector (if you are using this in a package function and want to allow the user to specify the pattern as a vector instead of having them use | or *), you can set it up like this:

    pattern1 = c('20130801','USD')
    file.ls <- list.files(path='~/DATA/PiP/Curvas/', pattern=paste0(pattern1, collapse="|"))
    

    This also allows the pattern1 vector to contain as many elements as you want without having to adjust your code.

提交回复
热议问题