-
Notifications
You must be signed in to change notification settings - Fork 14
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
Helper to resolve conflicts #4
Comments
I played with this and you can "resolve" conflicts by smashing the definition in the environment in the search path (position 2 usually). For example, if you want dplyr::filter to win, then
so now that environment acts as a switching yard for conflicted functions. |
Currently, that environment is wiped out every time you load a new package, so I wouldn't recommend working in it at the moment. |
I think this is starting to look like an imports env that sits between the global env and the package envs. You could import single functions or whole packages at a time but importing a symbol that already exists in that environment would throw a warning (or an error?). Basically the same pattern as for packages' imports, but for (and shared by) users and sourced scripts. |
I don’t think this is an imports env, as we’d never support preferring packages as a whole. |
Even without this feature isn't it an imports env? I think allowing importing whole packages would be convenient, users could import stats or Biobase and move on to their script. It'd be nice to provide a shortcut to this env so you can do: .imports$lag <- stats::lag The |
That is definitely not the intent of the conflicts package. |
Rather than (or pehaps along with?) making a given function from a package able to always win a conflict, would it make sense to be able to define the result of a single specific conflict between two packages? As an example, I use Essentially, I would like to be able to specify that when conflicted::win(dplyr::filter, stats::filter) Perhaps this could be extended to a form of |
Yeah I very much like that idea - then This will probably need to wait until I employ a different strategy for computing the conflicts, and after a thorough review of the other means of conflict resolution that we need. |
Latest syntax iteration: conflict_prefer("filter", "dplyr")
#> [conflicted] will prefer dplyr::filter() over any other package
conflict_prefer("filter", "dplyr", "base")
#> [conflicted] will prefer dplyr::filter() over base::filter() |
This is from a discussion I had with @hadley about resolving conflicts.
The recommended solution is to assign a value in the global env, like this:
This is a little fragile and changes the behavior from normal. For example, a user might clear their workspace by pressing the broom button in RStudio, or by doing
rm(list=ls())
, and that would reset the conflict resolution without any indication that it's happening.Another issue is that it introduces a slight change in the way R behaves when you assign a value with the same name as a function.
Normally, if you assign a variable with the same name as a function, you can still call the function as normal:
But if you've resolved a conflict by assigning it in the global env, then assigning a value to the same name will undo the resolution. For example:
One possible solution that @hadley suggested is to add a function
win
:The drawbacks here are that it's one more thing to learn, and that the package would need to have an exported function.
The text was updated successfully, but these errors were encountered: