From e02c8fb98235f10508f6ac03b2b8913ab5144b93 Mon Sep 17 00:00:00 2001 From: simonpcouch Date: Mon, 28 Oct 2024 21:21:38 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20simonpco?= =?UTF-8?q?uch/pal@7da14af8c931abd587a9fb6a3a68742b62914e32=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgdown.yml | 2 +- reference/index.html | 6 +++ reference/pal_options.html | 77 ++++++++++++++++++++++++++++++++++++++ search.json | 2 +- sitemap.xml | 1 + 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 reference/pal_options.html diff --git a/pkgdown.yml b/pkgdown.yml index 9f4a829..7bd8e81 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.1.1 pkgdown_sha: ~ articles: pal: pal.html -last_built: 2024-10-28T21:14Z +last_built: 2024-10-28T21:21Z urls: reference: https://simonpcouch.github.io/pal/reference article: https://simonpcouch.github.io/pal/articles diff --git a/reference/index.html b/reference/index.html index 193fd1a..b579c98 100644 --- a/reference/index.html +++ b/reference/index.html @@ -59,6 +59,12 @@

Creating custom palspal_options + + +
Options used by the pal package

Pals for package development

diff --git a/reference/pal_options.html b/reference/pal_options.html new file mode 100644 index 0000000..9cc7299 --- /dev/null +++ b/reference/pal_options.html @@ -0,0 +1,77 @@ + +Options used by the pal package — pal_options • pal + Skip to contents + + +
+
+
+ +
+

The pal package makes use of three notable user-facing options:

  • .pal_dir is the directory where pal prompts live. See the pal directory +help-page for more information.

  • +
  • .pal_fn and .pal_args determine the underlying LLM powering each pal. +See the "Choosing a model" section of vignette("pal", package = "pal") +for more information.

  • +
