Skip to content

Commit

Permalink
update .get_contacts to handle case when only one contact is supplied.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLBaker committed Oct 21, 2024
1 parent 9d99bd2 commit 5641db7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions R/load_core_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand All @@ -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,
Expand Down

0 comments on commit 5641db7

Please sign in to comment.