Skip to contents

Fetches /<db>/<table>.json (or /<db>.json?sql=...) from a Datasette instance and returns the rows as a base R data.frame. Datasette's SQL surface is read-only by design, so this cannot mutate the remote database.

Usage

morie_datasette_read(
  db,
  table = NULL,
  sql = NULL,
  limit = 1000L,
  base_url = NULL,
  timeout = 60
)

Arguments

db

Database name as served by the instance.

table

Table name; ignored when sql is given.

sql

Optional read-only SQL string executed against db.

limit

Row cap forwarded as Datasette's _size (table mode) or appended as LIMIT advice in SQL mode (default 1000).

base_url

Instance root URL; defaults to the MORIE_DATASETTE_URL environment variable.

timeout

HTTP timeout in seconds.

Value

A base R data.frame.

Examples

if (FALSE) { # nzchar(Sys.getenv("MORIE_DATASETTE_URL"))
dbs <- morie_datasette_databases()
# Peek at the first table of the first database:
tabs <- morie_datasette_read(dbs$name[1],
  sql = "SELECT name FROM sqlite_master WHERE type='table' LIMIT 5")
tabs
}