Package.load: Instantiate 'Data Package' class

Description Usage Arguments See Also Examples

View source: R/Package.R

Description

Constructor to instantiate Package class.

Usage

1
Package.load(descriptor = list(), basePath = NA, strict = FALSE)

Arguments

descriptor

Data package descriptor as local path, url or object.

basePath

Base path for all relative paths

strict

Strict flag to alter validation behavior. Setting it to TRUE leads to throwing errors on any operation with invalid descriptor.

See Also

Package, Data Package Specifications

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Load local descriptor
descriptor <- system.file('extdata/dp1/datapackage.json', 
                         package = "datapackage.r")
dataPackage <- Package.load(descriptor)
dataPackage$descriptor


# Retrieve Package Descriptor
descriptor2 <- '{"resources": [{"name": "name", "data": ["data"]}]}'
dataPackage2 <- Package.load(descriptor2)
dataPackage2$descriptor

# Expand Resource Descriptor
descriptor3 <- helpers.from.json.to.list('{"resources": 
                                         [{
                                          "name": "name",
                                          "data": ["data"]
                                          }]
                                        }')

dataPackage3 <- Package.load(descriptor3)
dataPackage3$descriptor


# Expand Tabular Resource Schema
descriptor4 <- helpers.from.json.to.list('{
                                      "resources": [{
                                        "name": "name",
                                        "data": ["data"],
                                        "profile": "tabular-data-resource",
                                        "schema": {
                                          "fields": [{
                                            "name": "name"
                                          }]
                                        }
                                      }]
                                      }')

dataPackage4 <- Package.load(descriptor4)
dataPackage4$descriptor


# Expand Tabular Resource Dialect
descriptor5 <- helpers.from.json.to.list('{
                                         "resources": [{
                                           "name": "name",
                                           "data": ["data"],
                                           "profile": "tabular-data-resource",
                                           "dialect": {
                                             "delimiter": "custom"
                                             }
                                           }]
                                         }')

dataPackage5 <- Package.load(descriptor5)
dataPackage5$descriptor


# Add, Get and Remove Package Resources
descriptor6 <- helpers.from.json.to.list(
       system.file('extdata/dp1/datapackage.json', 
                     package = "datapackage.r"))
dataPackage6 <- Package.load(descriptor6)
resource6 <- dataPackage6$addResource(
        helpers.from.json.to.list('{"name": "name", "data": ["test"]}'))
dataPackage6$resources[[2]]$source
# Get resource
dataPackage6$getResource('name')
# Remove resource
dataPackage6$removeResource('name')
dataPackage6$getResource('name')



# Modify and Commit Data Package
descriptor7 <- helpers.from.json.to.list(
        '{"resources": [{"name": "name", "data": ["data"]}]}')
dataPackage7 <- Package.load(descriptor7)
dataPackage7$descriptor$resources[[1]]$name <- 'modified'
## Name did not modified.
dataPackage7$resources[[1]]$name
## Should commit the changes
dataPackage7$commit() # TRUE - successful commit 

dataPackage7$resources[[1]]$name

datapackage.r documentation built on Dec. 1, 2019, 1:22 a.m.