Skip to content

Instantly share code, notes, and snippets.

View simonpcouch's full-sized avatar

Simon P. Couch simonpcouch

View GitHub Profile
@simonpcouch
simonpcouch / flight_query.md
Created May 22, 2025 13:15
Example CRAN package search
> client <- btw_client()
Using model = "claude-3-7-sonnet-latest".
> btw_app(client = client)
╔═══════════════════════════╗
║ Entering interactive chat ║
║ Press Ctrl+C to quit.     ║
╚═══════════════════════════╝

> client
@simonpcouch
simonpcouch / blog_post_prompt.md
Created May 21, 2025 14:10
Model prompt for a blog post on LLM eval

Here are three quarto source files for blog posts about new model releases. A new release of Gemini 2.5 Pro Flash just came out. I'd like to compare: Gemini 2.5 Pro Flash as the reference model, GPT o4-mini, Gemini 2.0 Flash, Gemini 2.5 Pro, GPT 4.1-nano, Claude Sonnet 3.7.

Gemini 2.5 Pro Flash is a "small"er model, which makes it like 2.0 Flash. It's also a thinking model, which makes it like o4-mini. o4-mini, being both cheap and thinking, is probably the closest analogue.

Try to write the source code implementing the eval exactly as I would. As with the o3 and o4-mini post, don't give so much explanation on how the vitals package works / what's happening under the hood. When writing the code, do it exactly as you'd imagine I would; just pattern match what's already there and don't include new code comments. When writing the exposition, be relatively terse and grounded; err on the side of writing too little rather than too much.

The "new Gemini 2.5 Pro update" is the newest blog post—refer to that most c

@simonpcouch
simonpcouch / mcp_client_demo.R
Created May 20, 2025 14:44
A demo implementation of the MCP client protocol in R
# an example server: acquaint's MCP server for R sessions
r_process <- callr::r_bg(
function() acquaint::mcp_server(),
stdout = "|",
stdin = "|"
)
Sys.sleep(1)
log_cat_client <- function(x, append = TRUE) {

Smoke test for parallelism in stacks' member fitting re: tidymodels/stacks#234.

With CRAN, sequential

# pak::pak("stacks")
library(stacks)

reg_st <- 
  stacks() %>%
@simonpcouch
simonpcouch / unpipe-replace.md
Created April 22, 2025 15:50
Chore helper prompt to remove pipes from code

Removing pipes from code

You are a terse assistant designed to help R coders transform their piped code (using either %>% or |>) into equivalent code without pipes. Respond with only the R code without pipes, no backticks or newlines around the response, though feel free to intersperse newlines within the code as needed, per tidy style.

  • Replace all instances of code that use the pipe operators %>% or |> with equivalent code that doesn't use pipes.
  • Each pipe step should become a separate line of code, where the result of each operation is assigned back to the same variable.
  • Maintain variable names from the original code. Use the same name for intermediate variables as you would for the result; don't create new intermediate variables in the process.
  • Ensure that the non-piped code is functionally identical to the piped code.
  • For dataframe subsetting using pipes (e.g., df %>% .$column), replace with standard R syntax like df$column.
  • Keep code comments on the same line as in the origi
@simonpcouch
simonpcouch / CLAUDE.md
Created March 26, 2025 15:44
An example `CLAUDE.md` prompt for R package development

You are situated inside of an R package source directory. The subdirectory R/ contains source files. The subdirectory tests/testthat/ contains corresponding tests. e.g. R/task.R is tested primarily in tests/testthat/test-task.R.

Do not add new code comments, and only remove existing code comments if the comment isn't relevant anymore.

The package has not yet been published and does not have any users; remove functionality outright when it's no longer needed rather than beginning a deprecation process. No need to worry about breaking changes.

When testing code that raises a message, warning, or error, use expect_snapshot() (possibly with error = TRUE) instead of expect_message() or otherwise.

When you're running package tests, use devtools::load_all(); testthat::test_file("tests/testthat/path-to-file.R"). If you encounter namespacing issues, don't delete tests that otherwise should work, and instead ask me what to do.

@simonpcouch
simonpcouch / databot_predictive_modeling.md
Created February 3, 2025 16:02
Prompt for predictive modeling with databot

When asked to build a machine learning model, use the tidymodels framework to do so. Rather than generating code to preprocess, fit, and evaluate models all at once, carry out the analysis step-by-step:

  1. Data splitting with rsample. Split into training and testing, and then split the training data into resamples. Do not touch the testing data until the very end of the analysis.
  2. Feature engineering with recipes. After preprocessing, stop generating and ask for user input. At this point, you can also ask for thoughts on what type of model the user would like to try.
  3. Resampling models with parsnip and tune. Based on the user's suggestions, decide on a parsnip model and tune important parameters across resamples using tune_grid().
    • Let tidymodels use its default performance metrics and parameter grids and check out its results with collect_metrics() and autoplot()—do not generate a custom grid in the first tune_grid() call.
    • Evaluate against resamples sequentially unless the user
@simonpcouch
simonpcouch / news-replace.md
Created January 24, 2025 19:47
A pal prompt for reformatting the R `NEWS.md` file (adapted from a CoT prompt from Hadley Wickham)

Polishing NEWS changelogs

You are a terse assistant designed to help R developers polish NEWS entries ahead of package releases. You will be supplied a changelog that's ordered reverse chronologically with little structure and possibly some formatting inconsistencies. Respond with only the properly structured markdown NEWS entries, no backticks or newlines around the response.

Your response should follow the following rules:

  • Bullets are group into to sections "Lifecycle changes" (i.e. changes to deprecated, defunct, and experimental), "New features" and "Bug fixes and minor improvements". Use sentence case for headings.

  • Within each section, the bullets should be alphabetized based on the first function name. If there's no function in the bullet, put it at the top of the list.

A log of a problematic run of a prefixing (roxygen) pal in Positron using these changes. Search for the first instance of key_get()modifyRange() attempts to add a "#' @" in its sixth line, but the rstudioapi::getActiveDocumentContext() call immediately after it doesn't find it (and instead finds the line that follows what should be there) and instead picks up key_get <- ..., which is erroneously replaced in the next iteration.

io$last_run

$before
$before$row_start_end
[1] 1 1

$before$before

min_grid() with submodels and postprocessors

library(tidymodels)
library(tailor)

Consider the following regular grid: