From 3d330b633febfa8176c0240ed936870d77edc141 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Wed, 15 Nov 2023 16:28:07 -0700 Subject: [PATCH 1/4] Update `pin_upload()` args --- R/pin-upload-download.R | 24 ++++++++++++++++++++--- tests/testthat/test-pin-upload-download.R | 3 ++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/R/pin-upload-download.R b/R/pin-upload-download.R index 023dc618..40c62beb 100644 --- a/R/pin-upload-download.R +++ b/R/pin-upload-download.R @@ -28,8 +28,21 @@ pin_download <- function(board, name, version = NULL, hash = NULL, ...) { #' @export #' @rdname pin_download #' @param paths A character vector of file paths to upload to `board`. -pin_upload <- function(board, paths, name = NULL, title = NULL, description = NULL, metadata = NULL, ...) { +pin_upload <- function(board, + paths, + name = NULL, + ..., + title = NULL, + description = NULL, + metadata = NULL, + tags = NULL, + urls = NULL) { check_board(board, "pin_upload", "pin") + dots <- list2(...) + if (!missing(...) && (is.null(names(dots)) || names(dots)[[1]] == "")) { + cli::cli_abort('Arguments after the dots `...` must be named, like {.code tags = "my-great-tag"}.') + } + if (!is.character(paths)) { abort("`path` must be a character vector") @@ -48,6 +61,10 @@ pin_upload <- function(board, paths, name = NULL, title = NULL, description = NU check_pin_name(name) } + check_metadata(metadata) + check_character(tags, allow_null = TRUE) + check_character(urls, allow_null = TRUE) + # Expand any directories is_dir <- fs::is_dir(paths) if (any(is_dir)) { @@ -60,10 +77,11 @@ pin_upload <- function(board, paths, name = NULL, title = NULL, description = NU paths = paths, type = "file", title = title %||% default_title(name, path = paths), - description = description + description = description, + tags = tags, + urls = urls ) meta$user <- metadata invisible(pin_store(board, name, paths, meta, ...)) } - diff --git a/tests/testthat/test-pin-upload-download.R b/tests/testthat/test-pin-upload-download.R index 77ec770d..22a639d7 100644 --- a/tests/testthat/test-pin-upload-download.R +++ b/tests/testthat/test-pin-upload-download.R @@ -51,10 +51,11 @@ test_that("user can supply metadata", { writeLines("Hi!", path1) board <- board_temp() - pin_upload(board, path1, "x", metadata = list(name = "Susan"), desc = "A vector") + pin_upload(board, path1, "x", metadata = list(name = "Susan"), description = "A vector", tags = c("blue", "green")) meta <- pin_meta(board, "x") expect_equal(meta$user, list(name = "Susan")) expect_equal(meta$description, "A vector") + expect_equal(meta$tags, c("blue", "green")) }) test_that("informative error for legacy boards", { From e0ac9ab660b4ded68ffbebca92d3e976e198abc8 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Wed, 15 Nov 2023 19:19:44 -0700 Subject: [PATCH 2/4] Update NEWS, docs --- NEWS.md | 4 ++++ man/pin_download.Rd | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 032845c3..639d3deb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # pins (development version) +## Breaking changes + +* Changed the function signature of `pin_upload()` to be consistent with `pin_write()` i.e. arguments like `tags` must be passed by name and not position (#809). + # pins 1.3.0 ## Breaking changes diff --git a/man/pin_download.Rd b/man/pin_download.Rd index a19bf2ae..917ee37c 100644 --- a/man/pin_download.Rd +++ b/man/pin_download.Rd @@ -11,10 +11,12 @@ pin_upload( board, paths, name = NULL, + ..., title = NULL, description = NULL, metadata = NULL, - ... + tags = NULL, + urls = NULL ) } \arguments{ @@ -43,6 +45,12 @@ description of the contents will be automatically generated.} \item{metadata}{A list containing additional metadata to store with the pin. When retrieving the pin, this will be stored in the \code{user} key, to avoid potential clashes with the metadata that pins itself uses.} + +\item{tags}{A character vector of tags for the pin; most important for +discoverability on shared boards.} + +\item{urls}{A character vector of URLs for more info on the pin, such as a +link to a wiki or other documentation.} } \value{ \code{pin_download()} returns a character vector of file paths; From 718c44c9cc0dad970cae5fa4904c6c72bcc644da Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Wed, 15 Nov 2023 20:07:59 -0700 Subject: [PATCH 3/4] Add test for new `...` message --- tests/testthat/_snaps/pin-upload-download.md | 5 +++++ tests/testthat/test-pin-upload-download.R | 1 + 2 files changed, 6 insertions(+) diff --git a/tests/testthat/_snaps/pin-upload-download.md b/tests/testthat/_snaps/pin-upload-download.md index da2816b8..d5018cac 100644 --- a/tests/testthat/_snaps/pin-upload-download.md +++ b/tests/testthat/_snaps/pin-upload-download.md @@ -16,6 +16,11 @@ Message Guessing `name = 'test.txt'` Creating new version '20120304T050607Z-xxxxx' + Code + pin_upload(board, path, "test", c("blue", "green")) + Condition + Error in `pin_upload()`: + ! Arguments after the dots `...` must be named, like `tags = "my-great-tag"`. # can pin file called data.txt diff --git a/tests/testthat/test-pin-upload-download.R b/tests/testthat/test-pin-upload-download.R index 22a639d7..1d1a4b3d 100644 --- a/tests/testthat/test-pin-upload-download.R +++ b/tests/testthat/test-pin-upload-download.R @@ -20,6 +20,7 @@ test_that("pin_upload generated useful messages", { path <- fs::file_touch(fs::path_temp("test.txt")) pin_upload(board, path) + pin_upload(board, path, "test", c("blue", "green")) }) }) From 4a0b3c2bd3a2ff253fabe5f753c42975e0d2b4d2 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Mon, 20 Nov 2023 11:43:16 -0700 Subject: [PATCH 4/4] Update NEWS --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 639d3deb..d0e88195 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # pins (development version) -## Breaking changes +## Lifecycle changes * Changed the function signature of `pin_upload()` to be consistent with `pin_write()` i.e. arguments like `tags` must be passed by name and not position (#809).