| btw | R Documentation |
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.
btw(vignette("colwise", "dplyr"), dplyr::across, dplyr::starwars)
#> btw copied to the clipboard!
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_anthropic() # 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."
))
Use btw() without arguments to describe all objects in your workspace:
btw() #> btw copied to the clipboard!
Describe a function (it's documentation) and a data frame:
btw(dplyr::mutate, mtcars) #> btw copied to the clipboard!
Use btw() to give additional context to an ellmer::Chat session:
library(ellmer) chat <- chat_ollama(model = "llama3.1:8b") chat$chat( btw(mtcars, "Are there cars with 8 cylinders in this dataset?") )
btw(..., clipboard = TRUE)
... |
Objects to describe from your R environment. You can pass objects
themselves, like data frames or functions, or the function also accepts
output from |
clipboard |
Whether to write the results to the clipboard.
A single logical value; will default to |
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).
# See documentation for detailed examples
btw(mtcars)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.