Skip to contents

A universal data-access entry point. Given a URL, MORIE detects the format from the HTTP Content-Type header (falling back to the URL extension), downloads the resource, and parses it into an R object. The behaviour is automatic by default but every step is controllable: pass an explicit format, extra query params, a zip_member to extract, or reader arguments via ....

Usage

morie_fetch(
  url,
  format = c("auto", "csv", "tsv", "json", "xml", "html", "xlsx", "zip", "arcgis"),
  params = NULL,
  zip_member = "",
  simplify = TRUE,
  ...
)

Arguments

url

The resource URL.

format

One of "auto" (default), "csv", "tsv", "json", "xml", "html", "xlsx", "zip", "arcgis".

params

Optional named list appended to url as a URL-encoded query string.

zip_member

For zip downloads, the archive member to extract (matched by basename, then by substring).

simplify

For json/xml/html, whether to simplify into a data.frame where possible (default TRUE).

...

Passed to the underlying reader (e.g. read.csv arguments, or morie_fetch_arcgis arguments).

Value

A data.frame for tabular formats; a list or document object for non-tabular json/xml/html.

Details

Supported formats: csv, tsv, json, xml, html, xlsx, zip (extract one member), and arcgis (delegates to morie_fetch_arcgis).

Examples

if (FALSE) { # \dontrun{
# Examples use placeholder URLs (example.org). Replace with a
# real CSV / JSON endpoint when running.
df <- morie_fetch("https://example.org/data.csv")
js <- morie_fetch("https://api.example.org/records",
  format = "json", params = list(limit = 100)
)
} # }