+ + + +
+ + +
+ + + +
+ + + + + + + diff --git a/search.json b/search.json index 2f6cb88..6e4fa33 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":[]},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement codeofconduct@posit.co. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":null,"dir":"","previous_headings":"","what":"Contributing to pal","title":"Contributing to pal","text":"outlines propose change pal. detailed discussion contributing tidyverse packages, please see development contributing guide code review principles.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":"fixing-typos","dir":"","previous_headings":"","what":"Fixing typos","title":"Contributing to pal","text":"can fix typos, spelling mistakes, grammatical errors documentation directly using GitHub web interface, long changes made source file. generally means ’ll need edit roxygen2 comments .R, .Rd file. can find .R file generates .Rd reading comment first line.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":"bigger-changes","dir":"","previous_headings":"","what":"Bigger changes","title":"Contributing to pal","text":"want make bigger change, ’s good idea first file issue make sure someone team agrees ’s needed. ’ve found bug, please file issue illustrates bug minimal reprex (also help write unit test, needed). See guide create great issue advice.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":"pull-request-process","dir":"","previous_headings":"Bigger changes","what":"Pull request process","title":"Contributing to pal","text":"Fork package clone onto computer. haven’t done , recommend using usethis::create_from_github(\"simonpcouch/pal\", fork = TRUE). Install development dependencies devtools::install_dev_deps(), make sure package passes R CMD check running devtools::check(). R CMD check doesn’t pass cleanly, ’s good idea ask help continuing. Create Git branch pull request (PR). recommend using usethis::pr_init(\"brief-description--change\"). Make changes, commit git, create PR running usethis::pr_push(), following prompts browser. title PR briefly describe change. body PR contain Fixes #issue-number. user-facing changes, add bullet top NEWS.md (.e. just first header). Follow style described https://style.tidyverse.org/news.html.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":"code-style","dir":"","previous_headings":"Bigger changes","what":"Code style","title":"Contributing to pal","text":"New code follow tidyverse style guide. can use styler package apply styles, please don’t restyle code nothing PR. use roxygen2, Markdown syntax, documentation. use testthat unit tests. Contributions test cases included easier accept.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"Contributing to pal","text":"Please note pal project released Contributor Code Conduct. contributing project agree abide terms.","code":""},{"path":"https://simonpcouch.github.io/pal/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2024 pal authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://simonpcouch.github.io/pal/SUPPORT.html","id":null,"dir":"","previous_headings":"","what":"Getting help with pal","title":"Getting help with pal","text":"Thanks using pal! filing issue, places explore pieces put together make process smooth possible.","code":""},{"path":"https://simonpcouch.github.io/pal/SUPPORT.html","id":"make-a-reprex","dir":"","previous_headings":"","what":"Make a reprex","title":"Getting help with pal","text":"Start making minimal reproducible example using reprex package. haven’t heard used reprex , ’re treat! Seriously, reprex make R-question-asking endeavors easier (pretty incredible ROI five ten minutes ’ll take learn ’s ). additional reprex pointers, check Get help! section tidyverse site.","code":""},{"path":"https://simonpcouch.github.io/pal/SUPPORT.html","id":"where-to-ask","dir":"","previous_headings":"","what":"Where to ask?","title":"Getting help with pal","text":"Armed reprex, next step figure ask. ’s question: start community.rstudio.com, /StackOverflow. people answer questions. ’s bug: ’re right place, file issue. ’re sure: let community help figure ! problem bug feature request, can easily return report . opening new issue, sure search issues pull requests make sure bug hasn’t reported /already fixed development version. default, search pre-populated :issue :open. can edit qualifiers (e.g. :pr, :closed) needed. example, ’d simply remove :open search issues repo, open closed.","code":""},{"path":"https://simonpcouch.github.io/pal/SUPPORT.html","id":"what-happens-next","dir":"","previous_headings":"","what":"What happens next?","title":"Getting help with pal","text":"efficient possible, development tidyverse packages tends bursty, shouldn’t worry don’t get immediate response. Typically don’t look repo sufficient quantity issues accumulates, ’s burst intense activity focus efforts. makes development efficient avoids expensive context switching problems, cost taking longer get back . process makes good reprex particularly important might multiple months initial report start working . can’t reproduce bug, can’t fix !","code":""},{"path":"https://simonpcouch.github.io/pal/articles/pal.html","id":"choosing-a-model","dir":"Articles","previous_headings":"","what":"Choosing a model","title":"Getting started with pal","text":"hood, pals driven Large Language Models (LLMs). use pals, need API key commercial model connection locally hosted model. Pals use elmer package interface LLMs. model supported elmer supported pal. October 2024, highly recommend Anthropic’s Claude Sonnet 3.5 model power pals. Compared models ’ve tried, Claude likely generate syntactically valid code aligns pal’s prompt well. , Claude default model used pal. want use Claude pal, additional setup step need set ANTHROPIC_API_KEY .Renviron—might use usethis::edit_r_environ() open file, set: use another model power pals, use .pal_fn .pal_args options. .pal_fn name chat_*() function elmer, .pal_args list non-default arguments ’d like supply function. example, use models OpenAI, might write: , use GPT 4o mini specifically, might write: ’ll probably want pal always use whichever model ’re configuring option. make selection persist across sessions, add options() code .Rprofile. might use usethis::edit_r_profile() open file. making changes restarting R, pal use new model.","code":"ANTHROPIC_API_KEY=your.key.here options( .pal_fn = \"chat_openai\" ) options( .pal_fn = \"chat_openai\", .pal_args = list(model = \"gpt-4o-mini\") )"},{"path":"https://simonpcouch.github.io/pal/articles/pal.html","id":"the-pal-addin","dir":"Articles","previous_headings":"","what":"The pal addin","title":"Getting started with pal","text":"Rather package functions directly, pals interfaced via pal addin. default model set , ’re ready use package RStudio session (even haven’t loaded package yet). Just: Select code. Trigger pal addin. Type pal “role.” ’s autocompleted, press Enter. Watch code rewritten. Pals interfaced via pal addin. easiest access, recommend registering pal addin keyboard shortcut. RStudio, navigate Tools > Modify Keyboard Shortcuts > Search \"Pal\"—suggest Ctrl+Alt+P (Ctrl+Cmd+P macOS). Positron, ’ll need open command palette, run “Open Keyboard Shortcuts (JSON)”, paste following keybindings.json(): analogous keybinding non-macOS Ctrl+Alt+P. said, change \"key\" entry keybinding wish! steps completed, ’re ready use pals keyboard shortcut.","code":"{ \"key\": \"Ctrl+Cmd+P\", \"command\": \"workbench.action.executeCode.console\", \"when\": \"editorTextFocus\", \"args\": { \"langId\": \"r\", \"code\": \"pal::.init_addin()\", \"focus\": true } }"},{"path":"https://simonpcouch.github.io/pal/articles/pal.html","id":"adding-custom-pals","dir":"Articles","previous_headings":"","what":"Adding custom pals","title":"Getting started with pal","text":"pal package comes three pals package development, one can use pals sorts coding tasks R, interactive data analysis authoring Quarto, even pieces code languages R! need set pal markdown file. pal package looks custom prompts “prompt directory”, can located directory_path() defaults ~/.config/pal. Prompts markdown files (likely created prompt_new()) live prompt directory name like role-interface.md. prompt directory might look like: case, pal register two custom pals call library(pal) (directory_load(). One role \"proofread\" replace selected text proofread version (according instructions contained markdown file ). role \"summarize\" prefix selected text summarized version (, according markdown file’s instructions). Note: Files without .md extension ignored. Files .md extension must contain one hyphen filename, text following hyphen must one replace, prefix, suffix. Custom pals can also situated R package. See palpable example pal extension package. -depth documentation adding custom pals, see documentation prompt_new() friends well directory_load() friends.","code":"/ ├── .config/ │ └── pal/ │ ├── proofread-replace.md │ └── summarize-prefix.md"},{"path":"https://simonpcouch.github.io/pal/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Simon Couch. Author, maintainer.","code":""},{"path":"https://simonpcouch.github.io/pal/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Couch S (2024). pal: LLM assistants R. R package version 0.0.2, https://simonpcouch.github.io/pal/, https://github.com/simonpcouch/pal.","code":"@Manual{, title = {pal: LLM assistants for R}, author = {Simon Couch}, year = {2024}, note = {R package version 0.0.2, https://simonpcouch.github.io/pal/}, url = {https://github.com/simonpcouch/pal}, }"},{"path":"https://simonpcouch.github.io/pal/index.html","id":"your-pal-","dir":"","previous_headings":"","what":"LLM assistants for R","title":"LLM assistants for R","text":"Pals persistent, ergonomic LLM assistants designed help complete repetitive, hard--automate tasks quickly. selecting code, press keyboard shortcut ’ve chosen trigger pal addin (suggest Ctrl+Cmd+P), select pal, watch code rewritten. package highly experimental interface likely change rapidly.","code":""},{"path":"https://simonpcouch.github.io/pal/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"LLM assistants for R","text":"can install pal like : , ensure ANTHROPIC_API_KEY environment variable set, ’re ready go. ’d like use LLM Anthropic’s Claude 3.5 Sonnet—like OpenAI’s ChatGPT—power pal, see Getting started pal vignette. Pals interfaced via pal addin. easiest access, recommend registering pal addin keyboard shortcut. RStudio, navigate Tools > Modify Keyboard Shortcuts > Search \"Pal\"—suggest Ctrl+Alt+P (Ctrl+Cmd+P macOS). Positron, ’ll need open command palette, run “Open Keyboard Shortcuts (JSON)”, paste following keybindings.json: analogous keybinding non-macOS Ctrl+Alt+P. said, change \"key\" entry keybinding wish! steps completed, ’re ready use pals keyboard shortcut.","code":"pak::pak(\"simonpcouch/pal\") { \"key\": \"Ctrl+Cmd+P\", \"command\": \"workbench.action.executeCode.console\", \"when\": \"editorTextFocus\", \"args\": { \"langId\": \"r\", \"code\": \"pal::.init_addin()\", \"focus\": true } }"},{"path":"https://simonpcouch.github.io/pal/index.html","id":"example","dir":"","previous_headings":"","what":"Example","title":"LLM assistants for R","text":"Pals created automatically users interact pal addin. Just highlight code, open addin, begin typing “role” pal press “Return”, watch code rewritten: -, package provides ergonomic LLM assistants R package development: \"cli\": Convert cli \"testthat\": Convert testthat 3 \"roxygen\": Document functions roxygen said, need create pal markdown file instructions ’d like work. See prompt_new() directory_load() information, palpable example pal extension package.","code":""},{"path":"https://simonpcouch.github.io/pal/index.html","id":"how-much-do-pals-cost","dir":"","previous_headings":"","what":"How much do pals cost?","title":"LLM assistants for R","text":"cost using pals depends 1) length underlying prompt given pal 2) cost per token chosen model. Using cli pal Anthropic’s Claude Sonnet 3.5, example, costs something like $15 per 1,000 code refactorings, using testthat pal OpenAI’s GPT 4o-mini cost something like $1 per 1,000 refactorings. Pals using locally-served LLM “free” (usual sense code execution, ignoring cost increased battery usage).","code":""},{"path":"https://simonpcouch.github.io/pal/reference/directory.html","id":null,"dir":"Reference","previous_headings":"","what":"The prompt directory — directory","title":"The prompt directory — directory","text":"pal package's prompt directory directory markdown files automatically registered pal package package load. directory_*() functions allow users interface directory, making new \"roles\" available: directory_path() returns path prompt directory, defaults ~/.config/pal. directory_set() changes path prompt directory (setting option .pal_dir). directory_list() enumerates different prompts currently live directory (provides clickable links ). directory_load() registers prompts prompt directory pal package (via .pal_add()). Functions prefixed prompt*() allow users conveniently create, edit, delete prompts pal's prompt directory.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/directory.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"The prompt directory — directory","text":"","code":"directory_load(dir = directory_path()) directory_list() directory_path() directory_set(dir)"},{"path":"https://simonpcouch.github.io/pal/reference/directory.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"The prompt directory — directory","text":"dir Path directory markdown files–see Details .","code":""},{"path":"https://simonpcouch.github.io/pal/reference/directory.html","id":"format-of-the-prompt-directory","dir":"Reference","previous_headings":"","what":"Format of the prompt directory","title":"The prompt directory — directory","text":"Prompts markdown files name role-interface.md, interface one \"replace\", \"prefix\" \"suffix\". example directory might look like: case, pal register two custom pals call library(pal). One role \"proofread\" replace selected text proofread version (according instructions contained markdown file ). role \"summarize\" prefix selected text summarized version (, according markdown file's instructions). Note: Files without .md extension ignored. Files .md extension must contain one hyphen filename, text following hyphen must one replace, prefix, suffix. load custom prompts every time package loaded, place prompts directory_path(). change prompt directory without loading package, just set .pal_dir option options(.pal_dir = some_dir). load directory files prompt directory, provide dir argument directory_load().","code":"/ ├── .config/ │ └── pal/ │ ├── proofread-replace.md │ └── summarize-prefix.md"},{"path":"https://simonpcouch.github.io/pal/reference/directory.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"The prompt directory — directory","text":"","code":"if (FALSE) { # print out the current prompt directory directory_get() # list out prompts currently in the directory directory_list() # create a prompt in the prompt directory prompt_new(\"boop\", \"replace\") # view updated list of prompts directory_list() # register the prompt with the package # (this will also happen automatically on reload) directory_load() # these are equivalent: directory_set(\"some/folder\") options(.pal_dir = \"some/folder\") }"},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_addin.html","id":null,"dir":"Reference","previous_headings":"","what":"Run the pal addin — .init_addin","title":"Run the pal addin — .init_addin","text":"pal addin allows users interactively select pal interface current selection. function intended interfaced regular usage package. launch pal addin RStudio, navigate Addins > Pal /register addin shortcut via Tools > Modify Keyboard Shortcuts > Search \"Pal\"—suggest Ctrl+Alt+P (Ctrl+Cmd+P macOS).","code":""},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_addin.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run the pal addin — .init_addin","text":"","code":".init_addin()"},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_addin.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run the pal addin — .init_addin","text":"NULL, invisibly. Called side effect launching pal addin interfacing selected text.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_pal.html","id":null,"dir":"Reference","previous_headings":"","what":"Initialize a Pal object — .init_pal","title":"Initialize a Pal object — .init_pal","text":"Users typically need call function. Create new pals automatically registered function prompt_new(). pal addin initialize needed pals --fly.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_pal.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Initialize a Pal object — .init_pal","text":"","code":".init_pal( role = NULL, fn = getOption(\".pal_fn\", default = \"chat_claude\"), ..., .ns = \"elmer\" )"},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_pal.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Initialize a Pal object — .init_pal","text":"role identifier pal prompt. default one \"cli\", \"testthat\" \"roxygen\", though custom pals can added .pal_add(). fn new_*() function, likely elmer package. Defaults elmer::chat_claude(). set persistent alternative default, set .pal_fn option; see examples . ... Additional arguments fn. system_prompt argument ignored supplied. set persistent defaults, set .pal_args option; see examples . .ns package new_*() function exported .","code":""},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_pal.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Initialize a Pal object — .init_pal","text":"Anthropic API key (another API key pal_*() options) set package installed, ready using addin R session setup library loading required; addin knows look API credentials call needed functions .","code":""},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_pal.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Initialize a Pal object — .init_pal","text":"","code":"if (FALSE) { # to create a chat with claude: .init_pal() # or with OpenAI's 4o-mini: .init_pal( \"chat_openai\", model = \"gpt-4o-mini\" ) # to set OpenAI's 4o-mini as the default, for example, set the # following options (possibly in your .Rprofile, if you'd like # them to persist across sessions): options( .pal_fn = \"chat_openai\", .pal_args = list(model = \"gpt-4o-mini\") ) }"},{"path":"https://simonpcouch.github.io/pal/reference/pal-package.html","id":null,"dir":"Reference","previous_headings":"","what":"pal: LLM assistants for R — pal-package","title":"pal: LLM assistants for R — pal-package","text":"Pals persistent, ergonomic LLM assistants designed help complete repetitive, hard--automate tasks quickly. selecting code, press keyboard shortcut chosen trigger pal addin, select pal, watch code rewritten. number pals R package development ship package, users can create suite custom pals directory markdown files.","code":""},{"path":[]},{"path":"https://simonpcouch.github.io/pal/reference/pal-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"pal: LLM assistants for R — pal-package","text":"Maintainer: Simon Couch simon.couch@posit.co (ORCID)","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":null,"dir":"Reference","previous_headings":"","what":"Registering pals — pal_add_remove","title":"Registering pals — pal_add_remove","text":"Users can create custom pals using .pal_add() function; passing function role prompt, pal available pal addin. users need interact functions. prompt_new() friends can used create prompts new pals, pals can registered pal using directory_load() friends. pals created functions persistent across sessions.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Registering pals — pal_add_remove","text":"","code":".pal_add(role, prompt = NULL, interface = c(\"replace\", \"prefix\", \"suffix\")) .pal_remove(role)"},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Registering pals — pal_add_remove","text":"role single string giving descriptor pal's functionality. Cand contain letters numbers. prompt single string giving system prompt. cases, rather long string, containing several newlines. interface One \"replace\", \"prefix\", \"suffix\", describing pal interact selection. example, cli pal \"replace\"s selection, roxygen pal \"prefixes\" selected code documentation.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Registering pals — pal_add_remove","text":"NULL, invisibly. Called side effect: pal role role registered (unregistered) pal package.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_cli.html","id":null,"dir":"Reference","previous_headings":"","what":"The cli pal — pal_cli","title":"The cli pal — pal_cli","text":"couple years ago, tidyverse team began migrating cli R package raising errors, transitioning away base R (e.g. stop()), rlang (e.g. rlang::abort()), glue, homegrown combinations . cli's new syntax easier work developer visually pleasing user. cases, transitioning simple Finding + Replacing rlang::abort() cli::cli_abort(). others, mess ad-hoc pluralization, paste0()s, glue interpolations, assorted nonsense sort . Total pain, especially thousands upon thousands error messages thrown across tidyverse, r-lib, tidymodels organizations. cli pal helps convert R package use cli error messages.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_cli.html","id":"cost","dir":"Reference","previous_headings":"","what":"Cost","title":"The cli pal — pal_cli","text":"system prompt pal includes something like 4,000 tokens. Add (generous) 100 tokens code actually highlighted also sent model looking 4,100 input tokens. model returns approximately number output tokens receives, call 100 output tokens per refactor. time writing (October 2024), default pal model Claude Sonnet 3.5 costs $3 per million input tokens $15 per million output tokens. , using default model, cli pals cost around $15 every 1,000 refactored pieces code. GPT-4o Mini, contrast, tend get cli markup classes right return syntactically valid calls cli functions, cost around 75 cents per 1,000 refactored pieces code.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_cli.html","id":"gallery","dir":"Reference","previous_headings":"","what":"Gallery","title":"The cli pal — pal_cli","text":"section includes handful examples \"wild\" generated default model, Claude Sonnet 3.5. simplest, one-line message little bit markup: Returns: strange vector collapsing funky line breaking: Returns: message probably best lives two separate elements: Returns: Gnarly ad-hoc pluralization: Returns: paste0() wonk: Returns: model instructed return call cli function, erroring code run conditionally can get borked: Returns: Note ?valid cli markup. Sprintf-style statements issue: Returns:","code":"rlang::abort(\"`save_pred` can only be used if the initial results saved predictions.\") cli::cli_abort(\"{.arg save_pred} can only be used if the initial results saved predictions.\") extra_grid_params <- glue::single_quote(extra_grid_params) extra_grid_params <- glue::glue_collapse(extra_grid_params, sep = \", \") msg <- glue::glue( \"The provided `grid` has the following parameter columns that have \", \"not been marked for tuning by `tune()`: {extra_grid_params}.\" ) rlang::abort(msg) cli::cli_abort( \"The provided {.arg grid} has parameter columns that have not been marked for tuning by {.fn tune}: {.val {extra_grid_params}}.\" ) rlang::abort( paste( \"Some model parameters require finalization but there are recipe\", \"parameters that require tuning. Please use \", \"`extract_parameter_set_dials()` to set parameter ranges \", \"manually and supply the output to the `param_info` argument.\" ) ) cli::cli_abort( c( \"Some model parameters require finalization but there are recipe parameters that require tuning.\", \"i\" = \"Please use {.fn extract_parameter_set_dials} to set parameter ranges manually and supply the output to the {.arg param_info} argument.\" ) ) msg <- \"Creating pre-processing data to finalize unknown parameter\" unk_names <- pset$id[unk] if (length(unk_names) == 1) { msg <- paste0(msg, \": \", unk_names) } else { msg <- paste0(msg, \"s: \", paste0(\"'\", unk_names, \"'\", collapse = \", \")) } rlang::inform(msg) cli::cli_inform( \"Creating pre-processing data to finalize unknown parameter{?s}: {.val {unk_names}}\" ) rlang::abort(paste0( \"The workflow has arguments to be tuned that are missing some \", \"parameter objects: \", paste0(\"'\", pset$id[!params], \"'\", collapse = \", \") )) cli::cli_abort( \"The workflow has arguments to be tuned that are missing some parameter objects: {.val {pset$id[!params]}}\" ) cls <- paste(cls, collapse = \" or \") if (!fine) { msg <- glue::glue(\"Argument '{deparse(cl$x)}' should be a {cls} or NULL\") if (!is.null(where)) { msg <- glue::glue(msg, \" in `{where}`\") } rlang::abort(msg) } cli::cli_abort( \"Argument {.code {deparse(cl$x)}} should be {?a/an} {.cls {cls}} or {.code NULL}{?in {where}}.\" ) abort(sprintf(\"No such '%s' function: `%s()`.\", package, name)) cli::cli_abort(\"No such {.pkg {package}} function: {.fn {name}}.\")"},{"path":"https://simonpcouch.github.io/pal/reference/pal_cli.html","id":"interfacing-manually-with-the-cli-pal","dir":"Reference","previous_headings":"","what":"Interfacing manually with the cli pal","title":"The cli pal — pal_cli","text":"Pals typically interfaced via pal addin. call cli pal directly, use: , submit query, run:","code":"pal_cli <- .init_pal(\"cli\") pal_cli$chat({expr})"},{"path":"https://simonpcouch.github.io/pal/reference/pal_roxygen.html","id":null,"dir":"Reference","previous_headings":"","what":"The roxygen pal — pal_roxygen","title":"The roxygen pal — pal_roxygen","text":"roxygen pal prefixes selected function minimal roxygen2 documentation template. pal instructed generate subset complete documentation entry, completed developer: Stub @param descriptions based defaults inferred types Stub @returns entry describes return value well important errors warnings users might encounter.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_roxygen.html","id":"cost","dir":"Reference","previous_headings":"","what":"Cost","title":"The roxygen pal — pal_roxygen","text":"system prompt roxygen pal includes something like 1,000 tokens. Add 200 tokens code actually highlighted also sent model looking 1,200 input tokens. model returns maybe 10 15 lines relatively barebones royxgen documentation, call 200 output tokens per refactor. time writing (October 2024), default pal model Claude Sonnet 3.5 costs $3 per million input tokens $15 per million output tokens. , using default model, roxygen pals cost around $4 every 1,000 generated roxygen documentation entries. GPT-4o Mini, contrast, tend infer argument types correctly often often fails line-break properly, usually return syntactically valid documentation entries, cost around 20 cents per 1,000 generated roxygen documentation entries.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_roxygen.html","id":"gallery","dir":"Reference","previous_headings":"","what":"Gallery","title":"The roxygen pal — pal_roxygen","text":"section includes handful examples \"wild\" generated default model, Claude Sonnet 3.5. Documenting function factory: Returns: function may raise condition: Returns: function tricky indexing: Returns:","code":"deferred_method_transform <- function(lambda_expr, transformer, eval_env) { transformer <- enexpr(transformer) force(eval_env) unique_id <- new_id() env_bind_lazy( generators, !!unique_id := inject((!!transformer)(!!lambda_expr)), eval.env = eval_env ) inject( function(...) { (!!generators)[[!!unique_id]](self, private, ...) } ) } #' #' Transform a deferred method #' #' @description #' A short description... #' #' @param lambda_expr A lambda expression to transform. #' @param transformer A transformer function or expression. #' @param eval_env The environment in which to evaluate the transformer. #' #' @returns #' A function that, when called, will evaluate the transformed lambda expression. #' The returned function accepts `...` arguments which are passed to the generated function. #' #' @export set_default <- function(value, default, arg = caller_arg(value)) { if (is.null(value)) { if (!is_testing() || is_snapshot()) { cli::cli_inform(\"Using {.field {arg}} = {.val {default}}.\") } default } else { value } } #' Set default value #' #' @description #' A short description... #' #' @param value A value to check. #' @param default The default value to use if `value` is NULL. #' @param arg Optional. The name of the argument being set. #' #' @returns #' Returns `value` if it's not NULL, otherwise returns `default`. #' Informs the user when using the default value. #' #' @export find_index <- function(left, e_right) { if (!is.list(e_right) || !has_name(e_right, \"index\") || !is.numeric(e_right$index)) { return(NA) } matches_idx <- map_lgl(left, function(e_left) e_left$index == e_right$index) if (sum(matches_idx) != 1) { return(NA) } which(matches_idx)[[1]] } #' Find matching index #' #' @description #' A short description... #' #' @param left A list of elements, each expected to have an 'index' field. #' @param e_right A list with an 'index' field to search for in `left`. #' #' @returns #' The numeric index in `left` where `e_right$index` matches, or NA if not found #' or if inputs are invalid. Returns NA if multiple matches are found. #' #' @export"},{"path":"https://simonpcouch.github.io/pal/reference/pal_roxygen.html","id":"interfacing-manually-with-the-roxygen-pal","dir":"Reference","previous_headings":"","what":"Interfacing manually with the roxygen pal","title":"The roxygen pal — pal_roxygen","text":"Pals typically interfaced via pal addin. call roxygen pal directly, use: , submit query, run:","code":"pal_roxygen <- .init_pal(\"roxygen\") pal_roxygen$chat({expr})"},{"path":"https://simonpcouch.github.io/pal/reference/pal_testthat.html","id":null,"dir":"Reference","previous_headings":"","what":"The testthat pal — pal_testthat","title":"The testthat pal — pal_testthat","text":"testthat 3.0.0 released 2020, bringing numerous changes huge quality life improvements package developers also highly breaking changes. task converting legacy unit testing code testthat 3e quite pretty straightforward, components can quite tedious. testthat pal helps transition R package's unit tests third edition testthat, namely via: Converting snapshot tests Disentangling nested expectations Transitioning deprecated functions like expect_known_*()","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_testthat.html","id":"cost","dir":"Reference","previous_headings":"","what":"Cost","title":"The testthat pal — pal_testthat","text":"system prompt testthat pal includes something like 1,000 tokens. Add (generous) 100 tokens code actually highlighted also sent model looking 1,100 input tokens. model returns approximately number output tokens receives, call 100 output tokens per refactor. time writing (October 2024), default pal model Claude Sonnet 3.5 costs $3 per million input tokens $15 per million output tokens. , using default model, testthat pals cost around $4 every 1,000 refactored pieces code. GPT-4o Mini, contrast, tend get many pieces formatting right often fails line-break properly, usually return syntactically valid calls testthat functions, cost around 20 cents per 1,000 refactored pieces code.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_testthat.html","id":"gallery","dir":"Reference","previous_headings":"","what":"Gallery","title":"The testthat pal — pal_testthat","text":"section includes handful examples \"wild\" generated default model, Claude Sonnet 3.5. Testthat pals convert expect_error() (*_warning() *_message() *_condition()) calls use expect_snapshot() regular expression present: Returns: Note, well, intermediate results assigned object snapshotted contents previously tests. Another example multiple, redudant calls: Returns: know regexp = NA, means \"error\" (warning, message): Returns: also know adjust calls condition expectations class argument present (usually means one testing condition another package, able change wording message without consequence): Returns: converting non-erroring code, testthat pals assign intermediate results snapshot result warning: Returns: Nested expectations can generally disentangled without issue: Returns: also edits pal knows make third-edition code. example, transitions expect_snapshot_error() friends use expect_snapshot(error = TRUE) error context snapshotted addition message : Returns:","code":"expect_warning( check_ellipses(\"exponentiate\", \"tidy\", \"boop\", exponentiate = TRUE, quick = FALSE), \"\\\\`exponentiate\\\\` argument is not supported in the \\\\`tidy\\\\(\\\\)\\\\` method for \\\\`boop\\\\` objects\" ) expect_snapshot( .res <- check_ellipses( \"exponentiate\", \"tidy\", \"boop\", exponentiate = TRUE, quick = FALSE ) ) augment_error <- \"augment is only supported for fixest models estimated with feols, feglm, or femlm\" expect_error(augment(res_fenegbin, df), augment_error) expect_error(augment(res_feNmlm, df), augment_error) expect_error(augment(res_fepois, df), augment_error) expect_snapshot(error = TRUE, augment(res_fenegbin, df)) expect_snapshot(error = TRUE, augment(res_feNmlm, df)) expect_snapshot(error = TRUE, augment(res_fepois, df)) expect_error( p4_b <- check_parameters(w4, p4_a, data = mtcars), regex = NA ) expect_no_error(p4_b <- check_parameters(w4, p4_a, data = mtcars)) expect_error(tidy(pca, matrix = \"u\"), class = \"pca_error\") expect_error(tidy(pca, matrix = \"u\"), class = \"pca_error\") expect_warning( tidy(fit, robust = TRUE), '\"robust\" argument has been deprecated' ) expect_snapshot( .res <- tidy(fit, robust = TRUE) ) expect_equal( fit_resamples(decision_tree(cost_complexity = 1), bootstraps(mtcars)), expect_warning(tune_grid(decision_tree(cost_complexity = 1), bootstraps(mtcars))) ) expect_snapshot({ fit_resamples_result <- fit_resamples(decision_tree(cost_complexity = 1), bootstraps(mtcars)) tune_grid_result <- tune_grid(decision_tree(cost_complexity = 1), bootstraps(mtcars)) }) expect_equal(fit_resamples_result, tune_grid_result) expect_snapshot_error( fit_best(knn_pca_res, parameters = tibble(neighbors = 2)) ) expect_snapshot( error = TRUE, fit_best(knn_pca_res, parameters = tibble(neighbors = 2)) )"},{"path":"https://simonpcouch.github.io/pal/reference/pal_testthat.html","id":"interfacing-manually-with-the-testthat-pal","dir":"Reference","previous_headings":"","what":"Interfacing manually with the testthat pal","title":"The testthat pal — pal_testthat","text":"Pals typically interfaced via pal addin. call testthat pal directly, use: , submit query, run:","code":"pal_testthat <- .init_pal(\"testthat\") pal_testthat$chat({expr})"},{"path":"https://simonpcouch.github.io/pal/reference/prompt.html","id":null,"dir":"Reference","previous_headings":"","what":"Working with pal prompts — prompt","title":"Working with pal prompts — prompt","text":"pal package provides number tools working system prompts. System prompts instruct pals behave provide information live models' \"short-term memory.\" prompt_*() functions allow users conveniently create, edit, remove, prompts pal's \"prompt directory.\" prompt_new() creates new markdown file automatically create pal specified role, prompt, interface package load. Specify contents argument prefill contents markdown file computer web. prompt_edit() prompt_remove() open delete, respectively, file defines given role's system prompt. Load prompts create functions using directory_load() (automatically called package loads).","code":""},{"path":"https://simonpcouch.github.io/pal/reference/prompt.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Working with pal prompts — prompt","text":"","code":"prompt_new(role, interface, contents = NULL) prompt_remove(role) prompt_edit(role)"},{"path":"https://simonpcouch.github.io/pal/reference/prompt.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Working with pal prompts — prompt","text":"role single string giving descriptor pal's functionality. Cand contain letters numbers. interface One \"replace\", \"prefix\", \"suffix\", describing pal interact selection. example, cli pal \"replace\"s selection, roxygen pal \"prefixes\" selected code documentation. contents Optional. Path markdown file contents \"pre-fill\" file. Anything file ending .md .markdown can read readLines() fair game; local file, \"raw\" URL GitHub Gist file GitHub repository, etc.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/prompt.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Working with pal prompts — prompt","text":"prompt_*() function returns file path created, edited, removed filepath, invisibly.","code":""},{"path":[]},{"path":"https://simonpcouch.github.io/pal/reference/prompt.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Working with pal prompts — prompt","text":"","code":"if (FALSE) { # create a new pal with role `\"boop\"` that replaces the selected text: prompt_new(\"boop\") # after writing a prompt, register it with the pal package with: directory_load() # after closing the file, reopen with: prompt_edit(\"boop\") # remove the prompt (next time the package is loaded) with: prompt_remove(\"boop\") # pull prompts from files on local drives or the web with # `prompt_new(contents)`. for example, here is a GitHub Gist: # paste0( # \"https://gist.githubusercontent.com/simonpcouch/\", # \"daaa6c4155918d6f3efd6706d022e584/raw/ed1da68b3f38a25b58dd9fdc8b9c258d\", # \"58c9b4da/summarize-prefix.md\" # ) # # press \"Raw\" and then supply that URL as `contents` (you don't actually # have to use the paste0() to write out the URL--we're just keeping # the characters per line under 80): prompt_new( role = \"summarize\", interface = \"prefix\", contents = paste0( \"https://gist.githubusercontent.com/simonpcouch/\", \"daaa6c4155918d6f3efd6706d022e584/raw/ed1da68b3f38a25b58dd9fdc8b9c258d\", \"58c9b4da/summarize-prefix.md\" ) ) }"}] +[{"path":[]},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement codeofconduct@posit.co. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://simonpcouch.github.io/pal/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":null,"dir":"","previous_headings":"","what":"Contributing to pal","title":"Contributing to pal","text":"outlines propose change pal. detailed discussion contributing tidyverse packages, please see development contributing guide code review principles.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":"fixing-typos","dir":"","previous_headings":"","what":"Fixing typos","title":"Contributing to pal","text":"can fix typos, spelling mistakes, grammatical errors documentation directly using GitHub web interface, long changes made source file. generally means ’ll need edit roxygen2 comments .R, .Rd file. can find .R file generates .Rd reading comment first line.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":"bigger-changes","dir":"","previous_headings":"","what":"Bigger changes","title":"Contributing to pal","text":"want make bigger change, ’s good idea first file issue make sure someone team agrees ’s needed. ’ve found bug, please file issue illustrates bug minimal reprex (also help write unit test, needed). See guide create great issue advice.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":"pull-request-process","dir":"","previous_headings":"Bigger changes","what":"Pull request process","title":"Contributing to pal","text":"Fork package clone onto computer. haven’t done , recommend using usethis::create_from_github(\"simonpcouch/pal\", fork = TRUE). Install development dependencies devtools::install_dev_deps(), make sure package passes R CMD check running devtools::check(). R CMD check doesn’t pass cleanly, ’s good idea ask help continuing. Create Git branch pull request (PR). recommend using usethis::pr_init(\"brief-description--change\"). Make changes, commit git, create PR running usethis::pr_push(), following prompts browser. title PR briefly describe change. body PR contain Fixes #issue-number. user-facing changes, add bullet top NEWS.md (.e. just first header). Follow style described https://style.tidyverse.org/news.html.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":"code-style","dir":"","previous_headings":"Bigger changes","what":"Code style","title":"Contributing to pal","text":"New code follow tidyverse style guide. can use styler package apply styles, please don’t restyle code nothing PR. use roxygen2, Markdown syntax, documentation. use testthat unit tests. Contributions test cases included easier accept.","code":""},{"path":"https://simonpcouch.github.io/pal/CONTRIBUTING.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"Contributing to pal","text":"Please note pal project released Contributor Code Conduct. contributing project agree abide terms.","code":""},{"path":"https://simonpcouch.github.io/pal/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2024 pal authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://simonpcouch.github.io/pal/SUPPORT.html","id":null,"dir":"","previous_headings":"","what":"Getting help with pal","title":"Getting help with pal","text":"Thanks using pal! filing issue, places explore pieces put together make process smooth possible.","code":""},{"path":"https://simonpcouch.github.io/pal/SUPPORT.html","id":"make-a-reprex","dir":"","previous_headings":"","what":"Make a reprex","title":"Getting help with pal","text":"Start making minimal reproducible example using reprex package. haven’t heard used reprex , ’re treat! Seriously, reprex make R-question-asking endeavors easier (pretty incredible ROI five ten minutes ’ll take learn ’s ). additional reprex pointers, check Get help! section tidyverse site.","code":""},{"path":"https://simonpcouch.github.io/pal/SUPPORT.html","id":"where-to-ask","dir":"","previous_headings":"","what":"Where to ask?","title":"Getting help with pal","text":"Armed reprex, next step figure ask. ’s question: start community.rstudio.com, /StackOverflow. people answer questions. ’s bug: ’re right place, file issue. ’re sure: let community help figure ! problem bug feature request, can easily return report . opening new issue, sure search issues pull requests make sure bug hasn’t reported /already fixed development version. default, search pre-populated :issue :open. can edit qualifiers (e.g. :pr, :closed) needed. example, ’d simply remove :open search issues repo, open closed.","code":""},{"path":"https://simonpcouch.github.io/pal/SUPPORT.html","id":"what-happens-next","dir":"","previous_headings":"","what":"What happens next?","title":"Getting help with pal","text":"efficient possible, development tidyverse packages tends bursty, shouldn’t worry don’t get immediate response. Typically don’t look repo sufficient quantity issues accumulates, ’s burst intense activity focus efforts. makes development efficient avoids expensive context switching problems, cost taking longer get back . process makes good reprex particularly important might multiple months initial report start working . can’t reproduce bug, can’t fix !","code":""},{"path":"https://simonpcouch.github.io/pal/articles/pal.html","id":"choosing-a-model","dir":"Articles","previous_headings":"","what":"Choosing a model","title":"Getting started with pal","text":"hood, pals driven Large Language Models (LLMs). use pals, need API key commercial model connection locally hosted model. Pals use elmer package interface LLMs. model supported elmer supported pal. October 2024, highly recommend Anthropic’s Claude Sonnet 3.5 model power pals. Compared models ’ve tried, Claude likely generate syntactically valid code aligns pal’s prompt well. , Claude default model used pal. want use Claude pal, additional setup step need set ANTHROPIC_API_KEY .Renviron—might use usethis::edit_r_environ() open file, set: use another model power pals, use .pal_fn .pal_args options. .pal_fn name chat_*() function elmer, .pal_args list non-default arguments ’d like supply function. example, use models OpenAI, might write: , use GPT 4o mini specifically, might write: ’ll probably want pal always use whichever model ’re configuring option. make selection persist across sessions, add options() code .Rprofile. might use usethis::edit_r_profile() open file. making changes restarting R, pal use new model.","code":"ANTHROPIC_API_KEY=your.key.here options( .pal_fn = \"chat_openai\" ) options( .pal_fn = \"chat_openai\", .pal_args = list(model = \"gpt-4o-mini\") )"},{"path":"https://simonpcouch.github.io/pal/articles/pal.html","id":"the-pal-addin","dir":"Articles","previous_headings":"","what":"The pal addin","title":"Getting started with pal","text":"Rather package functions directly, pals interfaced via pal addin. default model set , ’re ready use package RStudio session (even haven’t loaded package yet). Just: Select code. Trigger pal addin. Type pal “role.” ’s autocompleted, press Enter. Watch code rewritten. Pals interfaced via pal addin. easiest access, recommend registering pal addin keyboard shortcut. RStudio, navigate Tools > Modify Keyboard Shortcuts > Search \"Pal\"—suggest Ctrl+Alt+P (Ctrl+Cmd+P macOS). Positron, ’ll need open command palette, run “Open Keyboard Shortcuts (JSON)”, paste following keybindings.json(): analogous keybinding non-macOS Ctrl+Alt+P. said, change \"key\" entry keybinding wish! steps completed, ’re ready use pals keyboard shortcut.","code":"{ \"key\": \"Ctrl+Cmd+P\", \"command\": \"workbench.action.executeCode.console\", \"when\": \"editorTextFocus\", \"args\": { \"langId\": \"r\", \"code\": \"pal::.init_addin()\", \"focus\": true } }"},{"path":"https://simonpcouch.github.io/pal/articles/pal.html","id":"adding-custom-pals","dir":"Articles","previous_headings":"","what":"Adding custom pals","title":"Getting started with pal","text":"pal package comes three pals package development, one can use pals sorts coding tasks R, interactive data analysis authoring Quarto, even pieces code languages R! need set pal markdown file. pal package looks custom prompts “prompt directory”, can located directory_path() defaults ~/.config/pal. Prompts markdown files (likely created prompt_new()) live prompt directory name like role-interface.md. prompt directory might look like: case, pal register two custom pals call library(pal) (directory_load(). One role \"proofread\" replace selected text proofread version (according instructions contained markdown file ). role \"summarize\" prefix selected text summarized version (, according markdown file’s instructions). Note: Files without .md extension ignored. Files .md extension must contain one hyphen filename, text following hyphen must one replace, prefix, suffix. Custom pals can also situated R package. See palpable example pal extension package. -depth documentation adding custom pals, see documentation prompt_new() friends well directory_load() friends.","code":"/ ├── .config/ │ └── pal/ │ ├── proofread-replace.md │ └── summarize-prefix.md"},{"path":"https://simonpcouch.github.io/pal/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Simon Couch. Author, maintainer.","code":""},{"path":"https://simonpcouch.github.io/pal/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Couch S (2024). pal: LLM assistants R. R package version 0.0.2, https://simonpcouch.github.io/pal/, https://github.com/simonpcouch/pal.","code":"@Manual{, title = {pal: LLM assistants for R}, author = {Simon Couch}, year = {2024}, note = {R package version 0.0.2, https://simonpcouch.github.io/pal/}, url = {https://github.com/simonpcouch/pal}, }"},{"path":"https://simonpcouch.github.io/pal/index.html","id":"your-pal-","dir":"","previous_headings":"","what":"LLM assistants for R","title":"LLM assistants for R","text":"Pals persistent, ergonomic LLM assistants designed help complete repetitive, hard--automate tasks quickly. selecting code, press keyboard shortcut ’ve chosen trigger pal addin (suggest Ctrl+Cmd+P), select pal, watch code rewritten. package highly experimental interface likely change rapidly.","code":""},{"path":"https://simonpcouch.github.io/pal/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"LLM assistants for R","text":"can install pal like : , ensure ANTHROPIC_API_KEY environment variable set, ’re ready go. ’d like use LLM Anthropic’s Claude 3.5 Sonnet—like OpenAI’s ChatGPT—power pal, see Getting started pal vignette. Pals interfaced via pal addin. easiest access, recommend registering pal addin keyboard shortcut. RStudio, navigate Tools > Modify Keyboard Shortcuts > Search \"Pal\"—suggest Ctrl+Alt+P (Ctrl+Cmd+P macOS). Positron, ’ll need open command palette, run “Open Keyboard Shortcuts (JSON)”, paste following keybindings.json: analogous keybinding non-macOS Ctrl+Alt+P. said, change \"key\" entry keybinding wish! steps completed, ’re ready use pals keyboard shortcut.","code":"pak::pak(\"simonpcouch/pal\") { \"key\": \"Ctrl+Cmd+P\", \"command\": \"workbench.action.executeCode.console\", \"when\": \"editorTextFocus\", \"args\": { \"langId\": \"r\", \"code\": \"pal::.init_addin()\", \"focus\": true } }"},{"path":"https://simonpcouch.github.io/pal/index.html","id":"example","dir":"","previous_headings":"","what":"Example","title":"LLM assistants for R","text":"Pals created automatically users interact pal addin. Just highlight code, open addin, begin typing “role” pal press “Return”, watch code rewritten: -, package provides ergonomic LLM assistants R package development: \"cli\": Convert cli \"testthat\": Convert testthat 3 \"roxygen\": Document functions roxygen said, need create pal markdown file instructions ’d like work. See prompt_new() directory_load() information, palpable example pal extension package.","code":""},{"path":"https://simonpcouch.github.io/pal/index.html","id":"how-much-do-pals-cost","dir":"","previous_headings":"","what":"How much do pals cost?","title":"LLM assistants for R","text":"cost using pals depends 1) length underlying prompt given pal 2) cost per token chosen model. Using cli pal Anthropic’s Claude Sonnet 3.5, example, costs something like $15 per 1,000 code refactorings, using testthat pal OpenAI’s GPT 4o-mini cost something like $1 per 1,000 refactorings. Pals using locally-served LLM “free” (usual sense code execution, ignoring cost increased battery usage).","code":""},{"path":"https://simonpcouch.github.io/pal/reference/directory.html","id":null,"dir":"Reference","previous_headings":"","what":"The prompt directory — directory","title":"The prompt directory — directory","text":"pal package's prompt directory directory markdown files automatically registered pal package package load. directory_*() functions allow users interface directory, making new \"roles\" available: directory_path() returns path prompt directory, defaults ~/.config/pal. directory_set() changes path prompt directory (setting option .pal_dir). directory_list() enumerates different prompts currently live directory (provides clickable links ). directory_load() registers prompts prompt directory pal package (via .pal_add()). Functions prefixed prompt*() allow users conveniently create, edit, delete prompts pal's prompt directory.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/directory.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"The prompt directory — directory","text":"","code":"directory_load(dir = directory_path()) directory_list() directory_path() directory_set(dir)"},{"path":"https://simonpcouch.github.io/pal/reference/directory.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"The prompt directory — directory","text":"dir Path directory markdown files–see Details .","code":""},{"path":"https://simonpcouch.github.io/pal/reference/directory.html","id":"format-of-the-prompt-directory","dir":"Reference","previous_headings":"","what":"Format of the prompt directory","title":"The prompt directory — directory","text":"Prompts markdown files name role-interface.md, interface one \"replace\", \"prefix\" \"suffix\". example directory might look like: case, pal register two custom pals call library(pal). One role \"proofread\" replace selected text proofread version (according instructions contained markdown file ). role \"summarize\" prefix selected text summarized version (, according markdown file's instructions). Note: Files without .md extension ignored. Files .md extension must contain one hyphen filename, text following hyphen must one replace, prefix, suffix. load custom prompts every time package loaded, place prompts directory_path(). change prompt directory without loading package, just set .pal_dir option options(.pal_dir = some_dir). load directory files prompt directory, provide dir argument directory_load().","code":"/ ├── .config/ │ └── pal/ │ ├── proofread-replace.md │ └── summarize-prefix.md"},{"path":"https://simonpcouch.github.io/pal/reference/directory.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"The prompt directory — directory","text":"","code":"if (FALSE) { # print out the current prompt directory directory_get() # list out prompts currently in the directory directory_list() # create a prompt in the prompt directory prompt_new(\"boop\", \"replace\") # view updated list of prompts directory_list() # register the prompt with the package # (this will also happen automatically on reload) directory_load() # these are equivalent: directory_set(\"some/folder\") options(.pal_dir = \"some/folder\") }"},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_addin.html","id":null,"dir":"Reference","previous_headings":"","what":"Run the pal addin — .init_addin","title":"Run the pal addin — .init_addin","text":"pal addin allows users interactively select pal interface current selection. function intended interfaced regular usage package. launch pal addin RStudio, navigate Addins > Pal /register addin shortcut via Tools > Modify Keyboard Shortcuts > Search \"Pal\"—suggest Ctrl+Alt+P (Ctrl+Cmd+P macOS).","code":""},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_addin.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run the pal addin — .init_addin","text":"","code":".init_addin()"},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_addin.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run the pal addin — .init_addin","text":"NULL, invisibly. Called side effect launching pal addin interfacing selected text.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_pal.html","id":null,"dir":"Reference","previous_headings":"","what":"Initialize a Pal object — .init_pal","title":"Initialize a Pal object — .init_pal","text":"Users typically need call function. Create new pals automatically registered function prompt_new(). pal addin initialize needed pals --fly.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_pal.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Initialize a Pal object — .init_pal","text":"","code":".init_pal( role = NULL, fn = getOption(\".pal_fn\", default = \"chat_claude\"), ..., .ns = \"elmer\" )"},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_pal.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Initialize a Pal object — .init_pal","text":"role identifier pal prompt. default one \"cli\", \"testthat\" \"roxygen\", though custom pals can added .pal_add(). fn new_*() function, likely elmer package. Defaults elmer::chat_claude(). set persistent alternative default, set .pal_fn option; see examples . ... Additional arguments fn. system_prompt argument ignored supplied. set persistent defaults, set .pal_args option; see examples . .ns package new_*() function exported .","code":""},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_pal.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Initialize a Pal object — .init_pal","text":"Anthropic API key (another API key pal_*() options) set package installed, ready using addin R session setup library loading required; addin knows look API credentials call needed functions .","code":""},{"path":"https://simonpcouch.github.io/pal/reference/dot-init_pal.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Initialize a Pal object — .init_pal","text":"","code":"if (FALSE) { # to create a chat with claude: .init_pal() # or with OpenAI's 4o-mini: .init_pal( \"chat_openai\", model = \"gpt-4o-mini\" ) # to set OpenAI's 4o-mini as the default, for example, set the # following options (possibly in your .Rprofile, if you'd like # them to persist across sessions): options( .pal_fn = \"chat_openai\", .pal_args = list(model = \"gpt-4o-mini\") ) }"},{"path":"https://simonpcouch.github.io/pal/reference/pal-package.html","id":null,"dir":"Reference","previous_headings":"","what":"pal: LLM assistants for R — pal-package","title":"pal: LLM assistants for R — pal-package","text":"Pals persistent, ergonomic LLM assistants designed help complete repetitive, hard--automate tasks quickly. selecting code, press keyboard shortcut chosen trigger pal addin, select pal, watch code rewritten. number pals R package development ship package, users can create suite custom pals directory markdown files.","code":""},{"path":[]},{"path":"https://simonpcouch.github.io/pal/reference/pal-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"pal: LLM assistants for R — pal-package","text":"Maintainer: Simon Couch simon.couch@posit.co (ORCID)","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":null,"dir":"Reference","previous_headings":"","what":"Registering pals — pal_add_remove","title":"Registering pals — pal_add_remove","text":"Users can create custom pals using .pal_add() function; passing function role prompt, pal available pal addin. users need interact functions. prompt_new() friends can used create prompts new pals, pals can registered pal using directory_load() friends. pals created functions persistent across sessions.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Registering pals — pal_add_remove","text":"","code":".pal_add(role, prompt = NULL, interface = c(\"replace\", \"prefix\", \"suffix\")) .pal_remove(role)"},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Registering pals — pal_add_remove","text":"role single string giving descriptor pal's functionality. Cand contain letters numbers. prompt single string giving system prompt. cases, rather long string, containing several newlines. interface One \"replace\", \"prefix\", \"suffix\", describing pal interact selection. example, cli pal \"replace\"s selection, roxygen pal \"prefixes\" selected code documentation.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Registering pals — pal_add_remove","text":"NULL, invisibly. Called side effect: pal role role registered (unregistered) pal package.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_cli.html","id":null,"dir":"Reference","previous_headings":"","what":"The cli pal — pal_cli","title":"The cli pal — pal_cli","text":"couple years ago, tidyverse team began migrating cli R package raising errors, transitioning away base R (e.g. stop()), rlang (e.g. rlang::abort()), glue, homegrown combinations . cli's new syntax easier work developer visually pleasing user. cases, transitioning simple Finding + Replacing rlang::abort() cli::cli_abort(). others, mess ad-hoc pluralization, paste0()s, glue interpolations, assorted nonsense sort . Total pain, especially thousands upon thousands error messages thrown across tidyverse, r-lib, tidymodels organizations. cli pal helps convert R package use cli error messages.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_cli.html","id":"cost","dir":"Reference","previous_headings":"","what":"Cost","title":"The cli pal — pal_cli","text":"system prompt pal includes something like 4,000 tokens. Add (generous) 100 tokens code actually highlighted also sent model looking 4,100 input tokens. model returns approximately number output tokens receives, call 100 output tokens per refactor. time writing (October 2024), default pal model Claude Sonnet 3.5 costs $3 per million input tokens $15 per million output tokens. , using default model, cli pals cost around $15 every 1,000 refactored pieces code. GPT-4o Mini, contrast, tend get cli markup classes right return syntactically valid calls cli functions, cost around 75 cents per 1,000 refactored pieces code.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_cli.html","id":"gallery","dir":"Reference","previous_headings":"","what":"Gallery","title":"The cli pal — pal_cli","text":"section includes handful examples \"wild\" generated default model, Claude Sonnet 3.5. simplest, one-line message little bit markup: Returns: strange vector collapsing funky line breaking: Returns: message probably best lives two separate elements: Returns: Gnarly ad-hoc pluralization: Returns: paste0() wonk: Returns: model instructed return call cli function, erroring code run conditionally can get borked: Returns: Note ?valid cli markup. Sprintf-style statements issue: Returns:","code":"rlang::abort(\"`save_pred` can only be used if the initial results saved predictions.\") cli::cli_abort(\"{.arg save_pred} can only be used if the initial results saved predictions.\") extra_grid_params <- glue::single_quote(extra_grid_params) extra_grid_params <- glue::glue_collapse(extra_grid_params, sep = \", \") msg <- glue::glue( \"The provided `grid` has the following parameter columns that have \", \"not been marked for tuning by `tune()`: {extra_grid_params}.\" ) rlang::abort(msg) cli::cli_abort( \"The provided {.arg grid} has parameter columns that have not been marked for tuning by {.fn tune}: {.val {extra_grid_params}}.\" ) rlang::abort( paste( \"Some model parameters require finalization but there are recipe\", \"parameters that require tuning. Please use \", \"`extract_parameter_set_dials()` to set parameter ranges \", \"manually and supply the output to the `param_info` argument.\" ) ) cli::cli_abort( c( \"Some model parameters require finalization but there are recipe parameters that require tuning.\", \"i\" = \"Please use {.fn extract_parameter_set_dials} to set parameter ranges manually and supply the output to the {.arg param_info} argument.\" ) ) msg <- \"Creating pre-processing data to finalize unknown parameter\" unk_names <- pset$id[unk] if (length(unk_names) == 1) { msg <- paste0(msg, \": \", unk_names) } else { msg <- paste0(msg, \"s: \", paste0(\"'\", unk_names, \"'\", collapse = \", \")) } rlang::inform(msg) cli::cli_inform( \"Creating pre-processing data to finalize unknown parameter{?s}: {.val {unk_names}}\" ) rlang::abort(paste0( \"The workflow has arguments to be tuned that are missing some \", \"parameter objects: \", paste0(\"'\", pset$id[!params], \"'\", collapse = \", \") )) cli::cli_abort( \"The workflow has arguments to be tuned that are missing some parameter objects: {.val {pset$id[!params]}}\" ) cls <- paste(cls, collapse = \" or \") if (!fine) { msg <- glue::glue(\"Argument '{deparse(cl$x)}' should be a {cls} or NULL\") if (!is.null(where)) { msg <- glue::glue(msg, \" in `{where}`\") } rlang::abort(msg) } cli::cli_abort( \"Argument {.code {deparse(cl$x)}} should be {?a/an} {.cls {cls}} or {.code NULL}{?in {where}}.\" ) abort(sprintf(\"No such '%s' function: `%s()`.\", package, name)) cli::cli_abort(\"No such {.pkg {package}} function: {.fn {name}}.\")"},{"path":"https://simonpcouch.github.io/pal/reference/pal_cli.html","id":"interfacing-manually-with-the-cli-pal","dir":"Reference","previous_headings":"","what":"Interfacing manually with the cli pal","title":"The cli pal — pal_cli","text":"Pals typically interfaced via pal addin. call cli pal directly, use: , submit query, run:","code":"pal_cli <- .init_pal(\"cli\") pal_cli$chat({expr})"},{"path":"https://simonpcouch.github.io/pal/reference/pal_options.html","id":null,"dir":"Reference","previous_headings":"","what":"Options used by the pal package — pal_options","title":"Options used by the pal package — pal_options","text":"pal package makes use three notable user-facing options: .pal_dir directory pal prompts live. See pal directory help-page information. .pal_fn .pal_args determine underlying LLM powering pal. See \"Choosing model\" section vignette(\"pal\", package = \"pal\") information.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_roxygen.html","id":null,"dir":"Reference","previous_headings":"","what":"The roxygen pal — pal_roxygen","title":"The roxygen pal — pal_roxygen","text":"roxygen pal prefixes selected function minimal roxygen2 documentation template. pal instructed generate subset complete documentation entry, completed developer: Stub @param descriptions based defaults inferred types Stub @returns entry describes return value well important errors warnings users might encounter.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_roxygen.html","id":"cost","dir":"Reference","previous_headings":"","what":"Cost","title":"The roxygen pal — pal_roxygen","text":"system prompt roxygen pal includes something like 1,000 tokens. Add 200 tokens code actually highlighted also sent model looking 1,200 input tokens. model returns maybe 10 15 lines relatively barebones royxgen documentation, call 200 output tokens per refactor. time writing (October 2024), default pal model Claude Sonnet 3.5 costs $3 per million input tokens $15 per million output tokens. , using default model, roxygen pals cost around $4 every 1,000 generated roxygen documentation entries. GPT-4o Mini, contrast, tend infer argument types correctly often often fails line-break properly, usually return syntactically valid documentation entries, cost around 20 cents per 1,000 generated roxygen documentation entries.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_roxygen.html","id":"gallery","dir":"Reference","previous_headings":"","what":"Gallery","title":"The roxygen pal — pal_roxygen","text":"section includes handful examples \"wild\" generated default model, Claude Sonnet 3.5. Documenting function factory: Returns: function may raise condition: Returns: function tricky indexing: Returns:","code":"deferred_method_transform <- function(lambda_expr, transformer, eval_env) { transformer <- enexpr(transformer) force(eval_env) unique_id <- new_id() env_bind_lazy( generators, !!unique_id := inject((!!transformer)(!!lambda_expr)), eval.env = eval_env ) inject( function(...) { (!!generators)[[!!unique_id]](self, private, ...) } ) } #' #' Transform a deferred method #' #' @description #' A short description... #' #' @param lambda_expr A lambda expression to transform. #' @param transformer A transformer function or expression. #' @param eval_env The environment in which to evaluate the transformer. #' #' @returns #' A function that, when called, will evaluate the transformed lambda expression. #' The returned function accepts `...` arguments which are passed to the generated function. #' #' @export set_default <- function(value, default, arg = caller_arg(value)) { if (is.null(value)) { if (!is_testing() || is_snapshot()) { cli::cli_inform(\"Using {.field {arg}} = {.val {default}}.\") } default } else { value } } #' Set default value #' #' @description #' A short description... #' #' @param value A value to check. #' @param default The default value to use if `value` is NULL. #' @param arg Optional. The name of the argument being set. #' #' @returns #' Returns `value` if it's not NULL, otherwise returns `default`. #' Informs the user when using the default value. #' #' @export find_index <- function(left, e_right) { if (!is.list(e_right) || !has_name(e_right, \"index\") || !is.numeric(e_right$index)) { return(NA) } matches_idx <- map_lgl(left, function(e_left) e_left$index == e_right$index) if (sum(matches_idx) != 1) { return(NA) } which(matches_idx)[[1]] } #' Find matching index #' #' @description #' A short description... #' #' @param left A list of elements, each expected to have an 'index' field. #' @param e_right A list with an 'index' field to search for in `left`. #' #' @returns #' The numeric index in `left` where `e_right$index` matches, or NA if not found #' or if inputs are invalid. Returns NA if multiple matches are found. #' #' @export"},{"path":"https://simonpcouch.github.io/pal/reference/pal_roxygen.html","id":"interfacing-manually-with-the-roxygen-pal","dir":"Reference","previous_headings":"","what":"Interfacing manually with the roxygen pal","title":"The roxygen pal — pal_roxygen","text":"Pals typically interfaced via pal addin. call roxygen pal directly, use: , submit query, run:","code":"pal_roxygen <- .init_pal(\"roxygen\") pal_roxygen$chat({expr})"},{"path":"https://simonpcouch.github.io/pal/reference/pal_testthat.html","id":null,"dir":"Reference","previous_headings":"","what":"The testthat pal — pal_testthat","title":"The testthat pal — pal_testthat","text":"testthat 3.0.0 released 2020, bringing numerous changes huge quality life improvements package developers also highly breaking changes. task converting legacy unit testing code testthat 3e quite pretty straightforward, components can quite tedious. testthat pal helps transition R package's unit tests third edition testthat, namely via: Converting snapshot tests Disentangling nested expectations Transitioning deprecated functions like expect_known_*()","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_testthat.html","id":"cost","dir":"Reference","previous_headings":"","what":"Cost","title":"The testthat pal — pal_testthat","text":"system prompt testthat pal includes something like 1,000 tokens. Add (generous) 100 tokens code actually highlighted also sent model looking 1,100 input tokens. model returns approximately number output tokens receives, call 100 output tokens per refactor. time writing (October 2024), default pal model Claude Sonnet 3.5 costs $3 per million input tokens $15 per million output tokens. , using default model, testthat pals cost around $4 every 1,000 refactored pieces code. GPT-4o Mini, contrast, tend get many pieces formatting right often fails line-break properly, usually return syntactically valid calls testthat functions, cost around 20 cents per 1,000 refactored pieces code.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_testthat.html","id":"gallery","dir":"Reference","previous_headings":"","what":"Gallery","title":"The testthat pal — pal_testthat","text":"section includes handful examples \"wild\" generated default model, Claude Sonnet 3.5. Testthat pals convert expect_error() (*_warning() *_message() *_condition()) calls use expect_snapshot() regular expression present: Returns: Note, well, intermediate results assigned object snapshotted contents previously tests. Another example multiple, redudant calls: Returns: know regexp = NA, means \"error\" (warning, message): Returns: also know adjust calls condition expectations class argument present (usually means one testing condition another package, able change wording message without consequence): Returns: converting non-erroring code, testthat pals assign intermediate results snapshot result warning: Returns: Nested expectations can generally disentangled without issue: Returns: also edits pal knows make third-edition code. example, transitions expect_snapshot_error() friends use expect_snapshot(error = TRUE) error context snapshotted addition message : Returns:","code":"expect_warning( check_ellipses(\"exponentiate\", \"tidy\", \"boop\", exponentiate = TRUE, quick = FALSE), \"\\\\`exponentiate\\\\` argument is not supported in the \\\\`tidy\\\\(\\\\)\\\\` method for \\\\`boop\\\\` objects\" ) expect_snapshot( .res <- check_ellipses( \"exponentiate\", \"tidy\", \"boop\", exponentiate = TRUE, quick = FALSE ) ) augment_error <- \"augment is only supported for fixest models estimated with feols, feglm, or femlm\" expect_error(augment(res_fenegbin, df), augment_error) expect_error(augment(res_feNmlm, df), augment_error) expect_error(augment(res_fepois, df), augment_error) expect_snapshot(error = TRUE, augment(res_fenegbin, df)) expect_snapshot(error = TRUE, augment(res_feNmlm, df)) expect_snapshot(error = TRUE, augment(res_fepois, df)) expect_error( p4_b <- check_parameters(w4, p4_a, data = mtcars), regex = NA ) expect_no_error(p4_b <- check_parameters(w4, p4_a, data = mtcars)) expect_error(tidy(pca, matrix = \"u\"), class = \"pca_error\") expect_error(tidy(pca, matrix = \"u\"), class = \"pca_error\") expect_warning( tidy(fit, robust = TRUE), '\"robust\" argument has been deprecated' ) expect_snapshot( .res <- tidy(fit, robust = TRUE) ) expect_equal( fit_resamples(decision_tree(cost_complexity = 1), bootstraps(mtcars)), expect_warning(tune_grid(decision_tree(cost_complexity = 1), bootstraps(mtcars))) ) expect_snapshot({ fit_resamples_result <- fit_resamples(decision_tree(cost_complexity = 1), bootstraps(mtcars)) tune_grid_result <- tune_grid(decision_tree(cost_complexity = 1), bootstraps(mtcars)) }) expect_equal(fit_resamples_result, tune_grid_result) expect_snapshot_error( fit_best(knn_pca_res, parameters = tibble(neighbors = 2)) ) expect_snapshot( error = TRUE, fit_best(knn_pca_res, parameters = tibble(neighbors = 2)) )"},{"path":"https://simonpcouch.github.io/pal/reference/pal_testthat.html","id":"interfacing-manually-with-the-testthat-pal","dir":"Reference","previous_headings":"","what":"Interfacing manually with the testthat pal","title":"The testthat pal — pal_testthat","text":"Pals typically interfaced via pal addin. call testthat pal directly, use: , submit query, run:","code":"pal_testthat <- .init_pal(\"testthat\") pal_testthat$chat({expr})"},{"path":"https://simonpcouch.github.io/pal/reference/prompt.html","id":null,"dir":"Reference","previous_headings":"","what":"Working with pal prompts — prompt","title":"Working with pal prompts — prompt","text":"pal package provides number tools working system prompts. System prompts instruct pals behave provide information live models' \"short-term memory.\" prompt_*() functions allow users conveniently create, edit, remove, prompts pal's \"prompt directory.\" prompt_new() creates new markdown file automatically create pal specified role, prompt, interface package load. Specify contents argument prefill contents markdown file computer web. prompt_edit() prompt_remove() open delete, respectively, file defines given role's system prompt. Load prompts create functions using directory_load() (automatically called package loads).","code":""},{"path":"https://simonpcouch.github.io/pal/reference/prompt.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Working with pal prompts — prompt","text":"","code":"prompt_new(role, interface, contents = NULL) prompt_remove(role) prompt_edit(role)"},{"path":"https://simonpcouch.github.io/pal/reference/prompt.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Working with pal prompts — prompt","text":"role single string giving descriptor pal's functionality. Cand contain letters numbers. interface One \"replace\", \"prefix\", \"suffix\", describing pal interact selection. example, cli pal \"replace\"s selection, roxygen pal \"prefixes\" selected code documentation. contents Optional. Path markdown file contents \"pre-fill\" file. Anything file ending .md .markdown can read readLines() fair game; local file, \"raw\" URL GitHub Gist file GitHub repository, etc.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/prompt.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Working with pal prompts — prompt","text":"prompt_*() function returns file path created, edited, removed filepath, invisibly.","code":""},{"path":[]},{"path":"https://simonpcouch.github.io/pal/reference/prompt.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Working with pal prompts — prompt","text":"","code":"if (FALSE) { # create a new pal with role `\"boop\"` that replaces the selected text: prompt_new(\"boop\") # after writing a prompt, register it with the pal package with: directory_load() # after closing the file, reopen with: prompt_edit(\"boop\") # remove the prompt (next time the package is loaded) with: prompt_remove(\"boop\") # pull prompts from files on local drives or the web with # `prompt_new(contents)`. for example, here is a GitHub Gist: # paste0( # \"https://gist.githubusercontent.com/simonpcouch/\", # \"daaa6c4155918d6f3efd6706d022e584/raw/ed1da68b3f38a25b58dd9fdc8b9c258d\", # \"58c9b4da/summarize-prefix.md\" # ) # # press \"Raw\" and then supply that URL as `contents` (you don't actually # have to use the paste0() to write out the URL--we're just keeping # the characters per line under 80): prompt_new( role = \"summarize\", interface = \"prefix\", contents = paste0( \"https://gist.githubusercontent.com/simonpcouch/\", \"daaa6c4155918d6f3efd6706d022e584/raw/ed1da68b3f38a25b58dd9fdc8b9c258d\", \"58c9b4da/summarize-prefix.md\" ) ) }"}] diff --git a/sitemap.xml b/sitemap.xml index 13bc2e0..0162cf7 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -16,6 +16,7 @@ https://simonpcouch.github.io/pal/reference/pal-package.html https://simonpcouch.github.io/pal/reference/pal_add_remove.html https://simonpcouch.github.io/pal/reference/pal_cli.html +https://simonpcouch.github.io/pal/reference/pal_options.html https://simonpcouch.github.io/pal/reference/pal_roxygen.html https://simonpcouch.github.io/pal/reference/pal_testthat.html https://simonpcouch.github.io/pal/reference/prompt.html