diff --git a/NEWS.md b/NEWS.md index 952e16f20..bdafea54e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # pins (development version) +* Improved error message for `pin_versions()` (#657). + # pins 1.0.3 * The `arrow` package is now suggested, rather than imported (#644, @jonthegeek). diff --git a/R/pin_versions.R b/R/pin_versions.R index 6dd59fe8b..262e415d6 100644 --- a/R/pin_versions.R +++ b/R/pin_versions.R @@ -38,7 +38,9 @@ pin_versions <- function(board, name, ..., full = deprecated()) { lifecycle::deprecate_warn("1.0.0", "pin_versions(full)") } - if (missing(name) || is.board(name) || name %in% board_list()) { + if (missing(name) && is.board(board)) { + abort("Argument `name` is missing, with no default") + } else if (missing(name) || is.board(name) || name %in% board_list()) { swap <- board board <- if (missing(name)) NULL else name board <- board_get(board) diff --git a/tests/testthat/_snaps/pin_versions.md b/tests/testthat/_snaps/pin_versions.md index d22d762e9..c1ff00497 100644 --- a/tests/testthat/_snaps/pin_versions.md +++ b/tests/testthat/_snaps/pin_versions.md @@ -5,7 +5,7 @@ x <- pin_versions("x", "local") x <- pin_versions("x", board) -# can't swap arguments with modern api +# can't swap arguments or omit name with modern api Code pin_versions(name, board) @@ -13,6 +13,14 @@ Error in `pin_versions()`: ! Please supply `board` then `name` when working with modern boards +--- + + Code + pin_versions(board) + Condition + Error in `pin_versions()`: + ! Argument `name` is missing, with no default + # `full` is deprecated Code diff --git a/tests/testthat/test-pin_versions.R b/tests/testthat/test-pin_versions.R index 839cf68ef..987d14e62 100644 --- a/tests/testthat/test-pin_versions.R +++ b/tests/testthat/test-pin_versions.R @@ -10,10 +10,11 @@ test_that("can use old pin_versions() api", { }) }) -test_that("can't swap arguments with modern api", { +test_that("can't swap arguments or omit name with modern api", { board <- board_temp() name <- local_pin(board, 1) expect_snapshot(pin_versions(name, board), error = TRUE) + expect_snapshot(pin_versions(board), error = TRUE) }) test_that("`full` is deprecated", {