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

consider including an eml_get_simple function #303

Open
jeanetteclark opened this issue Jun 19, 2020 · 2 comments
Open

consider including an eml_get_simple function #303

jeanetteclark opened this issue Jun 19, 2020 · 2 comments

Comments

@jeanetteclark
Copy link
Contributor

eml_get is really helpful, but I find myself often needing to strip the return value down so that it is a simple vector that is easier to work with. For example, say I need to remove two entities from a list of otherEntities.

file_names <- eml_get(doc$dataset$otherEntity, "entityName")
remove <- c("file_1.csv", "file_2.csv")

i <- which(!(file_names %in% remove))

I can provide a full MRE if needed, but because of the output of eml_get still has the EML document context associated with it, the above returns unexpected results.

I have a very simple helper function that drops the context and attributes of eml_get

eml_get_simple <- function (doc, element) {
    out <- eml_get(doc, element, from = "list")
    out$`@context` <- NULL
    attributes(out) <- NULL
    out <- unlist(out)
    return(out)
}

Do we think that it would be worth including in EML? or perhaps the ability to pass a simple = TRUE argument to the existing eml_get function? I use that little helper every time I work with the EML package

@cboettig
Copy link
Member

I think a PR for this would be great. Arguably it should be the default behavior for eml_get, at least for dropping @context. I'm a bit less clear on the dropping of attributes and the unlist, that seems like it could have unexpected consequences in some cases?

@jeanetteclark
Copy link
Contributor Author

Yeah probably - the unlist especially is just nice when you are returning a value-only element (like entityName). You are right that it produces some weirdness for complex elements and probably shouldn't be included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants