Skip to content

Commit

Permalink
Merge pull request nationalparkservice#60 from RobLBaker/master
Browse files Browse the repository at this point in the history
enhance .get_contacts
  • Loading branch information
RobLBaker authored Oct 21, 2024
2 parents 4219725 + b6882a4 commit cf4588e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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
1 change: 1 addition & 0 deletions docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pkgdown: 2.1.0
pkgdown_sha: ~
articles:
NPSutils: NPSutils.html
last_built: 2024-10-21T15:46Z
last_built: 2024-10-21T18:50Z

0 comments on commit cf4588e

Please sign in to comment.