dpaddreader: Add a reader function for a specific format

View source: R/dpaddreader.R

dpaddreaderR Documentation

Add a reader function for a specific format

Description

Add a reader function for a specific format

Usage

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

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, dpgetdata 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, dpgetdata will try the same with the extension of the file.

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

Value

Does not return anything (invisible(NULL)).

Examples

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

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


djvanderlaan/datapackage documentation built on March 18, 2024, 4:57 p.m.