From 58082a377d682a48eb370e2d8b45588d0d118127 Mon Sep 17 00:00:00 2001 From: Michal Lauer Date: Tue, 27 Aug 2024 21:37:36 +0200 Subject: [PATCH] Fixed edge case where n_versions = 0 (#838) * Fixed edge case where n_versions = 0 * Update NEWS --------- Co-authored-by: Julia Silge --- NEWS.md | 2 ++ R/pin_versions.R | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index f62ca534..acd2943b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,8 @@ * Fixed a bug in handling folders with duplicate names for Google Drive (#819, @UchidaMizuki) +* Fixed how previously deleted pin versions are detected (#838, @MichalLauer) + # pins 1.3.0 ## Breaking changes diff --git a/R/pin_versions.R b/R/pin_versions.R index 3053cefe..7045a86d 100644 --- a/R/pin_versions.R +++ b/R/pin_versions.R @@ -157,19 +157,23 @@ version_from_path <- function(x) { } version_setup <- function(board, name, new_version, versioned = NULL, call = caller_env()) { + + n_versions <- 0 + if (pin_exists(board, name)) { versions <- pin_versions(board, name) - old_version <- versions$version[[1]] n_versions <- nrow(versions) - if (old_version == new_version) { - cli::cli_abort(c( - "The new version {.val {new_version}} is the same as the most recent version.", - i = "Did you try to create a new version with the same timestamp as the last version?" - ), - call = call) + + if (n_versions > 0) { + old_version <- versions$version[[1]] + if (old_version == new_version) { + cli::cli_abort(c( + "The new version {.val {new_version}} is the same as the most recent version.", + i = "Did you try to create a new version with the same timestamp as the last version?" + ), + call = call) + } } - } else { - n_versions <- 0 } versioned <- versioned %||% if (n_versions > 1) TRUE else board$versioned @@ -184,4 +188,4 @@ version_setup <- function(board, name, new_version, versioned = NULL, call = cal } new_version -} +} \ No newline at end of file