-
Notifications
You must be signed in to change notification settings - Fork 23
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
Improve find_root()
#83
Conversation
Thanks. To avoid mismatch between the other |
@krlmlr I've updated my PR to modify |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Current Aviator status
This PR was closed without merging. If you still want to merge this PR, re-open it. See the real-time status of this PR on the Aviator webapp. Use the Aviator Chrome Extension to see the status of your PR within GitHub.
|
See #96 for advice on running the tests. |
Thanks for the hint. I've overhauled the PR, should be good to go now. |
Thanks for your work on this. I now realize that my request to add a new argument to How do you like I prefer small focused PRs. Happy to review a separate PR for the last two bullet points first. I can also work with your commits and create suitable PRs. |
Lol. 😄 That was my initial approach with
Seems a bit "bumpy language" to me... but has the upside of "referring" to Some half-baked alternative suggestions:
In the end, I'd prefer the initially suggested
|
Yes. The initial proposal was nice. Again, sorry. I'm really having a hard time coming to terms with the
Did we discuss the motivation for this feature? What does the caller do if there's no root? I wonder if returning |
Hm, that is more appealing indeed. Especially if more "root"-specific functions should be added in the future! Regarding refactoring: I think I could do this in another PR if you'd like. I would make
No, I don't think so. My motivation is that I'd like to have a "native" way to logically check whether root criterion(s) are fulfilled. I.e. instead of !inherits(try(rprojroot::find_root(my_criterions),
silent = TRUE),
what = "try-error")
I'm not sure if I understand your question. In the first place, the caller is able to learn whether a root exists or not without the risk of throwing an error (or having to defuse
I think the proper way to maintain type stability is returning empty vectors of the proper type instead of |
Thank you for your patience with this. Can we please discuss the motivation first? This may influence the implementation. After the caller calls After the caller calls Do you have a practical use case in mind? Or is it just to get a clean interface that doesn't use conditions in the case of no root? |
Sure. I consider rprojroot's root criterions a suitable central place to define how a certain project type (R package, R package with testthat set up, pkgdown site etc. pp.) is to be detected, i.e. to collect and "standardize" this knowledge. If such a root criterion is updated or corrected/improved (like e.g. in #88), all the downstream rprojroot users benefit from it. The information whether a path is part of a certain project type can be leveraged in various ways. I don't think we can and should try to anticipate them in such detail as your questions imply. But to give an example: Does this answer your questions? |
Thanks again for your patience. Objects of class I understood your proposal in the following way: walk from the current directory to the root, return To move forward, I'll extract the test changes that are unrelated to the functionality into a separate PR. Is there a way to resolve #84 independently of this discussion? |
and purge `has_root()`
This should preserve the function's original intentions while still a) checking all criterion subdirs and b) offering the `logical` param.
The test changes were already merged independently. The least invasive and easiest way would be to return a classed condition, perhaps of class The other useful extension I can think of is to add an accessor function Let's discuss #84 separately. Sorry it took me so long to arrive at a conclusion here. |
rprojroot::is_pkgdown_project$testfun |>
purrr::map_lgl(\(x) x(path = path)) |>
any() I'd like to introduce an additional if (check_parent_dirs) {
result <- rprojroot::root_has(criterion = rprojroot::is_pkgdown_dir,
path = path)
} else {
result <-
rprojroot::is_pkgdown_dir$testfun %>%
purrr::map_lgl(~ .x(path = path)) %>%
any()
}
result
Yes, the necessary changes to
You mean to change
If I understand correctly, this would be +/- the same as introducing a dedicated |
tryCatch({ find_root(); TRUE }, rprojroot_not_found = function(e) FALSE) looks straightforward to me. If we agree on the classed condition, the question becomes: do we add an exported function in rprojroot for this one-liner? The answer to that question might be "no", or perhaps "yes" if we manage to find a good name and interface logic. Currently, we're in a place like "We want this new functionality, but we need a new function because of type stability, and naming is hard." The classed condition would get us to "We have the new functionality, the next step is to wrap it up nicely, but everybody can do the wrapping in their code today if needed." The new |
Ok, I see. I guess my aversion against error handling was unsubstantiated. Looks like an elegant way forward 👍
Got it. This seems like a sensible building block. How do we proceed? Do you want me to submit a PR adding classed conditions to |
Thanks. Yes, a classed condition would be nice. Do we want |
The |
|
This PR
adds a param
logical
tofind_root()
, which ifTRUE
, makes the fn return a boolean instead of a path or throwing an error.This allows for tests such as whether a certain path is the root of or below the root of an R package using
rprojroot::find_root(rprojroot::is_r_package, "/PATH/TO/WHEREVER", logical = TRUE)
.makes
find_root()
check all criterion subdirs, not just the first existing one, thus fixessubdir
concept seems flawed #84.fixes an example and re-roxygenizes the package (minor changes). superseded by fix: Fix example for
find_root()
#98replaces
mockr::with_mock()
withtestthat::local_mocked_bindings()
in tests. superseded by test: Replace mockr withtestthat::local_mocked_bindings()
#97