Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance .get_contacts #60

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading