get_meta_value.RdThis function retrieves the value associated with a specified key from a metadata data frame. If the key is not found or the metadata data frame is `NULL`, a default value is returned.
get_meta_value(meta_df, key_name, default_if_null = "")A data frame containing metadata with at least two columns: `key` and `value`. The `key` column should contain unique identifiers, and the `value` column should contain the corresponding values.
A character string specifying the key whose value is to be retrieved.
A default value to return if the key is not found in the metadata data frame or if the metadata data frame is `NULL`. Defaults to an empty string (`""`).
The value associated with the specified key as a character string. If the key is not found or the metadata data frame is `NULL`, the function returns the value specified by `default_if_null`.
# Example metadata data frame
meta_df <- data.frame(key = c("author", "version", "license"),
value = c("John Doe", "1.0.0", "MIT"))
# Retrieve the value for the key "author"
get_meta_value(meta_df, "author") # Returns "John Doe"
#> [1] "John Doe"
# Retrieve the value for a non-existent key with a default value
get_meta_value(meta_df, "description", default_if_null = "N/A") # Returns "N/A"
#> [1] "N/A"
# Handle a NULL metadata data frame
get_meta_value(NULL, "author", default_if_null = "Unknown") # Returns "Unknown"
#> [1] "Unknown"