vplot_ask() is a thin, model-agnostic convenience: it assembles the
grounding payload (the JSON spec_schema() plus spec_fields() for data
and the user's prompt), hands it to a responder function you supply — any
function that takes the payload and returns a JSON spec string (wrapping the
Claude API, an MCP client, a local model, or a canned fixture) — and validates
the result with vplot_from_spec().
Usage
vplot_ask(prompt, data, responder, env = globalenv())Arguments
- prompt
A natural-language description of the desired plot.
- data
The data frame to plot.
- responder
A function
function(payload) -> json_string.payloadis a list withprompt,fields(fromspec_fields()), andschema.- env
Environment channel expressions are re-quoted in.
Value
A PlotSpec.
Details
vellumplot deliberately ships no built-in model client: the value is the
schema, the grounding, and the validated repair loop, not a hard dependency on
one provider. For a ready-to-run agent integration, point an MCP client at the
bundled server (system.file("mcp/server.R", package = "vellumplot")).
Examples
# a canned responder standing in for a model call:
responder <- function(payload) {
spec_to_json(vplot(mtcars) |> mark_point(x = wt, y = mpg))
}
p <- vplot_ask("scatter of weight vs mpg", mtcars, responder)
