Skip to content
Open
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
27 changes: 22 additions & 5 deletions R/get_attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ get_attributes <- function(x, eml = NULL) {
}

## get attributes
attributes <- lapply(attributeList$attribute, function(x) {
getAttributes <- function(x) {

## get full attribute list
atts <- unlist(x, recursive = TRUE, use.names = TRUE)
Expand Down Expand Up @@ -95,7 +95,16 @@ get_attributes <- function(x, eml = NULL) {
"",
names(atts))
atts <- as.data.frame(t(atts), stringsAsFactors = FALSE)
})
}

# use lapply for multiple attributes, otherwise pass in singular non-null attribute
attributes <- NULL
if (is.list(attributeList$attribute[[1]])) {
attributes <- lapply(attributeList$attribute, getAttributes)
} else if (!is.null(attributeList$attribute)) {
attributes <- getAttributes(attributeList$attribute)
}

attributes <- dplyr::bind_rows(attributes)

## remove non_fields in attributes
Expand All @@ -109,7 +118,7 @@ get_attributes <- function(x, eml = NULL) {
attributes <- attributes[, !(names(attributes) %in% non_fields)]

## get factors
factors <- lapply(attributeList$attribute, function(x) {
getFactors <- function(x) {

## get factors
factors <- eml_get(x, "enumeratedDomain")
Expand All @@ -125,7 +134,15 @@ get_attributes <- function(x, eml = NULL) {
}

return(factors)
})
}

# use lapply for multiple attributes, otherwise pass in singular non-null attribute
factors <- NULL
if (is.list(attributeList$attribute[[1]])) {
factors <- lapply(attributeList$attribute, getFactors)
} else if (!is.null(attributeList$attribute)) {
factors <- getFactors(attributeList$attribute)
}

factors <- dplyr::bind_rows(factors)

Expand All @@ -142,4 +159,4 @@ get_attributes <- function(x, eml = NULL) {
factors = factors
)
return(out)
}
}