Skip to contents

Upgrades a Data Package, its Data Resources and Table Schemas to the v2 specification.

Usage

upgrade_package(package)

Arguments

package

Data Package object, as returned by read_package() or create_package().

Value

Upgraded package.

Upgrade details

Data Package

upgrade_package() upgrades a v1 descriptor to v2 as follows:

  • Adds $schema as first property and sets it to the recommended v2 value ("https://datapackage.org/profiles/2.0/datapackage.json"), except for certain profile values.

  • Removes profile, but retains its value in $schema if it is a URL to a custom profile (see backwards compatibility).

  • Converts contributors "role": "value" to "roles": ["value"] (see changelog).

Data Resource

upgrade_package() upgrades any v1 resource to v2 as follows:

  • Adds $schema as first property and sets it to the recommended v2 value ("https://datapackage.org/profiles/2.0/dataresource.json").

  • Removes profile, but converts "profile" = "tabular-data-resource" to "type" = "table" (see backwards compatibility).

Table Dialect

upgrade_package() leaves the dialect as is for all resources.

Table Schema

upgrade_package() upgrades any verbose v1 schema to v2 as follows:

  • Adds $schema as first property and sets it to the recommended v2 value ("https://datapackage.org/profiles/2.0/tableschema.json").

  • Converts primaryKey single values to an array (see changelog).

  • Converts foreignKeys single values in fields to an array and removes reference$resource if it is self-referential (see changelog).

Schemas referenced by path or URL are left as is.

See also

Other versioning functions: version()

Examples

# Load the v1 example Data Package
(package <- example_package(version = "1.0"))
#> A Data Package (version 1.0) with 3 resources:
#> • deployments
#> • observations
#> • media
#> Use `unclass()` to print the Data Package as a list.

# Upgrade
(package_upgraded <- upgrade_package(package))
#> A Data Package (version 2.0) with 3 resources:
#> • deployments
#> • observations
#> • media
#> Use `unclass()` to print the Data Package as a list.

# Check version of one of the resources
version(resource(package_upgraded, "deployments"))
#> [1] "2.0"