A class for working with data packages. It provides various capabilities like loading local or remote data package, inferring a data package descriptor, saving a data package descriptor and many more.
# Package.load(descriptor = list(),basePath = NA,strict = FALSE)
R6Class
object
Object of R6Class
Package$new(descriptor = list(),basePath = NA,strict = FALSE)
Use Package.load
to instantiate Package
class.
getResource(name)
Get data package resource by name or null if not found.
name
Data resource name.
addResource(descriptor)
Add new resource to data package. The data package descriptor will be validated with newly added resource descriptor.
descriptor
Data resource descriptor.
removeResource(name)
Remove data package resource by name. The data package descriptor will be validated after resource descriptor removal.
name
Data resource name.
infer(pattern=FALSE)
Infer a data package metadata. If pattern
is not provided only existent
resources will be inferred (added metadata like encoding, profile etc).
If pattern
is provided new resoures with file names mathing the pattern
will be added and inferred. It commits changes to data package instance.
pattern
Glob pattern for new resources.
commit(strict)
Update data package instance if there are in-place changes in the descriptor. Returns TRUE
on success and FALSE
if not modified.
strict
Boolean - Alter strict mode for further work.
save(target)
For now only descriptor will be saved. Save descriptor to target destination.
target
String path where to save a data package.
valid
Returns validation status. It always TRUE
in strict mode.
errors
Returns validation errors. It always empty in strict mode.
profile
Returns an instance of Profile
class.
descriptor
Returns list of package descriptor.
resources
Returns list of Resource instances.
resourceNames
Returns list of resource names.
A Data Package consists of:
Metadata that describes the structure and contents of the package.
Resources such as data files that form the contents of the package.
The Data Package metadata is stored in a "descriptor". This descriptor is what makes a collection of data a Data Package. The structure of this descriptor is the main content of the specification below.
In addition to this descriptor a data package will include other resources such as data files. The Data Package specification does NOT impose any requirements on their form or structure and can therefore be used for packaging any kind of data.
The data included in the package may be provided as:
Files bundled locally with the package descriptor.
Remote resources, referenced by URL.
"Inline" data which is included directly in the descriptor.
Jsolite package is internally used to convert json data to list objects. The input parameters of functions could be json strings,
files or lists and the outputs are in list format to easily further process your data in R environment and exported as desired.
It is recommended to use helpers.from.json.to.list
or helpers.from.list.to.json
to convert json objects to lists and vice versa.
More details about handling json you can see jsonlite documentation or vignettes here.
The key words MUST
, MUST NOT
, REQUIRED
, SHALL
, SHALL NOT
,
SHOULD
, SHOULD NOT
, RECOMMENDED
, MAY
, and OPTIONAL
in this package documents are to be interpreted as described in RFC 2119.
new()
Package$new( descriptor = list(), basePath = NULL, strict = FALSE, profile = NULL )
addResource()
Package$addResource(descriptor)
getResource()
Package$getResource(name)
removeResource()
Package$removeResource(name)
infer()
Package$infer(pattern)
commit()
Package$commit(strict = NULL)
save()
Package$save(target, type = "json")
clone()
The objects of this class are cloneable with this method.
Package$clone(deep = FALSE)
deep
Whether to make a deep clone.