Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing pattern to dir_ls() silently gives wrong result #312

Open
jennybc opened this issue Jan 30, 2021 · 2 comments
Open

Providing pattern to dir_ls() silently gives wrong result #312

jennybc opened this issue Jan 30, 2021 · 2 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@jennybc
Copy link
Member

jennybc commented Jan 30, 2021

library(fs)

dir_ls()
#> DESCRIPTION                        LICENSE                            
#> LICENSE.md                         NAMESPACE                          
#> NEWS.md                            R                                  
#> README.Rmd                         README.md                          
#> _pkgdown.yml                       codecov.yml                        
#> cran-comments.md                   fs.Rproj                           
#> inst                               man                                
#> man-roxygen                        reprex72c8745a53e2_reprex.R        
#> reprex72c8745a53e2_reprex.spin.R   reprex72c8745a53e2_reprex.spin.Rmd 
#> revdep                             src                                
#> tests                              vignettes

dir_ls(regexp = "[.]yml$")
#> _pkgdown.yml codecov.yml

dir_ls(pattern = "[.]yml$")
#> DESCRIPTION                        LICENSE                            
#> LICENSE.md                         NAMESPACE                          
#> NEWS.md                            R                                  
#> README.Rmd                         README.md                          
#> _pkgdown.yml                       codecov.yml                        
#> cran-comments.md                   fs.Rproj                           
#> inst                               man                                
#> man-roxygen                        reprex72c8745a53e2_reprex.R        
#> reprex72c8745a53e2_reprex.spin.R   reprex72c8745a53e2_reprex.spin.Rmd 
#> revdep                             src                                
#> tests                              vignettes

Created on 2021-01-29 by the reprex package (v1.0.0.9000)

It's very easy for people to provide their filtering regex to dir_ls() via pattern à la list.files(), when what they really mean is regexp. And then pattern gets silently swallowed by ... in dir_ls() and path_filter(), resulting in no filtering at all. The docs say that ... gets passed along to grep(), but that doesn't happen in this case.

Discovered while debugging a puzzling error in usethis (r-lib/usethis#1336).

jennybc added a commit to r-lib/usethis that referenced this issue Jan 30, 2021
@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Dec 8, 2021
@gaborcsardi
Copy link
Member

fs does pass ... down to grep(), e.g. fixed is passed:

❯ dir_ls(regexp = ".", fixed = TRUE)
LICENSE.md             MAINTENANCE.md         NEWS.md
R-4.1.2-1-1.x86_64.rpm README.Rmd             README.md
_pkgdown.yml           codecov.yml            cran-comments.md
fs.Rproj

❯ dir_ls(regexp = ".")
DESCRIPTION            LICENSE                LICENSE.md
MAINTENANCE.md         NAMESPACE              NEWS.md
R                      R-4.1.2-1-1.x86_64.rpm README.Rmd
README.md              _pkgdown.yml           codecov.yml
cran-comments.md       fs.Rproj               inst
man                    man-roxygen            revdep
src                    tests                  vignettes

But fs also sets the pattern argument of grep() explicitly, in addition to passing it in .... R seems to silently ignore the one in ....

We'll fix this at some point.

@jennybc
Copy link
Member Author

jennybc commented Jan 11, 2024

I just puzzled myself with this again today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants