Learn R Programming

datapackage.r (version 1.3.5)

Package.load: Instantiate Data Package class

Description

Constructor to instantiate Package class.

Usage

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

Run this code
# NOT RUN {
# 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

# }

Run the code above in your browser using DataLab