Skip to content
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

Create a v2 example_package() #258

Merged
merged 34 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c4ec0dc
folder move
sannegovaert Aug 27, 2024
36900c3
update path
sannegovaert Aug 27, 2024
c6a2d36
document()
sannegovaert Aug 27, 2024
ab26085
precompile vignette
sannegovaert Aug 27, 2024
f86a6fb
update path
sannegovaert Aug 27, 2024
4a48d26
Merge branch 'main' into v2-example_package
sannegovaert Aug 27, 2024
85e97f4
add param version
sannegovaert Aug 27, 2024
f8b3168
update path
sannegovaert Aug 27, 2024
8865e29
Create test-example_package.R
sannegovaert Aug 27, 2024
d8eef96
add error class
sannegovaert Aug 27, 2024
bbce506
copy v1 example data packaga
sannegovaert Aug 27, 2024
678ed47
add https://datapackage.org/overview/changelog/#packageschema-new
sannegovaert Aug 27, 2024
f829191
reorder to match https://datapackage.org/standard/data-package/
sannegovaert Aug 27, 2024
5344d0f
https://datapackage.org/overview/changelog/#resourcetype-new
sannegovaert Aug 27, 2024
0c0fdf5
add version (https://datapackage.org/overview/changelog/#packageversi…
sannegovaert Aug 27, 2024
55b32cb
Version should be a string value "1.0"
sannegovaert Aug 27, 2024
423a367
add resources.$schema
sannegovaert Aug 27, 2024
7575c54
fix error
sannegovaert Aug 27, 2024
0f193e4
primaryKey and foreignKeys should be an array of strings
sannegovaert Aug 28, 2024
a62d028
add version 2.0
sannegovaert Aug 28, 2024
5dd7ac6
add tests on versions
sannegovaert Aug 28, 2024
c40ddb3
document()
sannegovaert Aug 28, 2024
e6f1ff0
Add version to v1 and order image and created the same
peterdesmet Aug 29, 2024
fce05a0
Add $schema to schema and dialect
peterdesmet Aug 29, 2024
2b1e012
Change missing values to one with labels
peterdesmet Aug 29, 2024
2401644
Update created date
peterdesmet Aug 29, 2024
2993338
Change enum to categories
peterdesmet Aug 29, 2024
b06ff8c
Update doc and example
peterdesmet Aug 29, 2024
7e44709
Update doc and example
peterdesmet Aug 29, 2024
8c7a66a
Rather than returning error, default to 1.0
peterdesmet Aug 29, 2024
d25aaf9
Merge branch 'v2-example_package' of https://github.com/frictionlessd…
peterdesmet Aug 29, 2024
24bb578
Update example_package.R
peterdesmet Aug 29, 2024
ae72c51
Fix test
peterdesmet Aug 29, 2024
07f2002
Update NEWS.md
peterdesmet Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/add_resource.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,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,18 @@
{
"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
Loading