-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
tscheypidi
commented
Oct 25, 2024
- 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
R/prepExtendedComment.R
Outdated
#' @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 |
There was a problem hiding this comment.
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
R/getMetadataComment.R
Outdated
@@ -0,0 +1,23 @@ | |||
#' getMetadataComment | |||
#' | |||
#' Helper function extract a metadata comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' Helper function extract a metadata comment | |
#' Helper function to extract metadata from a magclass object's comment. |
There was a problem hiding this comment.
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
R/getMetadataComment.R
Outdated
#' getMetadataComment(x, "description") | ||
#' @export | ||
|
||
getMetadataComment <- function(x, name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
?
R/getMetadataComment.R
Outdated
comment <- attr(x, "comment") | ||
key <- paste0("^ ", name, ": ") | ||
entry <- grep(key, comment) | ||
if (length(entry) == 0) return(NULL) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Co-authored-by: Pascal Sauer <156898545+pascal-sauer@users.noreply.github.com>