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

Improved metadata handling in readSource + metadata helper function #224

Merged
merged 5 commits into from
Oct 25, 2024

Conversation

tscheypidi
Copy link
Member

  • adapted metadata handling from calcOutput in readSource (metadata will now be added as comment to the returned data objects)
  • added helper function getMetadataComment to more easily extract metadata from a data object

…ill now be added as comment to the returned data objects)

- added helper function getMetadataComment to more easily extract metadata from a data object
#' @param type output type, e.g. "TauTotal"
#' @param warn boolean indicating whether warnings should be triggered
#' if entries are missing, or not.
#' @param n the number of generations to go back
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a generation here? I feel this arg's documentation needs more clarification

@@ -0,0 +1,23 @@
#' getMetadataComment
#'
#' Helper function extract a metadata comment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' Helper function extract a metadata comment
#' Helper function to extract metadata from a magclass object's comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it also works for other objects as we create a comment attribute also for non-magclass objects

#' getMetadataComment(x, "description")
#' @export

getMetadataComment <- function(x, name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getMetadataComment <- function(x, name) {
getMetadata <- function(x, name) {

I find "Comment" a bit misleading, it reads to me like you can extract the "comment" from the metadata. It is actually getMetadataFromComment, right? Maybe to keep it short just getMetadata?

comment <- attr(x, "comment")
key <- paste0("^ ", name, ": ")
entry <- grep(key, comment)
if (length(entry) == 0) return(NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider throwing an error or warning in this case? Maybe one that can be disabled with an argument

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought about it, but decided not to implement it at this stage. We can add this feature later in case we need it

tscheypidi and others added 2 commits October 25, 2024 14:57
Co-authored-by: Pascal Sauer <156898545+pascal-sauer@users.noreply.github.com>
@tscheypidi tscheypidi merged commit 52605af into pik-piam:master Oct 25, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants