Constructor to instantiate Resource class.

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

Examples

# Resource Load - with base descriptor descriptor <- '{"name":"name","data":["data"]}' resource <- Resource.load(descriptor) resource$name
#> [1] "name"
resource$descriptor
#> $name #> [1] "name" #> #> $data #> $data[[1]] #> [1] "data" #> #> #> $profile #> [1] "data-resource" #> #> $encoding #> [1] "utf-8" #>
# Resource Load - with tabular descriptor descriptor2 <- '{"name":"name","data":["data"],"profile":"tabular-data-resource"}' resource2 <- Resource.load(descriptor2) resource2$name
#> [1] "name"
resource2$descriptor
#> $name #> [1] "name" #> #> $data #> $data[[1]] #> [1] "data" #> #> #> $profile #> [1] "tabular-data-resource" #> #> $encoding #> [1] "utf-8" #>
# Retrieve Resource Descriptor descriptor3 <- '{"name": "name","data": "data"}' resource3 <- Resource.load(descriptor3) resource3$descriptor
#> $name #> [1] "name" #> #> $data #> [1] "data" #> #> $profile #> [1] "data-resource" #> #> $encoding #> [1] "utf-8" #>
# Expand Resource Descriptor - General Resource descriptor4 <- '{"name": "name","data": "data"}' resource4 <- Resource.load(descriptor4) resource4$descriptor
#> $name #> [1] "name" #> #> $data #> [1] "data" #> #> $profile #> [1] "data-resource" #> #> $encoding #> [1] "utf-8" #>
# 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
#> $name #> [1] "name" #> #> $data #> [1] "data" #> #> $profile #> [1] "tabular-data-resource" #> #> $dialect #> $dialect$delimiter #> [1] "custom" #> #> $dialect$doubleQuote #> [1] TRUE #> #> $dialect$lineTerminator #> [1] "\r\n" #> #> $dialect$quoteChar #> [1] "\"" #> #> $dialect$skipInitialSpace #> [1] TRUE #> #> $dialect$header #> [1] TRUE #> #> $dialect$caseSensitiveHeader #> [1] FALSE #> #> #> $encoding #> [1] "utf-8" #>
# Resource - Inline source/sourceType descriptor6 <- '{"name": "name","data": "data","path": ["path"]}' resource6 <- Resource.load(descriptor6) resource6$source
#> [1] "data"
# Resource - Remote source/sourceType descriptor7 <- '{"name": "name","path": ["http://example.com//table.csv"]}' resource7 <- Resource.load(descriptor7) resource7$source
#> [1] "http://example.com//table.csv"
# Resource - Multipart Remote source/sourceType descriptor8 <- '{ "name": "name", "path": ["http://example.com/chunk1.csv", "http://example.com/chunk2.csv"] }' resource8 <- Resource.load(descriptor8) resource8$source
#> [1] "http://example.com/chunk1.csv" "http://example.com/chunk2.csv"
# 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
#> [[1]] #> [[1]][[1]] #> [1] 180 #> #> [[1]][[2]] #> [1] 18 #> #> [[1]][[3]] #> [1] "Tony" #> #> #> [[2]] #> [[2]][[1]] #> [1] 192 #> #> [[2]][[2]] #> [1] 32 #> #> [[2]][[3]] #> [1] "Jacob" #> #>