From c4ec0dc90d4a8e3e88a9ddbcec7f42f67c008e11 Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:39:31 +0200 Subject: [PATCH 01/32] folder move --- inst/extdata/{ => v1}/datapackage.json | 0 inst/extdata/{ => v1}/deployments.csv | 0 inst/extdata/{ => v1}/observations_1.tsv | 0 inst/extdata/{ => v1}/observations_2.tsv | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename inst/extdata/{ => v1}/datapackage.json (100%) rename inst/extdata/{ => v1}/deployments.csv (100%) rename inst/extdata/{ => v1}/observations_1.tsv (100%) rename inst/extdata/{ => v1}/observations_2.tsv (100%) diff --git a/inst/extdata/datapackage.json b/inst/extdata/v1/datapackage.json similarity index 100% rename from inst/extdata/datapackage.json rename to inst/extdata/v1/datapackage.json diff --git a/inst/extdata/deployments.csv b/inst/extdata/v1/deployments.csv similarity index 100% rename from inst/extdata/deployments.csv rename to inst/extdata/v1/deployments.csv diff --git a/inst/extdata/observations_1.tsv b/inst/extdata/v1/observations_1.tsv similarity index 100% rename from inst/extdata/observations_1.tsv rename to inst/extdata/v1/observations_1.tsv diff --git a/inst/extdata/observations_2.tsv b/inst/extdata/v1/observations_2.tsv similarity index 100% rename from inst/extdata/observations_2.tsv rename to inst/extdata/v1/observations_2.tsv From 36900c3a5df24bbfffca0fafa26c65cb0d56ee3a Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:44:55 +0200 Subject: [PATCH 02/32] update path --- R/add_resource.R | 6 ++++-- R/example_package.R | 4 +++- R/read_package.R | 2 +- R/read_resource.R | 2 +- R/write_package.R | 2 +- tests/testthat/test-add_resource.R | 2 +- tests/testthat/test-read_package.R | 6 +++--- tests/testthat/test-read_resource.R | 4 ++-- tests/testthat/test-write_package.R | 3 ++- vignettes/frictionless.Rmd.orig | 6 +++--- 10 files changed, 21 insertions(+), 16 deletions(-) diff --git a/R/add_resource.R b/R/add_resource.R index 533fe846..b5c40515 100644 --- a/R/add_resource.R +++ b/R/add_resource.R @@ -69,8 +69,10 @@ #' ) #' #' # Replace the resource "observations" with a file-based resource (2 TSV files) -#' path_1 <- system.file("extdata", "observations_1.tsv", package = "frictionless") -#' path_2 <- system.file("extdata", "observations_2.tsv", package = "frictionless") +#' path_1 <- +#' system.file("extdata", "v1", "observations_1.tsv", package = "frictionless") +#' path_2 <- +#' system.file("extdata", "v1", "observations_2.tsv", package = "frictionless") #' package <- add_resource( #' package, #' resource_name = "observations", diff --git a/R/example_package.R b/R/example_package.R index bd6c28d2..a42bbe91 100644 --- a/R/example_package.R +++ b/R/example_package.R @@ -15,6 +15,8 @@ #' @examples #' example_package() example_package <- function() { - path <- system.file("extdata", "datapackage.json", package = "frictionless") + path <- system.file( + "extdata", "v1", "datapackage.json", package = "frictionless" + ) read_package(path) } diff --git a/R/read_package.R b/R/read_package.R index 7aab5079..4778f7e1 100644 --- a/R/read_package.R +++ b/R/read_package.R @@ -11,7 +11,7 @@ #' @examples #' # Read a datapackage.json file #' package <- read_package( -#' system.file("extdata", "datapackage.json", package = "frictionless") +#' system.file("extdata", "v1", "datapackage.json", package = "frictionless") #' ) #' #' package diff --git a/R/read_resource.R b/R/read_resource.R index f012b7f3..669a63a1 100644 --- a/R/read_resource.R +++ b/R/read_resource.R @@ -183,7 +183,7 @@ #' @examples #' # Read a datapackage.json file #' package <- read_package( -#' system.file("extdata", "datapackage.json", package = "frictionless") +#' system.file("extdata", "v1", "datapackage.json", package = "frictionless") #' ) #' #' package diff --git a/R/write_package.R b/R/write_package.R index 8d29010b..233ca9dd 100644 --- a/R/write_package.R +++ b/R/write_package.R @@ -24,7 +24,7 @@ #' @examples #' # Load the example Data Package from disk #' package <- read_package( -#' system.file("extdata", "datapackage.json", package = "frictionless") +#' system.file("extdata", "v1", "datapackage.json", package = "frictionless") #' ) #' #' package diff --git a/tests/testthat/test-add_resource.R b/tests/testthat/test-add_resource.R index bd0810d6..59fa61fe 100644 --- a/tests/testthat/test-add_resource.R +++ b/tests/testthat/test-add_resource.R @@ -377,7 +377,7 @@ test_that("add_resource() can add resource from CSV file with other delimiter, test_that("add_resource() sets correct properties for CSV resources", { p <- create_package() - path <- system.file("extdata", "deployments.csv", package = "frictionless") + path <- system.file("extdata", "v1", "deployments.csv", package = "frictionless") # Encoding UTF-8 (0.8), ISO-8859-1 (0.59), ISO-8859-2 (0.26) p <- add_resource(p, "deployments", path) diff --git a/tests/testthat/test-read_package.R b/tests/testthat/test-read_package.R index 9be9edd8..b567c529 100644 --- a/tests/testthat/test-read_package.R +++ b/tests/testthat/test-read_package.R @@ -1,6 +1,6 @@ test_that("read_package() returns a valid Data Package reading from path", { # Load example package and a valid minimal one - p_path <- system.file("extdata", "datapackage.json", package = "frictionless") + p_path <- system.file("extdata", "v1", "datapackage.json", package = "frictionless") minimal_path <- test_path("data/valid_minimal.json") p_local <- read_package(p_path) p_minimal <- read_package(minimal_path) @@ -67,7 +67,7 @@ test_that("read_package() returns error on missing file and properties", { # Not a json file expect_error( read_package( - system.file("extdata", "deployments.csv", package = "frictionless") + system.file("extdata", "v1", "deployments.csv", package = "frictionless") ), regexp = "lexical error: invalid char in json text.", fixed = FALSE @@ -119,7 +119,7 @@ test_that("read_package() allows YAML descriptor", { }) test_that("read_package() converts JSON null to NULL", { - p_path <- system.file("extdata", "datapackage.json", package = "frictionless") + p_path <- system.file("extdata", "v1", "datapackage.json", package = "frictionless") p <- read_package(p_path) # { "image": null } is read as NULL (use chuck() to force error if missing) expect_null(purrr::chuck(p, "image")) diff --git a/tests/testthat/test-read_resource.R b/tests/testthat/test-read_resource.R index a51b94fb..8d25916d 100644 --- a/tests/testthat/test-read_resource.R +++ b/tests/testthat/test-read_resource.R @@ -198,7 +198,7 @@ test_that("read_resource() returns error on invalid resource", { # Add valid path p_invalid$resources[[1]]$path <- "deployments.csv" p_invalid$directory <- dirname( - system.file("extdata", "datapackage.json", package = "frictionless") + system.file("extdata", "v1", "datapackage.json", package = "frictionless") ) # Not a tabular-data-resource @@ -288,7 +288,7 @@ test_that("read_resource() can read local files", { resource <- read_resource(p, "deployments") p_local <- read_package( - system.file("extdata", "datapackage.json", package = "frictionless") + system.file("extdata", "v1", "datapackage.json", package = "frictionless") ) expect_identical(read_resource(p_local, "deployments"), resource) }) diff --git a/tests/testthat/test-write_package.R b/tests/testthat/test-write_package.R index e5a17703..61271b40 100644 --- a/tests/testthat/test-write_package.R +++ b/tests/testthat/test-write_package.R @@ -45,7 +45,8 @@ test_that("write_package() returns error if Data Package has no resource(s)", { }) test_that("write_package() writes unaltered datapackage.json as is", { - p_file <- system.file("extdata", "datapackage.json", package = "frictionless") + p_file <- + system.file("extdata", "v1", "datapackage.json", package = "frictionless") json_original <- readr::read_lines(p_file) # Will use line endings of system p <- read_package(p_file) dir <- file.path(tempdir(), "package") diff --git a/vignettes/frictionless.Rmd.orig b/vignettes/frictionless.Rmd.orig index 91ea9e6a..bd8372fb 100644 --- a/vignettes/frictionless.Rmd.orig +++ b/vignettes/frictionless.Rmd.orig @@ -66,7 +66,7 @@ You can also read data from a local (e.g. downloaded) Data Package. In fact, the ```{r} local_package <- read_package( - system.file("extdata", "datapackage.json", package = "frictionless") + system.file("extdata", "v1", "datapackage.json", package = "frictionless") ) local_package @@ -173,8 +173,8 @@ If you already have your data stored as CSV or TSV files and you want to include ```{r} # Two TSV files with the same structure -path_1 <- system.file("extdata", "observations_1.tsv", package = "frictionless") -path_2 <- system.file("extdata", "observations_2.tsv", package = "frictionless") +path_1 <- system.file("extdata", "v1", "observations_1.tsv", package = "frictionless") +path_2 <- system.file("extdata", "v1", "observations_2.tsv", package = "frictionless") # Add both TSV files as a single resource my_package <- From c6a2d36fc2c1a0be9e3d60efc2bdf81c817ff31b Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:45:37 +0200 Subject: [PATCH 03/32] document() --- man/add_resource.Rd | 6 ++++-- man/read_package.Rd | 2 +- man/read_resource.Rd | 2 +- man/write_package.Rd | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/man/add_resource.Rd b/man/add_resource.Rd index f0a62e25..e54ff5c5 100644 --- a/man/add_resource.Rd +++ b/man/add_resource.Rd @@ -93,8 +93,10 @@ package <- add_resource( ) # Replace the resource "observations" with a file-based resource (2 TSV files) -path_1 <- system.file("extdata", "observations_1.tsv", package = "frictionless") -path_2 <- system.file("extdata", "observations_2.tsv", package = "frictionless") +path_1 <- +system.file("extdata", "v1", "observations_1.tsv", package = "frictionless") +path_2 <- +system.file("extdata", "v1", "observations_2.tsv", package = "frictionless") package <- add_resource( package, resource_name = "observations", diff --git a/man/read_package.Rd b/man/read_package.Rd index ea725765..2982c2a2 100644 --- a/man/read_package.Rd +++ b/man/read_package.Rd @@ -19,7 +19,7 @@ describes the Data Package metadata and its Data Resources. \examples{ # Read a datapackage.json file package <- read_package( - system.file("extdata", "datapackage.json", package = "frictionless") + system.file("extdata", "v1", "datapackage.json", package = "frictionless") ) package diff --git a/man/read_resource.Rd b/man/read_resource.Rd index 1ab441d4..6848e808 100644 --- a/man/read_resource.Rd +++ b/man/read_resource.Rd @@ -201,7 +201,7 @@ Can be parsed afterwards with \code{\link[lubridate:duration]{lubridate::duratio \examples{ # Read a datapackage.json file package <- read_package( - system.file("extdata", "datapackage.json", package = "frictionless") + system.file("extdata", "v1", "datapackage.json", package = "frictionless") ) package diff --git a/man/write_package.Rd b/man/write_package.Rd index 81d935ac..e9f20847 100644 --- a/man/write_package.Rd +++ b/man/write_package.Rd @@ -39,7 +39,7 @@ Use \code{compress = TRUE} to gzip those CSV files. \examples{ # Load the example Data Package from disk package <- read_package( - system.file("extdata", "datapackage.json", package = "frictionless") + system.file("extdata", "v1", "datapackage.json", package = "frictionless") ) package From ab26085b0aa389826f54075cedbcb83ac0449840 Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:46:21 +0200 Subject: [PATCH 04/32] precompile vignette --- vignettes/frictionless.Rmd | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/vignettes/frictionless.Rmd b/vignettes/frictionless.Rmd index 3df48657..45e8dbfb 100644 --- a/vignettes/frictionless.Rmd +++ b/vignettes/frictionless.Rmd @@ -116,7 +116,7 @@ You can also read data from a local (e.g. downloaded) Data Package. In fact, the ``` r local_package <- read_package( - system.file("extdata", "datapackage.json", package = "frictionless") + system.file("extdata", "v1", "datapackage.json", package = "frictionless") ) local_package @@ -329,8 +329,8 @@ If you already have your data stored as CSV or TSV files and you want to include ``` r # Two TSV files with the same structure -path_1 <- system.file("extdata", "observations_1.tsv", package = "frictionless") -path_2 <- system.file("extdata", "observations_2.tsv", package = "frictionless") +path_1 <- system.file("extdata", "v1", "observations_1.tsv", package = "frictionless") +path_2 <- system.file("extdata", "v1", "observations_2.tsv", package = "frictionless") # Add both TSV files as a single resource my_package <- @@ -340,10 +340,6 @@ my_package <- data = c(path_1, path_2), delim = "\t" ) -#> Error in `purrr::map_chr()` at frictionless-r/R/add_resource.R:132:5: -#> ℹ In index: 1. -#> Caused by error in `check_path()`: -#> ! Can't find file at ''. ``` Your Data Package now contains 2 resources, but you can add metadata properties as well (see the [Data Package documentation](https://specs.frictionlessdata.io/data-package/#metadata) for an overview). Since it is a list, you can use `append()` to insert properties at the desired place. Let's add `name` as first and `title` as second property: @@ -374,7 +370,7 @@ The directory will contain four files: the descriptor `datapackage.json`, one CS ``` r list.files("my_directory") -#> [1] "datapackage.json" "iris.csv" +#> [1] "datapackage.json" "iris.csv" "observations_1.tsv" "observations_2.tsv" ``` From f86a6fb04ea0fcd719aee1452c5d22be79f09c21 Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:47:55 +0200 Subject: [PATCH 05/32] update path --- tests/testthat/test-add_resource.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-add_resource.R b/tests/testthat/test-add_resource.R index 59fa61fe..7c70bf0a 100644 --- a/tests/testthat/test-add_resource.R +++ b/tests/testthat/test-add_resource.R @@ -338,7 +338,7 @@ test_that("add_resource() can add resource from local, relative, absolute, # Absolute (doesn't throw unsafe error) absolute_path <- system.file( - "extdata", "deployments.csv", package = "frictionless" # Will start with / + "extdata", "v1", "deployments.csv", package = "frictionless" # Will start with / ) p <- add_resource(p, "absolute", absolute_path, schema) expect_identical(p$resources[[6]]$path, absolute_path) From 85e97f4a04582b7b26316e1d63cef882958f9340 Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:05:37 +0200 Subject: [PATCH 06/32] add param version --- R/example_package.R | 15 ++++++++++++--- man/example_package.Rd | 6 +++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/R/example_package.R b/R/example_package.R index a42bbe91..ab7b0a7d 100644 --- a/R/example_package.R +++ b/R/example_package.R @@ -9,14 +9,23 @@ #' `"path": ["observations_1.tsv", "observations_2.tsv"]`. #' 3. `media`: inline data stored in `data`. #' +#' @param version Version of the [Data Package]( +#' https://datapackage.org/blog/2024-06-26-v2-release/) standard that this +#' example Data Package uses. Currently only version 1 is supported. #' @return A Data Package object, see [create_package()]. #' @family sample data #' @export #' @examples #' example_package() -example_package <- function() { - path <- system.file( - "extdata", "v1", "datapackage.json", package = "frictionless" +example_package <- function(version = 1) { + if (!version %in% c(1, "1", 1.0, "1.0")) { + cli::cli_abort( + "Currently only version 1 is supported." ) + } else { + path <- system.file( + "extdata", "v1", "datapackage.json", package = "frictionless" + ) + } read_package(path) } diff --git a/man/example_package.Rd b/man/example_package.Rd index e3bf98b9..b961b81c 100644 --- a/man/example_package.Rd +++ b/man/example_package.Rd @@ -4,7 +4,11 @@ \alias{example_package} \title{Read the example Data Package} \usage{ -example_package() +example_package(version = 1) +} +\arguments{ +\item{version}{Version of the \href{https://datapackage.org/blog/2024-06-26-v2-release/}{Data Package} standard that this +example Data Package uses. Currently only version 1 is supported.} } \value{ A Data Package object, see \code{\link[=create_package]{create_package()}}. From f8b31685951a519b47e137fec31f38b23fd5ba6d Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:13:39 +0200 Subject: [PATCH 07/32] update path --- vignettes/data-package.Rmd | 2 +- vignettes/data-resource.Rmd | 10 +++++----- vignettes/table-dialect.Rmd | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vignettes/data-package.Rmd b/vignettes/data-package.Rmd index e40e0f45..f7648976 100644 --- a/vignettes/data-package.Rmd +++ b/vignettes/data-package.Rmd @@ -29,7 +29,7 @@ Frictionless supports reading, manipulating and writing packages. Much of its fu ```{r} library(frictionless) -file <- system.file("extdata", "datapackage.json", package = "frictionless") +file <- system.file("extdata", "v1", "datapackage.json", package = "frictionless") package <- read_package(file) ``` diff --git a/vignettes/data-resource.Rmd b/vignettes/data-resource.Rmd index 4fc9e5d2..d3a8bca7 100644 --- a/vignettes/data-resource.Rmd +++ b/vignettes/data-resource.Rmd @@ -61,7 +61,7 @@ remove_resource(package, "deployments") add_resource(package, "iris", data = iris) # Replace a resource with one where data is stored in a tabular file -path <- system.file("extdata", "deployments.csv", package = "frictionless") +path <- system.file("extdata", "v1", "deployments.csv", package = "frictionless") add_resource(package, "deployments", data = path, replace = TRUE) ``` @@ -105,7 +105,7 @@ read_resource(package, "observations") `add_resource()` sets `path` to the path(s) provided in `data`: ```{r} -path <- system.file("extdata", "deployments.csv", package = "frictionless") +path <- system.file("extdata", "v1", "deployments.csv", package = "frictionless") add_resource(package, "deployments", data = path, replace = TRUE) ``` @@ -176,7 +176,7 @@ delim | format any other value | `"csv"` ```{r} -path <- system.file("extdata", "observations_1.tsv", package = "frictionless") +path <- system.file("extdata", "v1", "observations_1.tsv", package = "frictionless") package <- add_resource(package, "observations", data = path, delim = "\t", replace = TRUE) package$resources[[2]]$format ``` @@ -194,7 +194,7 @@ delim | mediatype any other value | `"text/csv"` ```{r} -path <- system.file("extdata", "observations_1.tsv", package = "frictionless") +path <- system.file("extdata", "v1", "observations_1.tsv", package = "frictionless") package <- add_resource(package, "observations", data = path, delim = "\t", replace = TRUE) package$resources[[2]]$mediatype ``` @@ -208,7 +208,7 @@ package$resources[[2]]$mediatype `add_resource()` guesses the `encoding` (using `readr::guess_encoding()`) when data are provided as file. It leaves the `encoding` undefined when data are provided as a data frame. `write_package()` sets it to `"utf-8"` when writing to disk. ```{r} -path <- system.file("extdata", "deployments.csv", package = "frictionless") +path <- system.file("extdata", "v1", "deployments.csv", package = "frictionless") package <- add_resource(package, "deployments", data = path, delim = ",", replace = TRUE) package$resources[[2]]$encoding ``` diff --git a/vignettes/table-dialect.Rmd b/vignettes/table-dialect.Rmd index 0890ea26..2c974f8b 100644 --- a/vignettes/table-dialect.Rmd +++ b/vignettes/table-dialect.Rmd @@ -52,7 +52,7 @@ Frictionless does not support direct manipulation of the dialect. `add_resource( library(frictionless) package <- example_package() -path <- system.file("extdata", "observations_1.tsv", package = "frictionless") +path <- system.file("extdata", "v1", "observations_1.tsv", package = "frictionless") package <- add_resource(package, "observations", data = path, delim = "\t", replace = TRUE) package$resources[[2]]$dialect$delimiter ``` From 8865e292507624d752ab87626a7052beec6664af Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:28:27 +0200 Subject: [PATCH 08/32] Create test-example_package.R --- tests/testthat/test-example_package.R | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/testthat/test-example_package.R diff --git a/tests/testthat/test-example_package.R b/tests/testthat/test-example_package.R new file mode 100644 index 00000000..36a36af3 --- /dev/null +++ b/tests/testthat/test-example_package.R @@ -0,0 +1,14 @@ +test_that("example_package() returns error on invalid version", { + expect_error( + example_package("2"), + class = "frictionless_error_example_package_version_invalid" + ) + expect_error( + example_package(2), + class = "frictionless_error_example_package_version_invalid" + ) + expect_error( + example_package(2.0), + class = "frictionless_error_example_package_version_invalid" + ) +}) From d8eef96f886081524c8e737efd92fec28c5282c8 Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:29:10 +0200 Subject: [PATCH 09/32] add error class --- R/example_package.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/example_package.R b/R/example_package.R index ab7b0a7d..aafdef17 100644 --- a/R/example_package.R +++ b/R/example_package.R @@ -20,7 +20,8 @@ example_package <- function(version = 1) { if (!version %in% c(1, "1", 1.0, "1.0")) { cli::cli_abort( - "Currently only version 1 is supported." + "Currently only version 1 (`version = 1`) is supported.", + class = "frictionless_error_example_package_version_invalid" ) } else { path <- system.file( From bbce5069247358359a2cc9d2261b9ae21cca9861 Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:45:40 +0200 Subject: [PATCH 10/32] copy v1 example data packaga --- inst/extdata/v2/datapackage.json | 222 +++++++++++++++++++++++++++++ inst/extdata/v2/deployments.csv | 4 + inst/extdata/v2/observations_1.tsv | 4 + inst/extdata/v2/observations_2.tsv | 6 + 4 files changed, 236 insertions(+) create mode 100644 inst/extdata/v2/datapackage.json create mode 100644 inst/extdata/v2/deployments.csv create mode 100644 inst/extdata/v2/observations_1.tsv create mode 100644 inst/extdata/v2/observations_2.tsv diff --git a/inst/extdata/v2/datapackage.json b/inst/extdata/v2/datapackage.json new file mode 100644 index 00000000..e201b027 --- /dev/null +++ b/inst/extdata/v2/datapackage.json @@ -0,0 +1,222 @@ +{ + "name": "example_package", + "id": "115f49c1-8603-463e-a908-68de98327266", + "created": "2021-03-02T17:22:33Z", + "image": null, + "licenses": [ + { + "name": "CC0-1.0", + "path": "https://creativecommons.org/publicdomain/zero/1.0/", + "title": "CC0 1.0" + } + ], + "temporal": { + "start": "2020-01-01", + "end": "2021-01-10" + }, + "resources": [ + { + "name": "deployments", + "path": "deployments.csv", + "profile": "tabular-data-resource", + "title": "Camera trap deployments", + "format": "csv", + "mediatype": "text/csv", + "encoding": "utf-8", + "schema": { + "fields": [ + { + "name": "deployment_id", + "type": "string", + "constraints": { + "required": true, + "unique": true + } + }, + { + "name": "longitude", + "type": "number", + "constraints": { + "required": true, + "minimum": -180, + "maximum": 180 + } + }, + { + "name": "latitude", + "constraints": { + "required": true + } + }, + { + "name": "start", + "type": "date", + "format": "%x", + "constraints": { + "required": true + } + }, + { + "name": "comments", + "type": "string", + "constraints": { + "required": false + } + } + ], + "missingValues": ["", "NA", "NaN"], + "primaryKey": "deployment_id" + } + }, + { + "name": "observations", + "path": ["observations_1.tsv", "observations_2.tsv"], + "profile": "tabular-data-resource", + "title": "Camera trap observations", + "format": "csv", + "mediatype": "text/csv", + "encoding": "utf-8", + "dialect": { + "delimiter": "\t" + }, + "schema": { + "fields": [ + { + "name": "observation_id", + "type": "string", + "constraints": { + "required": true, + "unique": true + } + }, + { + "name": "deployment_id", + "type": "string", + "constraints": { + "required": true + } + }, + { + "name": "timestamp", + "type": "datetime", + "format": "%Y-%m-%dT%H:%M:%S%z", + "constraints": { + "required": true + } + }, + { + "name": "scientific_name", + "type": "string", + "constraints": { + "required": false + } + }, + { + "name": "count", + "type": "integer", + "constraints": { + "required": false, + "minimum": 1 + } + }, + { + "name": "life_stage", + "type": "string", + "constraints": { + "required": false, + "enum": ["adult", "subadult", "juvenile", "offspring", "unknown"] + } + }, + { + "name": "comments", + "type": "string", + "constraints": { + "required": false + } + } + ], + "missingValues": ["", "NA", "NaN"], + "primaryKey": "observation_id", + "foreignKeys": [ + { + "fields": "deployment_id", + "reference": { + "resource": "deployments", + "fields": "deployment_id" + } + } + ] + } + }, + { + "name": "media", + "data": [ + { + "media_id": "aed5fa71-3ed4-4284-a6ba-3550d1a4de8d", + "deployment_id": "1", + "observation_id": "1-1", + "timestamp": "2020-09-28 02:14:59+02:00", + "file_path": "https://multimedia.agouti.eu/assets/aed5fa71-3ed4-4284-a6ba-3550d1a4de8d/file" + }, + { + "media_id": "da81a501-8236-4cbd-aa95-4bc4b10a05df", + "deployment_id": "1", + "observation_id": "1-1", + "timestamp": "2020-09-28 02:15:00+02:00", + "file_path": "https://multimedia.agouti.eu/assets/da81a501-8236-4cbd-aa95-4bc4b10a05df/file" + }, + { + "media_id": "0ba57608-3cf1-49d6-a5a2-fe680851024d", + "deployment_id": "1", + "observation_id": "1-1", + "timestamp": "2020-09-28 02:15:01+02:00", + "file_path": "https://multimedia.agouti.eu/assets/0ba57608-3cf1-49d6-a5a2-fe680851024d/file" + } + ], + "profile": "tabular-data-resource", + "title": "Camera trap media files", + "schema": { + "fields": [ + { + "name": "media_id", + "type": "string" + }, + { + "name": "deployment_id", + "type": "string" + }, + { + "name": "observation_id", + "type": "string" + }, + { + "name": "timestamp", + "type": "datetime", + "format": "%Y-%m-%d %H:%M:%S%z" + }, + { + "name": "file_path", + "type": "string" + } + ], + "primaryKey": "media_id", + "foreignKeys": [ + { + "fields": "deployment_id", + "reference": { + "resource": "deployments", + "fields": "deployment_id" + } + }, + { + "fields": "observation_id", + "reference": { + "resource": "observations", + "fields": "observation_id" + } + } + ] + } + } + ] +} diff --git a/inst/extdata/v2/deployments.csv b/inst/extdata/v2/deployments.csv new file mode 100644 index 00000000..2af8ddf7 --- /dev/null +++ b/inst/extdata/v2/deployments.csv @@ -0,0 +1,4 @@ +deployment_id,longitude,latitude,start,comments +1,4.61612,50.76698,09/25/20, +2,4.64286,50.82716,10/01/20,"On ""forêt"" road." +3,4.65100,50.81860,10/05/20,"Malfunction/no photos, data" diff --git a/inst/extdata/v2/observations_1.tsv b/inst/extdata/v2/observations_1.tsv new file mode 100644 index 00000000..047d10b5 --- /dev/null +++ b/inst/extdata/v2/observations_1.tsv @@ -0,0 +1,4 @@ +observation_id deployment_id timestamp scientific_name count life_stage comments +1-1 1 2020-09-28T00:13:07Z Capreolus capreolus 1 juvenile Comment 1 +1-2 1 2020-09-28T15:59:17Z Capreolus capreolus 1 adult Comment 2 +1-3 1 2020-09-28T16:35:23Z Lepus europaeus 1 adult Comment 3 diff --git a/inst/extdata/v2/observations_2.tsv b/inst/extdata/v2/observations_2.tsv new file mode 100644 index 00000000..883ec4b3 --- /dev/null +++ b/inst/extdata/v2/observations_2.tsv @@ -0,0 +1,6 @@ +observation_id deployment_id timestamp scientific_name count life_stage comments +1-4 1 2020-09-28T17:04:04Z Lepus europaeus 1 adult NA +1-5 1 2020-09-28T19:19:54Z Sus scrofa 2 unknown NA +2-1 2 2021-10-01T01:25:06Z Sus scrofa 1 unknown Duplicate +2-2 2 2021-10-01T01:25:06Z Sus scrofa 1 unknown Duplicate +2-3 2 2021-10-01T04:47:30Z Sus scrofa 1 unknown NA From 678ed47ef0623e92aa0928cb33f86f819c2c0c65 Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:51:18 +0200 Subject: [PATCH 11/32] add https://datapackage.org/overview/changelog/#packageschema-new --- inst/extdata/v2/datapackage.json | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/extdata/v2/datapackage.json b/inst/extdata/v2/datapackage.json index e201b027..bd6bae04 100644 --- a/inst/extdata/v2/datapackage.json +++ b/inst/extdata/v2/datapackage.json @@ -1,4 +1,5 @@ { + "$schema": "https://datapackage.org/profiles/2.0/datapackage.json" "name": "example_package", "id": "115f49c1-8603-463e-a908-68de98327266", "created": "2021-03-02T17:22:33Z", From f82919165697e158833100bfea8ce91276d2818d Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:01:01 +0200 Subject: [PATCH 12/32] reorder to match https://datapackage.org/standard/data-package/ --- inst/extdata/v2/datapackage.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/extdata/v2/datapackage.json b/inst/extdata/v2/datapackage.json index bd6bae04..13bee44d 100644 --- a/inst/extdata/v2/datapackage.json +++ b/inst/extdata/v2/datapackage.json @@ -2,8 +2,6 @@ "$schema": "https://datapackage.org/profiles/2.0/datapackage.json" "name": "example_package", "id": "115f49c1-8603-463e-a908-68de98327266", - "created": "2021-03-02T17:22:33Z", - "image": null, "licenses": [ { "name": "CC0-1.0", @@ -11,6 +9,8 @@ "title": "CC0 1.0" } ], + "image": null, + "created": "2021-03-02T17:22:33Z", "temporal": { "start": "2020-01-01", "end": "2021-01-10" From 5344d0f42c5e30afc8d62dc433af70868fe10d9e Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:05:11 +0200 Subject: [PATCH 13/32] https://datapackage.org/overview/changelog/#resourcetype-new --- inst/extdata/v2/datapackage.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inst/extdata/v2/datapackage.json b/inst/extdata/v2/datapackage.json index 13bee44d..23ddf97c 100644 --- a/inst/extdata/v2/datapackage.json +++ b/inst/extdata/v2/datapackage.json @@ -19,7 +19,7 @@ { "name": "deployments", "path": "deployments.csv", - "profile": "tabular-data-resource", + "type": "table", "title": "Camera trap deployments", "format": "csv", "mediatype": "text/csv", @@ -72,7 +72,7 @@ { "name": "observations", "path": ["observations_1.tsv", "observations_2.tsv"], - "profile": "tabular-data-resource", + "type": "table", "title": "Camera trap observations", "format": "csv", "mediatype": "text/csv", @@ -174,7 +174,7 @@ "file_path": "https://multimedia.agouti.eu/assets/0ba57608-3cf1-49d6-a5a2-fe680851024d/file" } ], - "profile": "tabular-data-resource", + "type": "table", "title": "Camera trap media files", "schema": { "fields": [ From 0c0fdf5c8156a222f0adcfccf8c7d1afe3663d3d Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:10:02 +0200 Subject: [PATCH 14/32] add version (https://datapackage.org/overview/changelog/#packageversion-updated) --- inst/extdata/v2/datapackage.json | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/extdata/v2/datapackage.json b/inst/extdata/v2/datapackage.json index 23ddf97c..f60669eb 100644 --- a/inst/extdata/v2/datapackage.json +++ b/inst/extdata/v2/datapackage.json @@ -10,6 +10,7 @@ } ], "image": null, + "version": "2.0", "created": "2021-03-02T17:22:33Z", "temporal": { "start": "2020-01-01", From 55b32cbfb324aee8527058585a1ac2ff0fb0b9ff Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:52:06 +0200 Subject: [PATCH 15/32] Version should be a string value "1.0" --- R/example_package.R | 14 +++++++++----- man/example_package.Rd | 4 ++-- tests/testthat/test-example_package.R | 12 ++++++------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/R/example_package.R b/R/example_package.R index aafdef17..f88731a9 100644 --- a/R/example_package.R +++ b/R/example_package.R @@ -11,17 +11,21 @@ #' #' @param version Version of the [Data Package]( #' https://datapackage.org/blog/2024-06-26-v2-release/) standard that this -#' example Data Package uses. Currently only version 1 is supported. +#' example Data Package uses. Currently only version 1.0 is supported. #' @return A Data Package object, see [create_package()]. #' @family sample data #' @export #' @examples #' example_package() -example_package <- function(version = 1) { - if (!version %in% c(1, "1", 1.0, "1.0")) { +example_package <- function(version = "1.0") { + supported_versions <- c("1.0") + if (version %in% supported_versions) { cli::cli_abort( - "Currently only version 1 (`version = 1`) is supported.", - class = "frictionless_error_example_package_version_invalid" + c( + "{.val {version}} is not a supported Data Package version.", + "i" = "Supported version{?s}: {.val {supported_versions}}." + ), + class = "frictionless_error_unsupported_version" ) } else { path <- system.file( diff --git a/man/example_package.Rd b/man/example_package.Rd index b961b81c..9441102d 100644 --- a/man/example_package.Rd +++ b/man/example_package.Rd @@ -4,11 +4,11 @@ \alias{example_package} \title{Read the example Data Package} \usage{ -example_package(version = 1) +example_package(version = "1.0") } \arguments{ \item{version}{Version of the \href{https://datapackage.org/blog/2024-06-26-v2-release/}{Data Package} standard that this -example Data Package uses. Currently only version 1 is supported.} +example Data Package uses. Currently only version 1.0 is supported.} } \value{ A Data Package object, see \code{\link[=create_package]{create_package()}}. diff --git a/tests/testthat/test-example_package.R b/tests/testthat/test-example_package.R index 36a36af3..5a88a2d8 100644 --- a/tests/testthat/test-example_package.R +++ b/tests/testthat/test-example_package.R @@ -1,14 +1,14 @@ test_that("example_package() returns error on invalid version", { expect_error( - example_package("2"), - class = "frictionless_error_example_package_version_invalid" + example_package("1"), + class = "frictionless_error_unsupported_version" ) expect_error( - example_package(2), - class = "frictionless_error_example_package_version_invalid" + example_package("1.0.0"), + class = "frictionless_error_unsupported_version" ) expect_error( - example_package(2.0), - class = "frictionless_error_example_package_version_invalid" + example_package(1.0), + class = "frictionless_error_unsupported_version" ) }) From 423a367a56f52247f15715bbe0032b0c2bb457bf Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:56:58 +0200 Subject: [PATCH 16/32] add resources.$schema --- inst/extdata/v2/datapackage.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/inst/extdata/v2/datapackage.json b/inst/extdata/v2/datapackage.json index f60669eb..40b4b5e0 100644 --- a/inst/extdata/v2/datapackage.json +++ b/inst/extdata/v2/datapackage.json @@ -1,5 +1,5 @@ { - "$schema": "https://datapackage.org/profiles/2.0/datapackage.json" + "$schema": "https://datapackage.org/profiles/2.0/datapackage.json", "name": "example_package", "id": "115f49c1-8603-463e-a908-68de98327266", "licenses": [ @@ -21,6 +21,7 @@ "name": "deployments", "path": "deployments.csv", "type": "table", + "$schema": "https://datapackage.org/profiles/2.0/dataresource.json", "title": "Camera trap deployments", "format": "csv", "mediatype": "text/csv", @@ -74,6 +75,7 @@ "name": "observations", "path": ["observations_1.tsv", "observations_2.tsv"], "type": "table", + "$schema": "https://datapackage.org/profiles/2.0/dataresource.json", "title": "Camera trap observations", "format": "csv", "mediatype": "text/csv", @@ -176,6 +178,7 @@ } ], "type": "table", + "$schema": "https://datapackage.org/profiles/2.0/dataresource.json", "title": "Camera trap media files", "schema": { "fields": [ From 7575c54bc5d7ed2173c15ebacb09fc8a23d290d0 Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:59:47 +0200 Subject: [PATCH 17/32] fix error --- R/example_package.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/example_package.R b/R/example_package.R index f88731a9..86993390 100644 --- a/R/example_package.R +++ b/R/example_package.R @@ -19,7 +19,7 @@ #' example_package() example_package <- function(version = "1.0") { supported_versions <- c("1.0") - if (version %in% supported_versions) { + if (!version %in% supported_versions) { cli::cli_abort( c( "{.val {version}} is not a supported Data Package version.", From 0f193e47b86279b86285dbd88550359ee4e5044a Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:54:42 +0200 Subject: [PATCH 18/32] primaryKey and foreignKeys should be an array of strings --- inst/extdata/v2/datapackage.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/inst/extdata/v2/datapackage.json b/inst/extdata/v2/datapackage.json index 40b4b5e0..55f72d62 100644 --- a/inst/extdata/v2/datapackage.json +++ b/inst/extdata/v2/datapackage.json @@ -68,7 +68,7 @@ } ], "missingValues": ["", "NA", "NaN"], - "primaryKey": "deployment_id" + "primaryKey": ["deployment_id"] } }, { @@ -140,13 +140,13 @@ } ], "missingValues": ["", "NA", "NaN"], - "primaryKey": "observation_id", + "primaryKey": ["observation_id"], "foreignKeys": [ { - "fields": "deployment_id", + "fields": ["deployment_id"], "reference": { "resource": "deployments", - "fields": "deployment_id" + "fields": ["deployment_id"] } } ] @@ -204,20 +204,20 @@ "type": "string" } ], - "primaryKey": "media_id", + "primaryKey": ["media_id"], "foreignKeys": [ { - "fields": "deployment_id", + "fields": ["deployment_id"], "reference": { "resource": "deployments", - "fields": "deployment_id" + "fields": ["deployment_id"] } }, { - "fields": "observation_id", + "fields": ["observation_id"], "reference": { "resource": "observations", - "fields": "observation_id" + "fields": ["observation_id"] } } ] From a62d0288321f220d32bd9698d73d345e8a810609 Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:20:51 +0200 Subject: [PATCH 19/32] add version 2.0 --- R/example_package.R | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/R/example_package.R b/R/example_package.R index 86993390..f8a135d1 100644 --- a/R/example_package.R +++ b/R/example_package.R @@ -11,14 +11,14 @@ #' #' @param version Version of the [Data Package]( #' https://datapackage.org/blog/2024-06-26-v2-release/) standard that this -#' example Data Package uses. Currently only version 1.0 is supported. +#' example Data Package uses. #' @return A Data Package object, see [create_package()]. #' @family sample data #' @export #' @examples #' example_package() example_package <- function(version = "1.0") { - supported_versions <- c("1.0") + supported_versions <- c("1.0", "2.0") if (!version %in% supported_versions) { cli::cli_abort( c( @@ -27,10 +27,15 @@ example_package <- function(version = "1.0") { ), class = "frictionless_error_unsupported_version" ) - } else { + } + if (version == "1.0") { path <- system.file( "extdata", "v1", "datapackage.json", package = "frictionless" ) + } else { + path <- system.file( + "extdata", "v2", "datapackage.json", package = "frictionless" + ) } read_package(path) } From 5dd7ac6a909142ec74bab8514734873cd8ee47eb Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:24:38 +0200 Subject: [PATCH 20/32] add tests on versions --- tests/testthat/test-example_package.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/testthat/test-example_package.R b/tests/testthat/test-example_package.R index 5a88a2d8..1c670696 100644 --- a/tests/testthat/test-example_package.R +++ b/tests/testthat/test-example_package.R @@ -12,3 +12,19 @@ test_that("example_package() returns error on invalid version", { class = "frictionless_error_unsupported_version" ) }) + +test_that("example_package() uses the correct version", { + # version 1.0 + p_v1 <- example_package() + p_local_v1 <- read_package( + system.file("extdata", "v1", "datapackage.json", package = "frictionless") + ) + expect_identical(p_v1, p_local_v1) + + # version 2.0 + p_v2 <- example_package(version = "2.0") + p_local_v2 <- read_package( + system.file("extdata", "v2", "datapackage.json", package = "frictionless") + ) + expect_identical(p_v2, p_local_v2) +}) From c40ddb3471cbbd681a2973a29af3b8b69f5b0a41 Mon Sep 17 00:00:00 2001 From: Sanne Govaert <44606923+sannegovaert@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:25:27 +0200 Subject: [PATCH 21/32] document() --- man/example_package.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/example_package.Rd b/man/example_package.Rd index 9441102d..a06f4cc3 100644 --- a/man/example_package.Rd +++ b/man/example_package.Rd @@ -8,7 +8,7 @@ example_package(version = "1.0") } \arguments{ \item{version}{Version of the \href{https://datapackage.org/blog/2024-06-26-v2-release/}{Data Package} standard that this -example Data Package uses. Currently only version 1.0 is supported.} +example Data Package uses.} } \value{ A Data Package object, see \code{\link[=create_package]{create_package()}}. From e6f1ff0719f63440931d86e29ffe32a91224f5bf Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Thu, 29 Aug 2024 10:36:00 +0200 Subject: [PATCH 22/32] Add version to v1 and order image and created the same --- inst/extdata/v1/datapackage.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/inst/extdata/v1/datapackage.json b/inst/extdata/v1/datapackage.json index e201b027..8ec3ea3a 100644 --- a/inst/extdata/v1/datapackage.json +++ b/inst/extdata/v1/datapackage.json @@ -1,8 +1,6 @@ { "name": "example_package", "id": "115f49c1-8603-463e-a908-68de98327266", - "created": "2021-03-02T17:22:33Z", - "image": null, "licenses": [ { "name": "CC0-1.0", @@ -10,6 +8,11 @@ "title": "CC0 1.0" } ], + "image": null, + "version": "1.0", + "created": "2021-03-02T17:22:33Z", + + "temporal": { "start": "2020-01-01", "end": "2021-01-10" From fce05a0e83bc00a556e434b4253c0321e5e8c03c Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Thu, 29 Aug 2024 10:36:47 +0200 Subject: [PATCH 23/32] Add $schema to schema and dialect --- inst/extdata/v2/datapackage.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inst/extdata/v2/datapackage.json b/inst/extdata/v2/datapackage.json index 55f72d62..3f31f108 100644 --- a/inst/extdata/v2/datapackage.json +++ b/inst/extdata/v2/datapackage.json @@ -67,6 +67,7 @@ } } ], + "$schema": "https://datapackage.org/profiles/2.0/tableschema.json", "missingValues": ["", "NA", "NaN"], "primaryKey": ["deployment_id"] } @@ -81,6 +82,7 @@ "mediatype": "text/csv", "encoding": "utf-8", "dialect": { + "$schema": "https://datapackage.org/profiles/2.0/tabledialect.json", "delimiter": "\t" }, "schema": { @@ -140,6 +142,7 @@ } ], "missingValues": ["", "NA", "NaN"], + "$schema": "https://datapackage.org/profiles/2.0/tableschema.json", "primaryKey": ["observation_id"], "foreignKeys": [ { @@ -204,6 +207,7 @@ "type": "string" } ], + "$schema": "https://datapackage.org/profiles/2.0/tableschema.json", "primaryKey": ["media_id"], "foreignKeys": [ { From 2b1e0128ac2214fb69330934fd0b0bf1dc118526 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Thu, 29 Aug 2024 10:37:15 +0200 Subject: [PATCH 24/32] Change missing values to one with labels --- inst/extdata/v2/datapackage.json | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/inst/extdata/v2/datapackage.json b/inst/extdata/v2/datapackage.json index 3f31f108..2375ceec 100644 --- a/inst/extdata/v2/datapackage.json +++ b/inst/extdata/v2/datapackage.json @@ -141,8 +141,21 @@ } } ], - "missingValues": ["", "NA", "NaN"], "$schema": "https://datapackage.org/profiles/2.0/tableschema.json", + "missingValues": [ + { + "value": "", + "label": "missing" + }, + { + "value": "NA", + "label": "not applicable" + }, + { + "value": "NaN", + "label": "not a number" + } + ], "primaryKey": ["observation_id"], "foreignKeys": [ { From 24016444fdf4d75392da3d8130a2d06265ee06de Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Thu, 29 Aug 2024 10:37:29 +0200 Subject: [PATCH 25/32] Update created date --- inst/extdata/v2/datapackage.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/extdata/v2/datapackage.json b/inst/extdata/v2/datapackage.json index 2375ceec..f9bd5abc 100644 --- a/inst/extdata/v2/datapackage.json +++ b/inst/extdata/v2/datapackage.json @@ -11,7 +11,7 @@ ], "image": null, "version": "2.0", - "created": "2021-03-02T17:22:33Z", + "created": "2024-08-27T12:45:21Z", "temporal": { "start": "2020-01-01", "end": "2021-01-10" From 29933388d83ce94fcb69be36e93b4faf79be2fcb Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Thu, 29 Aug 2024 10:37:44 +0200 Subject: [PATCH 26/32] Change enum to categories --- inst/extdata/v2/datapackage.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inst/extdata/v2/datapackage.json b/inst/extdata/v2/datapackage.json index f9bd5abc..c611f4c9 100644 --- a/inst/extdata/v2/datapackage.json +++ b/inst/extdata/v2/datapackage.json @@ -128,9 +128,10 @@ { "name": "life_stage", "type": "string", + "categories": ["adult", "subadult", "juvenile", "offspring", "unknown"], + "categoriesOrdered": false, "constraints": { - "required": false, - "enum": ["adult", "subadult", "juvenile", "offspring", "unknown"] + "required": false } }, { From b06ff8c71ff65c967d254791d8b446f6c7130a25 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Thu, 29 Aug 2024 13:23:42 +0200 Subject: [PATCH 27/32] Update doc and example --- R/example_package.R | 12 +++++++++--- man/example_package.Rd | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/R/example_package.R b/R/example_package.R index f8a135d1..bb21ff45 100644 --- a/R/example_package.R +++ b/R/example_package.R @@ -9,14 +9,20 @@ #' `"path": ["observations_1.tsv", "observations_2.tsv"]`. #' 3. `media`: inline data stored in `data`. #' -#' @param version Version of the [Data Package]( -#' https://datapackage.org/blog/2024-06-26-v2-release/) standard that this -#' example Data Package uses. +#' The example Data Package is available in two versions: +#' - `v1`: specified with [Data Package v1](https://specs.frictionlessdata.io/). +#' - `v2`: specified with [Data Package v2](https://datapackage.org/). +#' +#' @param version Data Package standard version. #' @return A Data Package object, see [create_package()]. #' @family sample data #' @export #' @examples +#' # Version 1 #' example_package() +#' +#' # Version 2 +#' example_package(version = "2.0") example_package <- function(version = "1.0") { supported_versions <- c("1.0", "2.0") if (!version %in% supported_versions) { diff --git a/man/example_package.Rd b/man/example_package.Rd index a06f4cc3..f84f93bf 100644 --- a/man/example_package.Rd +++ b/man/example_package.Rd @@ -7,8 +7,7 @@ example_package(version = "1.0") } \arguments{ -\item{version}{Version of the \href{https://datapackage.org/blog/2024-06-26-v2-release/}{Data Package} standard that this -example Data Package uses.} +\item{version}{Data Package standard version.} } \value{ A Data Package object, see \code{\link[=create_package]{create_package()}}. @@ -25,7 +24,18 @@ camera trap data organized in 3 Data Resources: \item \code{media}: inline data stored in \code{data}. } } +\details{ +The example Data Package is available in two versions: +\itemize{ +\item \code{v1}: specified with \href{https://specs.frictionlessdata.io/}{Data Package v1}. +\item \code{v2}: specified with \href{https://datapackage.org/}{Data Package v2}. +} +} \examples{ +# Version 1 example_package() + +# Version 2 +example_package(version = "2.0") } \concept{sample data} From 7e447093e455a5a216c8f3d4c1a56032beeb49a2 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Thu, 29 Aug 2024 13:23:42 +0200 Subject: [PATCH 28/32] Update doc and example --- R/example_package.R | 13 ++++++++++--- man/example_package.Rd | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/R/example_package.R b/R/example_package.R index f8a135d1..c7515a01 100644 --- a/R/example_package.R +++ b/R/example_package.R @@ -9,14 +9,21 @@ #' `"path": ["observations_1.tsv", "observations_2.tsv"]`. #' 3. `media`: inline data stored in `data`. #' -#' @param version Version of the [Data Package]( -#' https://datapackage.org/blog/2024-06-26-v2-release/) standard that this -#' example Data Package uses. +#' The example Data Package is available in two versions: +#' - `1.0`: specified as a [Data Package v1]( +#' https://specs.frictionlessdata.io/). +#' - `2.0`: specified as a [Data Package v2](https://datapackage.org/). +#' +#' @param version Data Package standard version. #' @return A Data Package object, see [create_package()]. #' @family sample data #' @export #' @examples +#' # Version 1 #' example_package() +#' +#' # Version 2 +#' example_package(version = "2.0") example_package <- function(version = "1.0") { supported_versions <- c("1.0", "2.0") if (!version %in% supported_versions) { diff --git a/man/example_package.Rd b/man/example_package.Rd index a06f4cc3..0b9beb99 100644 --- a/man/example_package.Rd +++ b/man/example_package.Rd @@ -7,8 +7,7 @@ example_package(version = "1.0") } \arguments{ -\item{version}{Version of the \href{https://datapackage.org/blog/2024-06-26-v2-release/}{Data Package} standard that this -example Data Package uses.} +\item{version}{Data Package standard version.} } \value{ A Data Package object, see \code{\link[=create_package]{create_package()}}. @@ -25,7 +24,18 @@ camera trap data organized in 3 Data Resources: \item \code{media}: inline data stored in \code{data}. } } +\details{ +The example Data Package is available in two versions: +\itemize{ +\item \code{1.0}: specified as a \href{https://specs.frictionlessdata.io/}{Data Package v1}. +\item \code{2.0}: specified as a \href{https://datapackage.org/}{Data Package v2}. +} +} \examples{ +# Version 1 example_package() + +# Version 2 +example_package(version = "2.0") } \concept{sample data} From 8c7a66ac044325171e27f681a385b8a4a7562dd9 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Thu, 29 Aug 2024 13:59:00 +0200 Subject: [PATCH 29/32] Rather than returning error, default to 1.0 --- R/example_package.R | 28 ++++++++--------------- tests/testthat/test-example_package.R | 33 +++++++-------------------- 2 files changed, 17 insertions(+), 44 deletions(-) diff --git a/R/example_package.R b/R/example_package.R index c7515a01..9f3653ff 100644 --- a/R/example_package.R +++ b/R/example_package.R @@ -25,24 +25,14 @@ #' # Version 2 #' example_package(version = "2.0") example_package <- function(version = "1.0") { - supported_versions <- c("1.0", "2.0") - if (!version %in% supported_versions) { - cli::cli_abort( - c( - "{.val {version}} is not a supported Data Package version.", - "i" = "Supported version{?s}: {.val {supported_versions}}." - ), - class = "frictionless_error_unsupported_version" - ) - } - if (version == "1.0") { - path <- system.file( - "extdata", "v1", "datapackage.json", package = "frictionless" - ) - } else { - path <- system.file( - "extdata", "v2", "datapackage.json", package = "frictionless" - ) - } + version_dir <- switch( + version %||% "1.0", + "2.0" = "v2", + "1.0" = "v1", + "v1" # Use v1 for any other value + ) + path <- system.file( + "extdata", version_dir, "datapackage.json", package = "frictionless" + ) read_package(path) } diff --git a/tests/testthat/test-example_package.R b/tests/testthat/test-example_package.R index 1c670696..9897db82 100644 --- a/tests/testthat/test-example_package.R +++ b/tests/testthat/test-example_package.R @@ -1,30 +1,13 @@ -test_that("example_package() returns error on invalid version", { - expect_error( - example_package("1"), - class = "frictionless_error_unsupported_version" - ) - expect_error( - example_package("1.0.0"), - class = "frictionless_error_unsupported_version" - ) - expect_error( - example_package(1.0), - class = "frictionless_error_unsupported_version" - ) -}) - -test_that("example_package() uses the correct version", { - # version 1.0 - p_v1 <- example_package() - p_local_v1 <- read_package( +test_that("example_package() allows version selection (default 1.0)", { + p_v1 <- read_package( system.file("extdata", "v1", "datapackage.json", package = "frictionless") ) - expect_identical(p_v1, p_local_v1) - - # version 2.0 - p_v2 <- example_package(version = "2.0") - p_local_v2 <- read_package( + p_v2 <- read_package( system.file("extdata", "v2", "datapackage.json", package = "frictionless") ) - expect_identical(p_v2, p_local_v2) + + expect_identical(example_package("1.0"), p_v1) + expect_identical(example_package("2.0"), p_v2) + expect_identical(example_package("not_a_version"), p_v1) + expect_identical(example_package(version = NULL), p_v1) }) From 24bb578e265b27f7df6a6367672cf818a4bf36fa Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Thu, 29 Aug 2024 14:03:40 +0200 Subject: [PATCH 30/32] Update example_package.R --- R/example_package.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/example_package.R b/R/example_package.R index 9f3653ff..fe257be7 100644 --- a/R/example_package.R +++ b/R/example_package.R @@ -29,7 +29,7 @@ example_package <- function(version = "1.0") { version %||% "1.0", "2.0" = "v2", "1.0" = "v1", - "v1" # Use v1 for any other value + "v1" # Default v1 for any other value ) path <- system.file( "extdata", version_dir, "datapackage.json", package = "frictionless" From ae72c5100c9cdd4504480b2940819053a9947af4 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Thu, 29 Aug 2024 14:33:28 +0200 Subject: [PATCH 31/32] Fix test --- inst/extdata/v1/datapackage.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/inst/extdata/v1/datapackage.json b/inst/extdata/v1/datapackage.json index 8ec3ea3a..4bfd870c 100644 --- a/inst/extdata/v1/datapackage.json +++ b/inst/extdata/v1/datapackage.json @@ -11,8 +11,6 @@ "image": null, "version": "1.0", "created": "2021-03-02T17:22:33Z", - - "temporal": { "start": "2020-01-01", "end": "2021-01-10" From 07f20026dc42c9ab7eb84c31a1f7159986414010 Mon Sep 17 00:00:00 2001 From: Peter Desmet Date: Thu, 29 Aug 2024 14:51:44 +0200 Subject: [PATCH 32/32] Update NEWS.md --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 7b9626ff..bded1f6f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # frictionless 1.2.0 +* `example_package()` now has a `version` parameter, allowing to load the example Data Package following the Data Package [v1](https://specs.frictionlessdata.io/) or [v2](https://datapackage.org/) specification (#249). + ## Changes for users * `add_resource()` now allows to replace an existing resource (#227).