diff --git a/NEWS.md b/NEWS.md index c1f2e10c..9cfdd101 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,10 @@ -# pins (development version) +# pins (development version, to be released as 1.4.0) + +## 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). + +## Other improvements * Added example Python code to pin previews for Posit Connect (#806). 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/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; 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 77ec770d..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")) }) }) @@ -51,10 +52,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", {