Learn R Programming

datapackage.r (version 1.3.5)

Resource.load: Instantiate Resource class

Description

Constructor to instantiate Resource class.

Usage

Resource.load(descriptor = list(), basePath = NA, strict = FALSE, dataPackage = list())

Arguments

descriptor

Data resource 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.

dataPackage

data package list

Value

Resource class object

See Also

Resource, Data Resource Specifications

Examples

Run this code
# NOT RUN {
# Resource Load - with base descriptor
descriptor <- '{"name":"name","data":["data"]}'
resource <- Resource.load(descriptor)
resource$name
resource$descriptor


# Resource Load - with tabular descriptor
descriptor2 <- '{"name":"name","data":["data"],"profile":"tabular-data-resource"}' 
resource2 <- Resource.load(descriptor2)
resource2$name
resource2$descriptor


# Retrieve Resource Descriptor
descriptor3 <- '{"name": "name","data": "data"}'
resource3 <- Resource.load(descriptor3)
resource3$descriptor


# Expand Resource Descriptor - General Resource
descriptor4 <- '{"name": "name","data": "data"}'
resource4 <- Resource.load(descriptor4)
resource4$descriptor

# Expand Resource Descriptor - Tabular Resource Dialect
descriptor5 <- helpers.from.json.to.list('{
                                        "name": "name",
                                        "data": "data",
                                        "profile": "tabular-data-resource",
                                        "dialect": {"delimiter": "custom"}
                                        }')
resource5 <- Resource.load(descriptor5)
resource5$descriptor


# Resource - Inline source/sourceType
descriptor6 <- '{"name": "name","data": "data","path": ["path"]}'
resource6 <- Resource.load(descriptor6)
resource6$source

# Resource - Remote source/sourceType
descriptor7 <- '{"name": "name","path": ["https://example.com//table.csv"]}'
resource7 <- Resource.load(descriptor7)
resource7$source 

# Resource - Multipart Remote source/sourceType
descriptor8 <- '{
              "name": "name",
              "path": ["https://example.com/chunk1.csv", "https://example.com/chunk2.csv"]
              }'
resource8 <- Resource.load(descriptor8)
resource8$source 


# Inline Table Resource
descriptor9 <- '{
               "name": "example",
               "profile": "tabular-data-resource",
               "data": [
                  ["height", "age", "name"],
                  ["180", "18", "Tony"],
                  ["192", "32", "Jacob"]
                 ],
               "schema": {
                 "fields": [{
                   "name": "height",
                   "type": "integer"
                   },
                 {
                   "name": "age",
                   "type": "integer"
                 },
                 {
                   "name": "name",
                   "type": "string"
                 }
                 ]
                }
               }'
resource9 <- Resource.load(descriptor9)
table <- resource9$table$read()
table

# }

Run the code above in your browser using DataLab