| hal | R Documentation |
The main entry point for conversational interaction with Copilot models. Maintains a persistent session across calls. The SDK agent has built-in tools for file operations, code search, and shell commands.
hal(..., model = NULL, use_env = NULL, reset = FALSE, inspect = FALSE)
... |
Character strings, concatenated as the user message. |
model |
Model identifier. If NULL, uses the session/configured default. |
use_env |
Logical or NULL; if TRUE, snapshots the caller's environment
and injects it into the prompt so the model naturally uses eval_r to work
with your R objects. If NULL (default), auto-detects: scans the prompt
for R identifiers and injects the snapshot only when the prompt mentions
an object that exists in the caller's environment. When auto-detect
fires, a |
reset |
Logical; if TRUE, starts a fresh session before prompting. |
inspect |
Logical; if TRUE, returns session info instead of prompting. |
The assistant's text response (invisibly when displayed).
In an interactive session a transport failure prints an alert and
returns invisible(NULL). In non-interactive contexts (scripts, R
Markdown) it aborts with a classed condition instead, so programmatic
callers can handle hal failures specifically:
tryCatch(hal("..."), hal_transport_error = function(e) ...). All hal
conditions inherit from hal_error / hal_warning; hal_do() signals
hal_do_error / hal_do_warning, and hal_ask() signals
hal_ask_warning.
## Not run:
# Simple conversation
hal("What is R?")
hal("Can you explain more about data frames?")
# Environment access (auto-detected when objects exist)
df <- mtcars
hal("What's the mean mpg?") # auto-detects df, injects env snapshot
# Reset and start fresh
hal("Hello", reset = TRUE)
# Inspect session
hal(inspect = TRUE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.