Skip to contents

These functions describe package documentation in plain text:

Usage

btw_tool_get_package_help_topics(package_name)

btw_tool_get_help_page(package_name, topic)

btw_tool_get_available_vignettes_in_package(package_name)

btw_tool_get_vignette_from_package(package_name, vignette = package_name)

Arguments

package_name

The name of the package as a string, e.g. "shiny".

topic

The topic_id or alias of the help page, e.g. "withProgress" or "incProgress". Find topic_ids or aliases using get_package_help().

vignette

The name (or index) of the vignette to retrieve. Defaults to the "intro" vignette to the package (by the same rules as pkgdown.)

Value

  • btw_tool_get_package_help_topics() returns the topic_id, title, and aliases fields for every topic in a package's documentation as a json-formatted string.

  • btw_tool_get_help_page() return the help-page for a package topic as a string.

Examples

cat(btw_tool_get_package_help_topics("btw"))
#> ```json [
#>   {"topic_id":"btw","title":"Plain-text descriptions of R objects","aliases":["btw"]},
#>   {"topic_id":"btw-package","title":"btw: Describe R Stuff to Large Language Models","aliases":["btw-package"]},
#>   {"topic_id":"btw_register_tools","title":"Tools: Register tools from btw","aliases":["btw_register_tools"]},
#>   {"topic_id":"btw_this","title":"Describe something for use by an LLM","aliases":["btw_this"]},
#>   {"topic_id":"btw_this.character","title":"Describe objects","aliases":["btw_this.character"]},
#>   {"topic_id":"btw_this.data.frame","title":"Describe a data frame in plain text","aliases":["btw_this.data.frame","btw_this.tbl"]},
#>   {"topic_id":"btw_this.environment","title":"Describe the contents of an environment","aliases":["btw_this.environment"]},
#>   {"topic_id":"btw_tool_describe_data_frame","title":"Tool: Describe data frame","aliases":["btw_tool_describe_data_frame"]},
#>   {"topic_id":"btw_tool_describe_environment","title":"Tool: Describe an environment","aliases":["btw_tool_describe_environment"]},
#>   {"topic_id":"btw_tool_get_installed_packages","title":"Tool: Describe installed packages","aliases":["btw_tool_get_installed_packages"]},
#>   {"topic_id":"btw_tool_list_files","title":"Tool: List files","aliases":["btw_tool_list_files"]},
#>   {"topic_id":"btw_tool_package_docs","title":"Tool: Describe R package documentation","aliases":["btw_tool_package_docs","btw_tool_get_package_help_topics","btw_tool_get_help_page","btw_tool_get_available_vignettes_in_package","btw_tool_get_vignette_from_package"]},
#>   {"topic_id":"btw_tool_read_current_editor","title":"Tool: Read current file","aliases":["btw_tool_read_current_editor"]},
#>   {"topic_id":"btw_tool_read_text_file","title":"Tool: Read a file","aliases":["btw_tool_read_text_file"]}
#> ] ```

cat(btw_tool_get_help_page("btw", "btw"))
#> btw                    package:btw                     R Documentation  Plain-text descriptions of R objects  Description:       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()’:         1. 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!                   2. 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."           ))            Usage:       btw(..., clipboard = TRUE)       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 like           ‘btw_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?")        )      }      

# show the TOC of vignettes in the dplyr package
cat(btw_tool_get_available_vignettes_in_package("dplyr"))
#> [   {"vignette":"colwise","title":"Column-wise operations"},   {"vignette":"grouping","title":"Grouped data"},   {"vignette":"dplyr","title":"Introduction to dplyr"},   {"vignette":"programming","title":"Programming with dplyr"},   {"vignette":"rowwise","title":"Row-wise operations"},   {"vignette":"two-table","title":"Two-table verbs"},   {"vignette":"in-packages","title":"Using dplyr in packages"},   {"vignette":"window-functions","title":"Window functions"},   {"vignette":"base","title":"dplyr <-> base R"} ]

# returns a whole bunch of output and relies on
# dplyr to have the mentioned vignettes available
if (FALSE) { # \dontrun{
# grab the intro vignette
cat(btw_tool_get_vignette_from_package("dplyr"))

# grab the programming vignette specifically
cat(btw_tool_get_vignette_from_package("dplyr", "programming"))
} # }