-
Notifications
You must be signed in to change notification settings - Fork 62
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
New force_identical_write
arg
#735
Changes from all commits
b30eadd
5180df4
d313fbe
312171c
04565eb
28f0ecd
856b26c
4f219ad
7966273
01508aa
d93dab9
7503901
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,9 @@ pin_read <- function(board, name, version = NULL, hash = NULL, ...) { | |
#' use the default for `board` | ||
#' @param tags A character vector of tags for the pin; most important for | ||
#' discoverability on shared boards. | ||
#' @param force_identical_write Store the pin even if the pin contents are | ||
#' identical to the last version (compared using the hash). Only the pin | ||
#' contents are compared, not the pin metadata. Defaults to `FALSE`. | ||
#' @rdname pin_read | ||
#' @export | ||
pin_write <- function(board, x, | ||
|
@@ -74,7 +77,8 @@ pin_write <- function(board, x, | |
metadata = NULL, | ||
versioned = NULL, | ||
tags = NULL, | ||
...) { | ||
..., | ||
force_identical_write = FALSE) { | ||
ellipsis::check_dots_used() | ||
check_board(board, "pin_write", "pin") | ||
|
||
|
@@ -111,6 +115,17 @@ pin_write <- function(board, x, | |
) | ||
meta$user <- metadata | ||
|
||
if (!force_identical_write) { | ||
old_hash <- possibly_pin_meta(board, name)$pin_hash | ||
if (identical(old_hash, meta$pin_hash)) { | ||
pins_inform(c( | ||
"!" = "The hash of pin {.val {name}} has not changed.", | ||
"*" = "Your pin will not be stored." | ||
)) | ||
return(invisible(name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could return something different here, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's correct; it should return what |
||
} | ||
} | ||
|
||
name <- pin_store(board, name, path, meta, versioned = versioned, x = x, ...) | ||
pins_inform("Writing to pin '{name}'") | ||
invisible(name) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,8 +86,8 @@ test_that("generates useful messages", { | |
ui_loud() | ||
b <- board_temp() | ||
expect_snapshot({ | ||
pin_write(b, 1:5, "x", type = "rds") | ||
pin_write(b, 1:5, "x", type = "rds") | ||
pin_write(b, 1:6, "x", type = "rds") | ||
pin_write(b, 1:7, "x", type = "rds") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did have to change a couple of tests if the default is |
||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we think this might fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to let someone use
check_hash = TRUE
when they write a pin for the first time, before there is any metadata.old_hash
returns asNULL
here when there isn't any metadata.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I think I'd prefer an explicit
pin_exists()
check? Is there some reason not to do that?