Learn R Programming

datapackage (version 0.2.1)

dp_add_reader: Add a reader function for a specific format

Description

Add a reader function for a specific format

Usage

dp_add_reader(
  format,
  reader,
  mediatypes = character(0),
  extensions = character(0)
)

Value

Does not return anything (invisible(NULL)).

Arguments

format

the data format read by the reader. Should be a length 1 character vector.

reader

the reader function. See details.

mediatypes

a character vector with the media-types that are used for the format.

extensions

a character vector with typical file extensions used by the format.

Details

Adds a reader for a given format. The reader is added to a list of reades references by the format. It is also possible to assign mediatypes and file extensions to the format. When the format for a given Data Resource is missing, dp_get_data will first check if a mediatype is associated with the resource and will try to look up which format belongs to the fiven mediatype. If that doesn't result in a valid format, dp_get_data will try the same with the extension of the file.

Note that adding a reader for an existing format will overwrite the existing reader.

Examples

Run this code
# Add a very simple reader for json
json_reader <- function(path, resource, ...) {
  lapply(path, function(fn) {
    jsonlite::read_json(fn)
  })
}

dp_add_reader("json", json_reader, c("application/json"), "json")

Run the code above in your browser using DataLab