The pal package provides a library of ergonomic LLM assistants designed to help you complete repetitive, hard-to-automate tasks quickly. After selecting some code, press the keyboard shortcut you’ve chosen to trigger the pal addin (we suggest Ctrl+Cmd+P
), select the pal, and watch your code be rewritten.
Installation
You can install pal like so:
pak::pak("simonpcouch/pal")
Then, ensure that you have an ANTHROPIC_API_KEY
environment variable set, and you’re ready to go. If you’d like to use an LLM other than Anthropic’s Claude 3.5 Sonnet—like OpenAI’s ChatGPT or a local ollama model—to power the pal, see the Getting started with pal vignette.
Pals are interfaced with the via the pal addin. For easiest access, we recommend registering the pal addin to a keyboard shortcut.
In RStudio, navigate to Tools > Modify Keyboard Shortcuts > Search "Pal"
—we suggest Ctrl+Alt+P
(or Ctrl+Cmd+P
on macOS).
In Positron, you’ll need to open the command palette, run “Open Keyboard Shortcuts (JSON)”, and paste the following into your keybindings.json
:
{
"key": "Ctrl+Cmd+P",
"command": "workbench.action.executeCode.console",
"when": "editorTextFocus",
"args": {
"langId": "r",
"code": "pal::.init_addin()",
"focus": true
}
}
The analogous keybinding on non-macOS is Ctrl+Alt+P
. That said, change the "key"
entry to any keybinding you wish!
Once those steps are completed, you’re ready to use pals with a keyboard shortcut.
Example
Pals are created automatically when users interact with the pal addin. Just highlight some code, open the addin, begin typing the “role” of your pal and press “Return”, and watch your code be rewritten:
As-is, the package provides ergonomic LLM assistants for R package development:
-
"cli"
: Convert to cli -
"testthat"
: Convert to testthat 3 -
"roxygen"
: Document functions with roxygen
Users have also contributed a number of pals for a wide range of tasks–see vignette("gallery", package = "pal")
for a gallery of user-contributed pals!
That said, all you need to create your own pal is a markdown file with some instructions on how you’d like it to work. See prompt_new()
and directory_load()
for more information, and palpable for an example pal extension package.
How much do pals cost?
The cost of using pals depends on 1) the length of the underlying prompt for a given pal and 2) the cost per token of the chosen model. Using the cli pal with Anthropic’s Claude Sonnet 3.5, for example, costs something like $15 per 1,000 code refactorings, while using the testthat pal with OpenAI’s GPT 4o-mini would cost something like $1 per 1,000 refactorings. Pals using a locally-served LLM are “free” (in the usual sense of code execution, ignoring the cost of increased battery usage).