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

Make dir_tree() work even when glob= or regexp= argument is supplied #442

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JoshOBrien
Copy link

@JoshOBrien JoshOBrien commented Feb 5, 2024

This PR addresses the issue described in #398. dir_tree() didn't work when a pattern was supplied to regexp= or glob= arguments that get passed on to dir_ls(). That's because the list of file paths returned by those calls to dir_ls() did not include paths of the parent (and grandparent etc.) directories that dir_tree() uses to construct the tree.

The code I've added uses the file paths returned by dir_ls() to recreate the directory paths that'll be needed to build the tree.

To see that this now works, try for example:

dir_tree(system.file(package = "fs"), regexp = "[.]rds$")
## C:/R/Library/fs
## ├── help
## │   ├── aliases.rds
## │   └── paths.rds
## └── Meta
##     ├── features.rds
##     ├── hsearch.rds
##     ├── links.rds
##     ├── nsInfo.rds
##     ├── package.rds
##     └── Rd.rds

dir_tree(system.file(package = "fs"), type = "directory")
## C:/R/Library/fs
## ├── help
## │   └── figures
## ├── html
## ├── libs
## │   └── x64
## ├── Meta
## └── R

This PR addresses the issue described in r-lib#398. `dir_tree()` didn't work when a pattern was supplied to `regexp=` or `glob=` arguments that get passed on to `dir_ls()`. That's because the list of file paths returned by those calls to `dir_ls()` did not include paths of the parent (and grandparent etc.) directories that `dir_tree()` uses to construct the tree.

The code I've added uses the file paths returned by `dir_ls()` to recreate the directory paths that'll be needed to build the tree.

To see that this now works, try for example:

```r
dir_tree(system.file(package = "fs"), regexp = "[.]rds$")
dir_tree(system.file(package = "fs"), type = "directory")
```
Files should come before directories at each level in tree. Fixed code
to ensure that happens.
@JoshOBrien JoshOBrien changed the title Make dir_tree() work even when glob or regexp is used Make dir_tree() work even when glob= or regexp= argument is supplied Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant