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.
Getting started with pal takes three steps.
1) Install the pal package like so:
pak::pak("simonpcouch/pal")
2) Then, you need to configure pal with an
ellmer model. pal uses ellmer under the
hood, so any model that you can chat with through ellmer is also
supported by pal. To configure pal with ellmer, set the option
.pal_chat
to any ellmer Chat. For example, to use Claude, you’d write
options(.pal_chat = ellmer::chat_claude()
, possibly in your
.Rprofile
so that pal is ready to go every time you start R. To learn
more, see the Getting started with
pal vignette.
3) 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.
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.
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).