conflicted icon indicating copy to clipboard operation
conflicted copied to clipboard

Should this package set `options(conflicts.policy = list(warn = FALSE))` when attaching?

Open krlmlr opened this issue 10 months ago • 6 comments

We implement a stricter conflict resolution system here. Would be useful for reprexes and vignettes.

krlmlr avatar Feb 21 '25 19:02 krlmlr

When attaching, you mean? Sounds reasonable to me, although I'd appreciate a link to the relevant docs.

hadley avatar Feb 21 '25 21:02 hadley

See the "Conflicts" section in https://rdrr.io/r/base/library.html :

Conflicts

Handling of conflicts depends on the setting of the conflicts.policy option. If this option is not set, then conflicts result in warning messages if the argument warn.conflicts is TRUE. If the option is set to the character string "strict", then all unresolved conflicts signal errors. Conflicts can be resolved using the mask.ok, exclude, and include.only arguments to library and require. Defaults for mask.ok and exclude can be specified using conflictRules.

If the conflicts.policy option is set to the string "depends.ok" then conflicts resulting from attaching declared dependencies will not produce errors, but other conflicts will. This is likely to be the best setting for most users wanting some additional protection against unexpected conflicts.

The policy can be tuned further by specifying the conflicts.policy option as a named list with the following fields:

error:

logical; if TRUE treat unresolved conflicts as errors.

warn:

logical; unless FALSE issue a warning message when conflicts are found.

generics.ok:

logical; if TRUE ignore conflicts created by defining S4 generics for functions on the search path.

depends.ok:

logical; if TRUE do not treat conflicts with required packages as errors.

can.mask:

character vector of names of packages that are allowed to be masked. These would typically be base packages attached by default.

krlmlr avatar Feb 21 '25 22:02 krlmlr

Seems like setting this option amounts to adding warn.conflicts = FALSE to each library() call.

krlmlr avatar Feb 21 '25 22:02 krlmlr

We already have to shim library() so I'm not sure what this would get us.

hadley avatar Feb 24 '25 15:02 hadley

I want the following to be silent. How to achieve?

library(conflicted)
library(duckplyr)
#> Loading required package: dplyr
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#> ✔ Overwriting dplyr methods with duckplyr methods.
#> ℹ Turn off with `duckplyr::methods_restore()`.

Created on 2025-02-24 with reprex v2.1.1

krlmlr avatar Feb 24 '25 15:02 krlmlr

Ooooh it's because it's not library() generating the errors directly, it's because duckdplyr requires dplyr.

I retract my objection 😄

hadley avatar Feb 24 '25 16:02 hadley