Skip to content

Commit

Permalink
Change the pin_write() function signature, moving the dots (#792)
Browse files Browse the repository at this point in the history
* Move the dots in `pin_write()`

* Update tests

* Better error message

* Update NEWS

* Better checking of names of dots

* Fix test case

* Let's call this a breaking change

* Don't have `...names()` available for all our R versions yet
  • Loading branch information
juliasilge authored Sep 29, 2023
1 parent b853504 commit b3f1fcd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# pins (development version)
# pins (development version to be released as 1.3.0)

## Breaking changes

* Changed the function signature of `pin_write()` so arguments like `type` and `title` must be passed by name and not position (#792).

# pins 1.2.2

Expand Down
6 changes: 5 additions & 1 deletion R/pin-read-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ pin_read <- function(board, name, version = NULL, hash = NULL, ...) {
#' @export
pin_write <- function(board, x,
name = NULL,
...,
type = NULL,
title = NULL,
description = NULL,
metadata = NULL,
versioned = NULL,
tags = NULL,
...,
force_identical_write = FALSE) {
check_board(board, "pin_write", "pin")
dots <- list2(...)
if (!missing(...) && (is.null(names(dots)) || names(dots)[[1]] == "")) {
cli::cli_abort('Arguments after the dots `...` must be named, like {.code type = "json"}.')
}

if (is.null(name)) {
name <- enexpr(x)
Expand Down
2 changes: 1 addition & 1 deletion man/pin_read.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/_snaps/pin-read-write.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
Condition
Error in `pin_write()`:
! `name` must be a string
Code
pin_write(board, mtcars, name = "mtcars", "json")
Condition
Error in `pin_write()`:
! Arguments after the dots `...` must be named, like `type = "json"`.
Code
pin_write(board, mtcars, name = "mtcars", type = "froopy-loops")
Condition
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-pin-read-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ test_that("useful errors on bad inputs", {
expect_snapshot(error = TRUE, {
pin_write(mtcars)
pin_write(board, mtcars, name = 1:10)
pin_write(board, mtcars, name = "mtcars", "json")
pin_write(board, mtcars, name = "mtcars", type = "froopy-loops")
pin_write(board, mtcars, name = "mtcars", metadata = 1)
})
Expand All @@ -65,7 +66,7 @@ test_that("pin_write() noisily generates name and type", {
test_that("user can supply metadata", {
board <- board_temp()

pin_write(board, 1:10, "x", metadata = list(name = "Susan"), desc = "A vector")
pin_write(board, 1:10, "x", metadata = list(name = "Susan"), description = "A vector")
meta <- pin_meta(board, "x")
expect_equal(meta$user, list(name = "Susan"))
expect_equal(meta$description, "A vector")
Expand Down

0 comments on commit b3f1fcd

Please sign in to comment.