Skip to content

Instantly share code, notes, and snippets.

@kmiddleton
kmiddleton / CLAUDE.md
Created October 8, 2025 12:50 — forked from sj-io/CLAUDE.md
Claude R Tidyverse Expert

Modern R Development Guide

This document captures current best practices for R development, emphasizing modern tidyverse patterns, performance, and style. Last updated: August 2025

Core Principles

  1. Use modern tidyverse patterns - Prioritize dplyr 1.1+ features, native pipe, and current APIs
  2. Profile before optimizing - Use profvis and bench to identify real bottlenecks
  3. Write readable code first - Optimize only when necessary and after profiling
  4. Follow tidyverse style guide - Consistent naming, spacing, and structure
#' Convert geomorph 3D array to edma_data class
#'
#' @param A 2D or 3D array of landmarks
#' @param name Character: Name for data set
#' @param IDs Vector of IDs
#'
#' @return Object of class "edma_data"
#' @export
#'
#' @examples
ssPlot <- function(X, Y, b, do.plot = TRUE, do.labels = TRUE){
n <- length(X)
pred <- (X * b + (mean(Y) - b * mean(X)))
SSy <- sum((Y - pred) ^ 2)
M <- tibble(X, Y, pred)
if (do.plot) {
p <- ggplot() +
geom_point(data = tibble(X = mean(X), Y = mean(Y)),
shade_normal <- function(q, tail = "both", mean = 0, sd = 1) {
require(tidyverse, quietly = TRUE)
require(cowplot)
crit <- qnorm(q, mean, sd)
M <- tibble(x = seq(-4, 4, length = 200),
y = dnorm(x))
p <- ggplot(M, aes(x, y)) +
geom_line() +
labs(x = "Value", y = "Relative Likelihood")
lower <- geom_ribbon(data = subset(M, x < crit),
library(tidyverse)
library(cowplot)
if (Sys.info()['sysname'] == "Darwin") {
suff <- ".pdf"
} else {
suff <- ".wmf"
}
base_size <- 36
@kmiddleton
kmiddleton / optimize_corMartins.R
Last active May 17, 2021 19:28
Manual optimization for corMartins()
library(ape)
library(nlme)
library(geiger)
set.seed(3879742)
tree <- sim.bdtree(b=1, d=0.2, stop=c("taxa", "time"), n=10, t=4, seed=0, extinct=TRUE)
plot(tree)
y <- sim.char(tree, 0.02, 1)[, , 1]