diff --git a/authors.html b/authors.html index 137ed00..986bcb3 100644 --- a/authors.html +++ b/authors.html @@ -43,11 +43,11 @@

Citation

Source: DESCRIPTION

Couch S (2024). -pal: LLM-driven coding assistants. +pal: LLM assistants for R. R package version 0.0.1, https://simonpcouch.github.io/pal/, https://github.com/simonpcouch/pal.

@Manual{,
-  title = {pal: LLM-driven coding assistants},
+  title = {pal: LLM assistants for R},
   author = {Simon Couch},
   year = {2024},
   note = {R package version 0.0.1, https://simonpcouch.github.io/pal/},
diff --git a/index.html b/index.html
index c89b28f..e3a3576 100644
--- a/index.html
+++ b/index.html
@@ -5,14 +5,14 @@
 
 
 
-LLM-driven coding assistants • pal
+LLM assistants for R • pal
 
 
 
 
-
-
-
+
+
+
 
 
 
diff --git a/pkgdown.yml b/pkgdown.yml
index e2297c8..25a0c1d 100644
--- a/pkgdown.yml
+++ b/pkgdown.yml
@@ -2,7 +2,7 @@ pandoc: 3.1.11
 pkgdown: 2.1.1
 pkgdown_sha: ~
 articles: {}
-last_built: 2024-10-11T13:56Z
+last_built: 2024-10-11T14:20Z
 urls:
   reference: https://simonpcouch.github.io/pal/reference
   article: https://simonpcouch.github.io/pal/articles
diff --git a/reference/pal-package.html b/reference/pal-package.html
index a73d963..2d1c2d4 100644
--- a/reference/pal-package.html
+++ b/reference/pal-package.html
@@ -1,7 +1,7 @@
 
-pal: LLM-driven coding assistants — pal-package • pal
+pal: LLM assistants for R — pal-package • pal
     Skip to contents
 
 
@@ -28,14 +28,14 @@
 

-

LLM-driven coding assistants.

+

Pals are persistent, ergonomic LLM assistants designed to help you complete repetitive, hard-to-automate tasks quickly. After selecting some code, press the keyboard shortcut you've chosen to trigger the pal addin, select a pal, and watch your code be rewritten. While a number of pals for R package development ship with the package, users can create a suite of custom pals with only a directory of markdown files.

diff --git a/search.json b/search.json index 3e3c37e..8800dee 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/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-driven coding assistants. R package version 0.0.1, https://simonpcouch.github.io/pal/, https://github.com/simonpcouch/pal.","code":"@Manual{, title = {pal: LLM-driven coding assistants}, author = {Simon Couch}, year = {2024}, note = {R package version 0.0.1, 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-driven coding assistants","title":"LLM-driven coding assistants","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. Much documentation package aspirational interface likely change rapidly. ## Installation can install pal like : , ensure ANTHROPIC_API_KEY set .Renviron—see usethis::edit_r_environ() information. ’d like use LLM Anthropic’s Claude 3.5 Sonnet—like OpenAI’s ChatGPT—power pal, see ?pal() information set default metadata model.","code":"pak::pak(\"simonpcouch/pal\")"},{"path":"https://simonpcouch.github.io/pal/index.html","id":"example","dir":"","previous_headings":"","what":"Example","title":"LLM-driven coding assistants","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.","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-driven coding assistants","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/pal-package.html","id":null,"dir":"Reference","previous_headings":"","what":"pal: LLM-driven coding assistants — pal-package","title":"pal: LLM-driven coding assistants — pal-package","text":"LLM-driven coding assistants.","code":""},{"path":[]},{"path":"https://simonpcouch.github.io/pal/reference/pal-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"pal: LLM-driven coding assistants — pal-package","text":"Maintainer: Simon Couch simon.couch@posit.co (ORCID)","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a pal — pal","title":"Create a pal — pal","text":"Pals persistent, ergonomic LLM assistants designed help complete repetitive, hard--automate tasks quickly. selecting code, press keyboard shortcut chosen trigger pal addin (suggest Ctrl+Cmd+P), select pal, watch code rewritten. Users typically need call function. pal addin create needed pals --fly.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a pal — pal","text":"","code":"pal( role = NULL, fn = getOption(\".pal_fn\", default = \"chat_claude\"), ..., .ns = \"elmer\" )"},{"path":"https://simonpcouch.github.io/pal/reference/pal.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a pal — 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/pal.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create a pal — 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/pal.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a pal — pal","text":"","code":"if (FALSE) { # to create a chat with claude: pal() # or with OpenAI's 4o-mini: 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_add_remove.html","id":null,"dir":"Reference","previous_headings":"","what":"Creating custom pals — pal_add_remove","title":"Creating custom pals — pal_add_remove","text":"Users can create custom pals using pal_add() function; passing function role prompt, pal available command palette.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Creating custom 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":"Creating custom pals — pal_add_remove","text":"role single string giving pal() role. prompt file path markdown file giving system prompt output elmer::interpolate(). 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":"Creating custom pals — pal_add_remove","text":"NULL, invisibly. Called side effect: pal role role registered pal package.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Creating custom pals — pal_add_remove","text":"pal_add() register add-coming pal package —, custom pals deleted pal package reinstalled. Include pal_add() code .Rprofile make pal extension package using pal_add(package = TRUE) create persistent custom pals.","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 <- 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 <- 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 <- pal(\"testthat\") pal_testthat$chat({expr})"}] +[{"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/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.1, 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.1, 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. Much documentation package aspirational interface likely change rapidly. ## Installation can install pal like : , ensure ANTHROPIC_API_KEY set .Renviron—see usethis::edit_r_environ() information. ’d like use LLM Anthropic’s Claude 3.5 Sonnet—like OpenAI’s ChatGPT—power pal, see ?pal() information set default metadata model.","code":"pak::pak(\"simonpcouch/pal\")"},{"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.","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/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.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a pal — pal","title":"Create a pal — pal","text":"Pals persistent, ergonomic LLM assistants designed help complete repetitive, hard--automate tasks quickly. selecting code, press keyboard shortcut chosen trigger pal addin (suggest Ctrl+Cmd+P), select pal, watch code rewritten. Users typically need call function. pal addin create needed pals --fly.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a pal — pal","text":"","code":"pal( role = NULL, fn = getOption(\".pal_fn\", default = \"chat_claude\"), ..., .ns = \"elmer\" )"},{"path":"https://simonpcouch.github.io/pal/reference/pal.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a pal — 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/pal.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create a pal — 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/pal.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a pal — pal","text":"","code":"if (FALSE) { # to create a chat with claude: pal() # or with OpenAI's 4o-mini: 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_add_remove.html","id":null,"dir":"Reference","previous_headings":"","what":"Creating custom pals — pal_add_remove","title":"Creating custom pals — pal_add_remove","text":"Users can create custom pals using pal_add() function; passing function role prompt, pal available command palette.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Creating custom 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":"Creating custom pals — pal_add_remove","text":"role single string giving pal() role. prompt file path markdown file giving system prompt output elmer::interpolate(). 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":"Creating custom pals — pal_add_remove","text":"NULL, invisibly. Called side effect: pal role role registered pal package.","code":""},{"path":"https://simonpcouch.github.io/pal/reference/pal_add_remove.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Creating custom pals — pal_add_remove","text":"pal_add() register add-coming pal package —, custom pals deleted pal package reinstalled. Include pal_add() code .Rprofile make pal extension package using pal_add(package = TRUE) create persistent custom pals.","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 <- 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 <- 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 <- pal(\"testthat\") pal_testthat$chat({expr})"}]