Skip to content

Commit

Permalink
Merge pull request #170 from RobLBaker/main
Browse files Browse the repository at this point in the history
fix set_orcid_creators
  • Loading branch information
RobLBaker authored Nov 8, 2024
2 parents e6a0b99 + accfa65 commit c579457
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions R/editEMLfunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"]])
}
}
}

Expand All @@ -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")
Expand Down Expand Up @@ -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")
}
Expand Down
1 change: 1 addition & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ globalVariables(c("UnitCode",
#' var1 <- .get_user_input()
#' }
.get_user_input <- function () {

var1 <- readline(prompt = "1: Yes\n2: No\n")
return(var1)
}
Expand Down

0 comments on commit c579457

Please sign in to comment.