-
Notifications
You must be signed in to change notification settings - Fork 0
Dev/metadata #26
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
Merged
Merged
Dev/metadata #26
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
3a9c87c
Added spd metadata.
Nic-Chr ca376b9
Added metadata helper.
Nic-Chr 6abe8b3
New helpers and better messaging.
Nic-Chr 71a3c9a
Added helpful messages.
Nic-Chr 7cdc902
Style code (GHA)
Nic-Chr 0192ec8
Merge branch 'main' into dev/metadata
Moohan 95d3a94
Merge branch 'main' into dev/metadata
Moohan 8847246
Rename cols with readr
Nic-Chr 193c59a
Use base print
Nic-Chr e71f447
Use read_file and added file check warning
Nic-Chr e7f4b34
Style code (GHA)
Nic-Chr ac7a3aa
Merge branch 'main' into dev/metadata
bnowok 067ef01
Merge branch 'main' into dev/metadata
Moohan cfd0335
Refactor metadata messaging into the metadata fucntions
Moohan 2a1e692
Add an error if `metadata` is used on a non-tibble
Moohan 055cf4e
Fix and improve tests to expect the messaging
Moohan 352ff49
Improve CSV lazy read and suppress progress messages
Moohan 77ef99c
Style code (GHA)
Moohan 808a8ba
Refactor to make loading the metadata be on demand
Moohan c05d856
Merge pull request #51 from Public-Health-Scotland/dev/metadata-lazy-…
Moohan 764cb2e
Document package (GHA)
Moohan c38bae4
Add error handling for missing metadata reference
Moohan d6bd04f
Update warning message for metadata version
bnowok 9a279d9
Clarify parameter description in metadata function
bnowok 2aaa7c0
Fix roxygen2 configuration in DESCRIPTION file
bnowok 2746559
Style code (GHA)
bnowok 857b276
Document package (GHA)
bnowok a833657
Fix comment formatting in metadata.R
bnowok 28eb000
Style code (GHA)
bnowok d4586d5
Clean up comments in metadata function
bnowok c528474
Document package (GHA)
bnowok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #' Function to access metadata | ||
| #' | ||
| #' @param data Dataset imported using one of the [phslookups] functions, | ||
| #' e.g. `get_spd()`. | ||
| #' | ||
| #' @returns | ||
| #' Metadata `tibble` associated with dataset. | ||
| #' | ||
| #' @examples | ||
| #' library(phslookups) | ||
| #' \dontrun{ | ||
| #' spd <- get_spd() | ||
| #' metadata(spd) | ||
| #' } | ||
| #' @export | ||
| metadata <- function(data) { | ||
| if (!inherits(data, "tbl_df")) { | ||
| cli::cli_abort( | ||
| "{.arg data} must must be a tibble loaded using {.pkg phslookups}." | ||
| ) | ||
| } | ||
|
|
||
| # If already loaded, return immediately | ||
| metadata <- attr(data, "metadata", exact = TRUE) | ||
| if (!is.null(metadata)) { | ||
| return(metadata) | ||
| } | ||
|
|
||
| ref <- attr(data, "metadata_ref", exact = TRUE) | ||
|
|
||
| if (is.null(ref)) { | ||
| cli::cli_abort("Metadata is not available for this data.") | ||
| } | ||
|
|
||
| if (rlang::is_false(ref$exists)) { | ||
| cli::cli_abort(c( | ||
| "x" = "{ref$type} metadata not available.", | ||
| "i" = "Expected at {.path {ref$path}}" | ||
| )) | ||
| } | ||
|
|
||
| metadata <- read_file( | ||
| ref$path, | ||
| col_select = 1:2, | ||
| col_names = c("variable", "description"), | ||
| skip = 1, | ||
| col_types = readr::cols_only( | ||
| variable = readr::col_character(), | ||
| description = readr::col_character() | ||
| ) | ||
| ) | ||
|
|
||
| inform_metadata_version(ref$version) | ||
|
|
||
| # Attach metadata to the object | ||
| set_metadata(data, metadata) | ||
|
|
||
| metadata | ||
| } | ||
|
|
||
| set_metadata_ref <- function(data, path, type, version, exists) { | ||
| attr(data, "metadata_ref") <- list( | ||
| path = path, | ||
| type = type, | ||
| version = version, | ||
| exists = exists | ||
| ) | ||
| data | ||
| } | ||
|
|
||
| set_metadata <- function(data, metadata) { | ||
| attr(data, "metadata") <- metadata | ||
| data | ||
| } | ||
|
|
||
| inform_metadata_access <- function(metadata) { | ||
| cli::cli_inform(c( | ||
| i = "Metadata is available and can be accessed using {.fun metadata}." | ||
| )) | ||
| } | ||
|
|
||
| inform_metadata_version <- function(version) { | ||
| if (version != "latest") { | ||
| cli::cli_warn( | ||
| "Metadata corresponds to the latest version of the data | ||
| and may not exactly match the data currently loaded." | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.