Skip to content

Commit

Permalink
Improve conflict_scout() behavior after resolving conflicts (#96)
Browse files Browse the repository at this point in the history
Fixes #95
  • Loading branch information
krlmlr authored Sep 26, 2023
1 parent 92c361d commit 290f6e9
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# conflicted (development version)

* `conflict_scout()` no longer returns functions whose conflicts have been
resolved manually or automatically (#95).

# conflicted 1.2.0

* New `conflicts_prefer()` to easily declare multiple preferences at once:
Expand Down
8 changes: 4 additions & 4 deletions R/find.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#' @param pkgs Set of packages for which to report conflicts. If `NULL`,
#' the default, will report conflicts for all loaded packages
#' @return A named list of character vectors. The names are functions and
#' the values are the packages where they appear. If there is only a single
#' package listed, it means that an automated disambiguation has selected
#' that function.
#' the values are the packages where they appear. Disambiguated functions
#' are removed from that list.
#'
#' A user friendly print method displays the result as bulleted list.
#' @export
Expand Down Expand Up @@ -45,7 +44,8 @@ conflict_scout <- function(pkgs = NULL) {
conflicts[[fun]] <- prefs_resolve(fun, conflicts[[fun]])
}

conflicts <- compact(conflicts)
# remove all non-conflicts from the list
conflicts <- conflicts[lengths(conflicts) > 1]

new_conflict_report(conflicts)
}
Expand Down
5 changes: 2 additions & 3 deletions man/conflict_scout.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/testthat/_snaps/find.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@
* `ns_env()`: rlang and pkgload
* `pkg_env()`: rlang and pkgload

# preferences are obeyed

Code
conflict_scout(c("rlang", "prefs"))
Message
1 conflict
* `set_names()`: rlang and prefs
Code
conflicts_prefer(rlang::set_names())
Message
[conflicted] Will prefer rlang::set_names over any other package.
Code
conflict_scout(c("rlang", "prefs"))
Message
0 conflicts

13 changes: 13 additions & 0 deletions tests/testthat/prefs/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Package: prefs
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R: c(
person("Hadley", "Wickham", , "[email protected]", role = c("aut", "cre")),
person("RStudio", role = c("cph", "fnd"))
)
Description: What the package does (one paragraph).
License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
license
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
1 change: 1 addition & 0 deletions tests/testthat/prefs/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export(set_names)
1 change: 1 addition & 0 deletions tests/testthat/prefs/R/test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set_names <- function() {}
13 changes: 13 additions & 0 deletions tests/testthat/test-find.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ test_that("can find conflicts with data", {
expect_named(conflict_scout(c("datasets", "data")), "mtcars")
})

test_that("preferences are obeyed", {
pkgload::load_all(test_path("prefs"), quiet = TRUE)
withr::defer(pkgload::unload("prefs"))

on.exit(prefs_reset(), add = TRUE)

expect_snapshot({
conflict_scout(c("rlang", "prefs"))
conflicts_prefer(rlang::set_names())
conflict_scout(c("rlang", "prefs"))
})
})

# moved functions ----------------------------------------------------

test_that(".Deprecated call contains function name", {
Expand Down

0 comments on commit 290f6e9

Please sign in to comment.