This function allows you to quickly describe your computational environment to a model by concatenating plain-text descriptions of "R stuff", from data frames to packages to function documentation.
There are two key ways to use btw()
:
Use it interactively at the console to gather information about your environment into prompt text that you can paste into the chat interface of an LLM, like ChatGPT or Claude. By default,
btw()
copies the prompt to the clipboard for you.Pair
btw()
with ellmer::Chat during a chat session to create a prompt that includes additional context drawn from your environment and help pages.library(ellmer) chat <- chat_claude() # requires an Anthropic API key chat <- chat_ollama(model = "llama3.1:8b") # requires ollama and a local model chat$chat(btw( vignette("colwise", "dplyr"), dplyr::across, dplyr::starwars, "Create a few interesting examples that use `dplyr::across()`", "with the `starwars` data set." ))
Arguments
- ...
Objects to describe from your R environment. You can pass objects themselves, like data frames or functions, or the function also accepts output from
btw_tool_*()
functions likebtw_tool_get_package_help_topics()
,btw_tool_get_help_page()
, etc. If omitted, this function will just describe the elements in your global R environment.- clipboard
Whether to write the results to the clipboard. A single logical value; will default to
TRUE
when run interactively.
Value
Returns an ellmer::ContentText object with the collected prompt. If
clipboard = TRUE
, the prompt text is copied to the clipboard when the
returned object is printed for the first time (e.g. calling btw()
without
assignment).
Examples
btw()
btw(mtcars)
btw(btw::btw)
if (FALSE) {
# btw() can also be used directly in {ellmer} chats
library(ellmer)
chat <- chat_ollama(model = "llama3.1:8b")
chat$chat(
btw(mtcars, "Are there cars with 8 cylinders in this dataset?")
)
}