From 955ccb18188d0b099ff4dea21adbf7f315860db1 Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Thu, 7 Nov 2024 16:24:56 -0700 Subject: [PATCH 1/2] updated set_creator_orcids to handle some individuals with and some without orcids. --- R/editEMLfunctions.R | 14 ++++++++++++-- R/utils.R | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/R/editEMLfunctions.R b/R/editEMLfunctions.R index 327d948..fd2f7e6 100644 --- a/R/editEMLfunctions.R +++ b/R/editEMLfunctions.R @@ -2255,7 +2255,7 @@ set_data_urls <- function(eml_object, url = NULL, force = FALSE, NPS = TRUE){ #' creator_orcids <- c("1234-1234-1234-1234", NA, "4321-4321-4321-4321") #' mymetadata <- set_creator_orcids(mymetadata, creator_orcids) #' } -set_creator_orcids <- function(eml_object, orcids, force = FALSE, NPS = TRUE){ +set_creator_orcids <- function(eml_object, orcids, force = FALSE, NPS = TRUE) { #if NA supplied as "NA": if (sum(stringr::str_detect(na.exclude(orcids), "NA")) > 0) { if (force == FALSE) { @@ -2293,8 +2293,12 @@ set_creator_orcids <- function(eml_object, orcids, force = FALSE, NPS = TRUE){ surName <- append(surName, creator[[i]][["individualName"]][["surName"]]) #what if there is no orcid? + if (is.null(creator[[i]][["userId"]][["userId"]])) { + existing_orcid <- append(existing_orcid, NA) + } else { existing_orcid <- append(existing_orcid, creator[[i]][["userId"]][["userId"]]) + } } } @@ -2315,6 +2319,11 @@ set_creator_orcids <- function(eml_object, orcids, force = FALSE, NPS = TRUE){ current_orcids <- tibble::tibble(surName, existing_orcid) #construct tibble of replacement orcids: new_orcids <- tibble::tibble(surName, orcids) + for (i in 1:nrow(new_orcids)) { + if(!is.na(new_orcids[i,2])) { + new_orcids[i,2] <- paste0("https://orcid.org/", new_orcids[i,2]) + } + } cat("Your data package contains ORCiDs for the following creators:\n\n") cat(format(tibble::as_tibble(current_orcids))[c(-3L, -1L)], sep = "\n") cat("\nAre you sure you want to replace the existing ORCiDs with the following:\n\n") @@ -2364,12 +2373,13 @@ set_creator_orcids <- function(eml_object, orcids, force = FALSE, NPS = TRUE){ existing_orcid <- append(existing_orcid, next_orcid) } else { - existing_orcid <- append(existing_orcid, "NULL") + existing_orcid <- append(existing_orcid, NA) } } } #construct tibble of existing orcids: new_orcids <- tibble::tibble(surName, existing_orcid) + names(new_orcids) <- c("surName", "new_orcids") cat("Your new ORCiDs are:\n") cat(format(tibble::as_tibble(new_orcids))[c(-3L, -1L)], sep = "\n") } diff --git a/R/utils.R b/R/utils.R index a9fe7da..154b4e9 100644 --- a/R/utils.R +++ b/R/utils.R @@ -266,7 +266,8 @@ globalVariables(c("UnitCode", #' var1 <- .get_user_input() #' } .get_user_input <- function () { - var1 <- readline(prompt = "1: Yes\n2: No\n") + + var1 <- readline(prompt = ">1: Yes\n>2: No\n") return(var1) } From accfa65d46d97e2bf38bc498235578d34593aefa Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Thu, 7 Nov 2024 16:25:17 -0700 Subject: [PATCH 2/2] revert to previous display ofr .get_user_input --- R/utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index 154b4e9..62b1cb5 100644 --- a/R/utils.R +++ b/R/utils.R @@ -267,7 +267,7 @@ globalVariables(c("UnitCode", #' } .get_user_input <- function () { - var1 <- readline(prompt = ">1: Yes\n>2: No\n") + var1 <- readline(prompt = "1: Yes\n2: No\n") return(var1) }