Fetch a dataset from any URL, with automatic format detection
Source:R/data_access.R
morie_fetch.RdA 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
urlas a URL-encoded query string.- zip_member
For
zipdownloads, 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 (defaultTRUE).- ...
Passed to the underlying reader (e.g.
read.csvarguments, ormorie_fetch_arcgisarguments).
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)
)
} # }