-
Notifications
You must be signed in to change notification settings - Fork 13
Add version() function
#299
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f14945c
Use Roxygen 8.0.0
peterdesmet 554022f
Ignore positai
peterdesmet 9e191fd
Create version() function
peterdesmet 9cda74c
Add test
peterdesmet ee3a9c6
Stricter matching on entire domain
peterdesmet 38c9570
Use correcter >=2.0 rather than 2.x
peterdesmet 90e172e
Add version family to pkgdown
peterdesmet e251a8f
Link to dollar-schema property
peterdesmet 0cdb62a
Describe changes of #299
peterdesmet e84a878
Merge branch 'main' into version
peterdesmet e53a473
Fix typo in example
peterdesmet 3632163
Use returns
peterdesmet b35c08d
Merge branch 'main' into version
peterdesmet f98dfd4
Use quotes
peterdesmet 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,5 @@ | |
| ^pkgdown$ | ||
| ^README\.Rmd$ | ||
| ^CRAN-SUBMISSION$ | ||
| ^\.positai$ | ||
| ^\.claude$ | ||
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 |
|---|---|---|
|
|
@@ -46,3 +46,4 @@ docs | |
|
|
||
| # Mac OS | ||
| .DS_Store | ||
| .positai | ||
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,43 @@ | ||
| #' Get Data Package version | ||
| #' | ||
| #' Determines what version of the [Data Package standard]( | ||
| #' https://datapackage.org/) is used by a Data Package, based on the | ||
| #' [`$schema`](https://datapackage.org/standard/data-package/#dollar-schema) | ||
| #' property. | ||
| #' Version `"1.0"` is assumed if `$schema` is missing, version `">=2.0"` is | ||
| #' assumed for custom values (e.g. [extensions]( | ||
| #' https://datapackage.org/standard/extensions/)). | ||
| #' | ||
| #' @inheritParams read_resource | ||
| #' @returns Data Package version number (e.g. `"1.0"`). | ||
| #' @family version functions | ||
| #' @export | ||
| #' @examples | ||
| #' package <- example_package() | ||
| #' version(package) | ||
| version <- function(package) { | ||
| dollar_schema <- purrr::pluck(package, "$schema") | ||
|
|
||
| if (is.null(dollar_schema)) { | ||
| return("1.0") # Assume 1.0 if $schema is undefined | ||
| } | ||
| if (!is.character(dollar_schema)) { | ||
| return(">=2.0") # Assume 2.0 or higher if $schema is present but invalid | ||
| } | ||
|
|
||
| # Extract version from e.g. | ||
| # "https://datapackage.org/profiles/<version>/datapackage.json" | ||
| pattern = "^https://datapackage\\.org/profiles/((?:[0-9A-Za-z]|\\.|-)+)/.*" | ||
| extracted_version <- sub( | ||
| pattern, | ||
| "\\1", | ||
| dollar_schema, | ||
| perl = TRUE | ||
| ) | ||
|
|
||
| if (extracted_version == dollar_schema) { | ||
| return(">=2.0") # Assume 2.0 or higher if $schema is a custom value | ||
| } | ||
|
|
||
| extracted_version | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| test_that("version() returns version based on $schema", { | ||
| p <- create_package() | ||
|
|
||
| # Undefined | ||
| p$`$schema` <- NULL | ||
| expect_equal(version(p), "1.0") | ||
|
|
||
| # Defined default | ||
| p$`$schema` <- "https://datapackage.org/profiles/1.0/datapackage.json" | ||
| expect_equal(version(p), "1.0") | ||
|
|
||
| # 2.0 | ||
| p$`$schema` <- "https://datapackage.org/profiles/2.0/datapackage.json" | ||
| expect_equal(version(p), "2.0") | ||
|
|
||
| # Future versions | ||
| p$`$schema` <- "https://datapackage.org/profiles/2.1/datapackage.json" | ||
| expect_equal(version(p), "2.1") | ||
| p$`$schema` <- "https://datapackage.org/profiles/2.2-rc.1/datapackage.json" | ||
| expect_equal(version(p), "2.2-rc.1") | ||
| p$`$schema` <- "https://datapackage.org/profiles/3.0/datapackage.json" | ||
| expect_equal(version(p), "3.0") | ||
|
|
||
| # Custom extensions | ||
| p$`$schema` <- "https://spatial.datapackage.org/profiles/1.0/datapackage.json" | ||
| expect_equal(version(p), ">=2.0") | ||
| p$`$schema` <- "http://rs.tdwg.org/dwc-dp/1.0/dwc-dp-profile.json" | ||
| expect_equal(version(p), ">=2.0") | ||
| }) | ||
|
|
||
| test_that("version() returns >=2.0 for invalid $schema", { | ||
| p <- create_package() | ||
| p$`$schema` <- list() | ||
| expect_equal(version(p), ">=2.0") | ||
| p$`$schema` <- 3.0 | ||
| expect_equal(version(p), ">=2.0") | ||
| }) | ||
|
|
||
| test_that("version() returns correct version for example packages", { | ||
| p_1.0 <- example_package(version = "1.0") | ||
| expect_equal(version(p_1.0), "1.0") | ||
| p_2.0 <- example_package(version = "2.0") | ||
| expect_equal(version(p_2.0), "2.0") | ||
| }) |
Oops, something went wrong.
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.