Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pin_upload() args #809

Merged
merged 6 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# pins (development version)
# pins (development version, to be released as 1.4.0)

## Breaking changes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started calling these sections "Lifecycle changes" which is a bit less harsh than breaking, but still gets the point across.


* 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).

Expand Down
24 changes: 21 additions & 3 deletions R/pin-upload-download.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)) {
Expand All @@ -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, ...))
}

10 changes: 9 additions & 1 deletion man/pin_download.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-upload-download.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-pin-upload-download.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})

Expand Down Expand Up @@ -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", {
Expand Down