From 5641db73366de33d7c086c98160a3f9aa96bc163 Mon Sep 17 00:00:00 2001 From: Rob Baker Date: Mon, 21 Oct 2024 12:51:11 -0600 Subject: [PATCH] update .get_contacts to handle case when only one contact is supplied. --- R/load_core_metadata.R | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/R/load_core_metadata.R b/R/load_core_metadata.R index 5ab2cfd..4753534 100644 --- a/R/load_core_metadata.R +++ b/R/load_core_metadata.R @@ -205,7 +205,7 @@ load_core_metadata <- function(ds_ref, path = paste0(getwd(), "/data")){ #' #' `r lifecycle::badge('experimental')` #' -#' @description `.get_contacts()` extracts the "contacts" element from EML metadata and returns it as a dataframe with three columsn, first a column indicating that each row is an contact. Second, and column with the contact's name (first last). Third, the contact's email address. +#' @description `.get_contacts()` extracts the "contacts" element from EML metadata and returns it as a dataframe with two columns, first a column with the contact's name (first last) and second the contact's email address. #' #' @param metadata an EML formatted R object #' @@ -221,8 +221,16 @@ load_core_metadata <- function(ds_ref, path = paste0(getwd(), "/data")){ contact <- metadata$dataset$contact individual <- NULL email <- NULL + + #if single contact, nest it so that it behaves the same as when there are + #multiple contacts: + if ("organizationName" %in% names(contact) | + "individualName" %in% names(contact)) { + contact <- list(contact) + } + for(i in 1:length(seq_along(contact))){ - #get name as first-laste: + #get name as first-last: name_list <- unlist(contact[[i]]$individualName, recursive = FALSE) if(length(seq_along(name_list)) == 3){ ind_name <- paste(name_list$givenName1,