frictionless-r
frictionless-r copied to clipboard
Detect Data Package version with `version()` function
trafficstars
To support Data Package v2 we need to be able to detect the version used by a package.
- [ ]
$schemais undefinedversion=1.0- We theoretically should look at the
profileproperty in this case (see backward compatibility note) but frictionless-r ignores this property since it doesn't use it (it is useful for validation etc.).
- [ ]
$schema=https://datapackage.org/profiles/1.0/datapackage.jsonversion=1.0profileis ignored (since new property$schemais used)
- [ ]
$schema=https://datapackage.org/profiles/2.0/datapackage.jsonversion=2.0profileis ignored (deprecated in 2.0)
- [ ]
$schema=https://datapackage.org/profiles/2.1-rc.1/datapackage.jsonversion=2.1-rc.1(theoretical example)profileis ignored
- [ ]
$schema=https://fiscal.datapackage.org/profiles/fiscal-data-package.json,https://raw.githubusercontent.com/tdwg/camtrap-dp/1.0.1/camtrap-dp-profile.jsonor any other valueversion=>=2.0: we can't detect the version, but it is higher or equal to2.0since$schemais used.profileis ignored
Even if we would read profile, the end result would still be version = 1.0
- [x]
profileis undefinedprofileis assumed to bedata-package(see https://specs.frictionlessdata.io/profiles/#introduction)version= 1.0 (implied byprofileuse)
- [x]
profile=data-packageversion= 1.0 (implied byprofileuse)
- [x]
profile=tabular-data-package,fiscal-data-package,https://raw.githubusercontent.com/tdwg/camtrap-dp/1.0.1/camtrap-dp-profile.jsonor any other valueversion= 1.0 (implied byprofileuse)
In my opinion, the best way to implement this is with a version(package) function. This allows us in the future to create a version()<- function. Alternative names:
get_version(): this limits us in the future from having aversion(). I'm tempted to rename all functions that start withget_package_version(): the version logic is the same for package, resource, dialect, schema: it's just the name of the file in the URL that is different (datapackage.json,dataresource.json). I therefore think we can make one function for all of these, rather than four functions.
I think we can generalize to a version(list) function:
- [ ] Use the logic above for any incoming list (JSON). Search for
$schemaand get the version from the URL if it starts withhttps://datapackage.org, otherwise use1.0(if undefined$schema) or>2.0. - [ ] Setting the version is a bit harder, since - especially for a value like
https://raw.githubusercontent.com/tdwg/camtrap-dp/1.0.1/camtrap-dp-profile.jsonif it's a package, resource, etc. I think this can be solved with an extra argument in the set function:version(level = "schema") <- 2.0would assignhttps://datapackage.org/profiles/2.0/tableschema.json