diff --git a/NEWS.md b/NEWS.md index 08637be..3d45d56 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ * Bug fixes to `.get_authors()` * `get_authors` now adds a period (.) after given names with a single character and can handle an unlimited number of given names. * Moved sf, leaflet, and stringr to from imports to suggests. + * Enable `.get_contacts()` to handle cases when there is only one contact. # NPSutils 0.3.2 "Lost Coast" * Add new functions, `load_data_packages()` and `load_data_package()`, which can load data packages (EML in .xml and data in .csv) similarly to the deprecated `load_data_package_deprecated()` function but also allows the data types in the tibbles loaded to be specified based on the information in the metadata. 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, diff --git a/docs/news/index.html b/docs/news/index.html index ce14266..574a728 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -61,6 +61,7 @@