Skip to content

Commit

Permalink
Merge pull request #258 from frictionlessdata/v2-example_package
Browse files Browse the repository at this point in the history
Create a v2 `example_package()`
  • Loading branch information
peterdesmet authored Aug 29, 2024
2 parents 33aade2 + 07f2002 commit d5e723e
Show file tree
Hide file tree
Showing 29 changed files with 348 additions and 36 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# 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).
Expand Down
6 changes: 4 additions & 2 deletions R/add_resource.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,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",
Expand Down
22 changes: 20 additions & 2 deletions R/example_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@
#' `"path": ["observations_1.tsv", "observations_2.tsv"]`.
#' 3. `media`: inline data stored in `data`.
#'
#' 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()
example_package <- function() {
path <- system.file("extdata", "datapackage.json", package = "frictionless")
#'
#' # Version 2
#' example_package(version = "2.0")
example_package <- function(version = "1.0") {
version_dir <- switch(
version %||% "1.0",
"2.0" = "v2",
"1.0" = "v1",
"v1" # Default v1 for any other value
)
path <- system.file(
"extdata", version_dir, "datapackage.json", package = "frictionless"
)
read_package(path)
}
2 changes: 1 addition & 1 deletion R/read_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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
Expand Down
2 changes: 1 addition & 1 deletion R/read_resource.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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
Expand Down
2 changes: 1 addition & 1 deletion R/write_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"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"
}
],
"image": null,
"version": "1.0",
"created": "2021-03-02T17:22:33Z",
"temporal": {
"start": "2020-01-01",
"end": "2021-01-10"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
245 changes: 245 additions & 0 deletions inst/extdata/v2/datapackage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
{
"$schema": "https://datapackage.org/profiles/2.0/datapackage.json",
"name": "example_package",
"id": "115f49c1-8603-463e-a908-68de98327266",
"licenses": [
{
"name": "CC0-1.0",
"path": "https://creativecommons.org/publicdomain/zero/1.0/",
"title": "CC0 1.0"
}
],
"image": null,
"version": "2.0",
"created": "2024-08-27T12:45:21Z",
"temporal": {
"start": "2020-01-01",
"end": "2021-01-10"
},
"resources": [
{
"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",
"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
}
}
],
"$schema": "https://datapackage.org/profiles/2.0/tableschema.json",
"missingValues": ["", "NA", "NaN"],
"primaryKey": ["deployment_id"]
}
},
{
"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",
"encoding": "utf-8",
"dialect": {
"$schema": "https://datapackage.org/profiles/2.0/tabledialect.json",
"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",
"categories": ["adult", "subadult", "juvenile", "offspring", "unknown"],
"categoriesOrdered": false,
"constraints": {
"required": false
}
},
{
"name": "comments",
"type": "string",
"constraints": {
"required": false
}
}
],
"$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": [
{
"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"
}
],
"type": "table",
"$schema": "https://datapackage.org/profiles/2.0/dataresource.json",
"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"
}
],
"$schema": "https://datapackage.org/profiles/2.0/tableschema.json",
"primaryKey": ["media_id"],
"foreignKeys": [
{
"fields": ["deployment_id"],
"reference": {
"resource": "deployments",
"fields": ["deployment_id"]
}
},
{
"fields": ["observation_id"],
"reference": {
"resource": "observations",
"fields": ["observation_id"]
}
}
]
}
}
]
}
4 changes: 4 additions & 0 deletions inst/extdata/v2/deployments.csv
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions inst/extdata/v2/observations_1.tsv
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions inst/extdata/v2/observations_2.tsv
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions man/add_resource.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d5e723e

Please sign in to comment.