From d6c4496a1b4fc3d4d431bb88978ac32f8d393eb9 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Thu, 29 Sep 2022 21:54:42 -0600 Subject: [PATCH 1/4] Add logic to trigger better error message --- R/pin_versions.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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) From 1f2266f7e478925d8ab9394bcd7dbd6c94d5e98d Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Thu, 29 Sep 2022 21:55:09 -0600 Subject: [PATCH 2/4] Update tests --- tests/testthat/_snaps/pin_versions.md | 10 +++++++++- tests/testthat/test-pin_versions.R | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/testthat/_snaps/pin_versions.md b/tests/testthat/_snaps/pin_versions.md index d22d762e9..b9c7d710a 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 and 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", { From b50d68ad79143e296078760e948c5631d3326b02 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Thu, 29 Sep 2022 22:03:25 -0600 Subject: [PATCH 3/4] Update snapshots --- tests/testthat/_snaps/pin_versions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/pin_versions.md b/tests/testthat/_snaps/pin_versions.md index b9c7d710a..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 and omit name with modern api +# can't swap arguments or omit name with modern api Code pin_versions(name, board) From d0f330416395c8bd45bdf9e7bfeb4a484aa4f064 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Fri, 30 Sep 2022 16:03:02 -0600 Subject: [PATCH 4/4] Update NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) 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).