r/rstats

ggsketch 2.0: hand-drawn ggplot2 geoms in pure R, now with drawing media
▲ 100 r/rstats

ggsketch 2.0: hand-drawn ggplot2 geoms in pure R, now with drawing media

https://i.redd.it/2zd8qeolt8bh1.gif

I posted v1.5 of ggsketch here a while back. Short version if you missed it: the sketchy hand-drawn look as real ggplot2 geoms - pure R, no JavaScript, no browser, clean PDF/SVG export, and all the wobble is seeded so plots stay reproducible.

2.0 ended up much bigger than I intended.

The main change is that lines now have a medium: pen, ink, brush, pencil, charcoal, chalk, marker, highlighter, crayon and a few others, 13 in all. Set it as a constant or map it with aes(medium = ) like anything else. Getting there meant making strokes variable-width, which grid won't do with a polyline, so each stroke is now a filled ribbon built around a re-roughened centreline. That's what lets ink pool at the end of a stroke and a brush swell through the middle.

I also fell down two rabbit holes. geom_sketch_engrave() shades by hatch density the way old engravings build shadow - the relief map in the images is just volcano. And there's a watercolor fill now: the violins in the images are the exact example from my last post with fill_style = "watercolor" added.

Beyond that: a pile of new chart types (waterfall, gantt, calendar heatmap, treemap, chord, radar, dendrogram, and more - the geom count is at 89, which is getting silly), repelled labels with hand-drawn leader lines, and animate_sketch(), which either "boils" a plot or draws it on stroke by stroke. Both GIFs attached are a single function call.

Same caveat as last time: I build this working with AI, with me driving the design and checking the behaviour.

The example from last post, one argument later:

library(ggplot2)
library(ggsketch)

ggplot(mpg, aes(class, hwy, fill = class)) +
  geom_sketch_violin(fill_style = "watercolor", show.legend = FALSE, seed = 1) +
  scale_fill_sketch() +
  labs(title = "Highway mpg by class") +
  theme_sketch(rough_frame = TRUE)

2.0.0 is submitted to CRAN. Until it lands:

pak::pak("orijitghosh/ggsketch")

Gallery of every geom: https://orijitghosh.github.io/ggsketch/articles/gallery.html

Docs: https://orijitghosh.github.io/ggsketch/

As before, feedback is very welcome - especially if the API feels off somewhere, or there's a medium or chart type you'd want. And if you make something with it, I'd love to see it.

reddit.com
u/bongbalok — 2 days ago
▲ 1 r/rstats

Help in formulating a course of Advance Statistics...

Hello everyone I have been assigned the work of formulating a proposal for a course on advance statistics , I was hoping if you all had any pointers in what should it cover and what not,

My objective is to make it in a manner that it doesn't get too tough and is rather accessible and easy to comprehend for people from all walks of life, but at the same time it also covers enough and should be made keeping in mind that it should make the learner more employable or more practically skilled than they were before it. Any help or advice would be greatly appreciated

reddit.com
u/harshdce — 1 day ago
▲ 181 r/rstats

LLM inference running in pure R

This was a fun one to get working. The package has to unpack the weights into a .rds file for each layer and has to load and unload the layers one-by-one for each token... surprisingly, none of the math is particularly complex or hard to do in R. Just a lot of delicate data and file handling.

all coded by hand, yada yada. It runs off an old 3GB open-source model from last year.

it's set up as a (minimal, undocumented) package in case you want to try it out yourself :)
not very useful, but perhaps interesting to look at or play around with the code.

repo: https://github.com/gbkorr/ggufr
big writeup: https://gbkorr.github.io/r-bites/ggufr/ggufr
A little dissatisfied with how the writeup turned out, but oh well... it's still got some pretty cool stuff in there.

u/mantisalt — 4 days ago
▲ 78 r/rstats

Arity: a fast R language server, formatter, and linter written in Rust

I'm happy to announce Arity, an all-in-one toolchain for R: a language server, formatter, and linter, built in Rust on top of a lossless, incremental parser (the same rust-analyzer architecture: rowan for syntax trees, salsa for incremental reparsing).

The goal is a fast, deterministic development experience that just works in your editor. Here are some of the the most important features:

  • Formatter: deterministic, rule-based formatting toward the tidyverse style guide. Output is idempotent and doesn't depend on your existing line breaks. roxygen comments are handled too.
  • Linter: a growing set of correctness, readability, and performance rules, many with safe autofixes.
  • Language server: formatting, diagnostics with quick fixes, hover, completion, signature help, go-to-definition and references, rename, document and workspace symbols, semantic tokens, folding, and call hierarchy.

Arity runs on Linux, macOS, and Windows (x86_64 and arm64). You can install it in several ways:

  • cargo install arity
  • npm install -g arity-cli (bundles a prebuilt binary, no Rust toolchain needed)
  • uv tool install arity or pipx install arity
  • VS Code and Open VSX extension (also works in Positron)
  • Prebuilt binaries from the releases page

Neovim, Helix, and other editors are covered in the editor setup guide.

Acknowledgements

Arity is heavily inspired by air (Posit's R formatter), and borrows tests, rules, and style from it, as well as from jarl. The big difference from air is that Arity also aims to be a full linter and language server, not just a formatter.

It's still early (v0.8.0), so expect rough edges and please file issues if you encounter them. The docs are at arity.cc and the source is at github.com/jolars/arity.

u/johlars — 4 days ago
▲ 23 r/rstats

R takes a lot of time to start when using Positron

Why that when I start Positron, It takes more than a minute for the R session to start. While when I open R from the windows terminal or the Rgui it starts instantly?

Windows 11, R 4.6.1, latest Positron version

reddit.com
u/emanresUweNyMsiT — 4 days ago
▲ 32 r/rstats+39 crossposts

Made a free iOS app to open and read raw Markdown (.md) files on iPhone/iPad — handy for peeking at Logseq pages outside the app

Logseq stores everything as plain .md files, but if you ever open one of those files directly on iOS (from Files, iCloud, Dropbox, a backup, etc.) you just get raw text. I built a small viewer to read them rendered on a phone.

Md Preview:

• Renders GitHub-Flavored Markdown — headings, tables, task lists, footnotes

• Code blocks with syntax highlighting, plus LaTeX math and Mermaid diagrams

• Opens .md / .markdown / .mdx / .rmd / .qmd from Files or the Share Sheet

• 100% on-device — no account, no uploads, no ads, no subscriptions

Free on the App Store: https://apps.apple.com/app/id6760341080

Details: https://markdown.cybergame.ai/

Not a Logseq replacement at all — just a quick way to read loose .md files when you're away from the desktop app. Curious how you all read your graph on the go.

u/Fujima4Kenji — 5 days ago
▲ 82 r/rstats

**glmbayes v 0.9.6 is now on CRAN: multi-response models, additional prior specifications, and companion vignettes based on Bayes Rules! book and the companion bayesrules package datasets**

Hi all, glmbayes v 0.9.6 just hit CRAN last week. For anyone not familiar: it's a package for Bayesian linear and generalized linear models that draws independent, identically distributed samples from the posterior (accept-reject sampling for log-concave likelihoods) instead of relying on MCMC — so no chains, no convergence diagnostics to babysit. Interface mirrors `lm()`/`glm()`. The package includes dNormal() priors for all families and additional priors for the gaussian() family.

A few highlights from 0.9.6:

**New conjugate GLM priors** – Closed-form IID sampling paths for intercept-only Poisson, Binomial, and Gamma models with identity links: Beta–Binomial via `dBeta()`/`rBeta_reg()`, and Gamma–Poisson / Gamma–Gamma via `dGamma(Inv_Dispersion = FALSE)`/`rGamma_Conjugate_reg()`. `Prior_Setup()` can now calibrate hyperparameters for these families directly.

**Multi-response `lmb()`** – `lmb()` now handles `cbind(y1, y2) ~ x`-style multivariate response formulas, fitting a separate Bayesian linear model per column and returning a named `mlmb` list (with its own summary/print/coef methods). Single-response calls are unchanged.

**Bayes Rules! companion vignettes** – If you've worked through *Bayes Rules!* (Johnson, Ott & Dogucu), there are now optional vignette appendices that reproduce several of the book's datasets and published posterior summaries using glmbayes' `lmb()`, `glmb()`, `Prior_Setup()`, and `dNormal()`. Chapter-02 has been expanded to cover Conjugate priors and now includes plots using its companion package. Some of the more advanced/later Vignette Chapters also used examples from Bayes Rules!

CRAN: https://cran.r-project.org/package=glmbayes

Happy to answer questions, especially if you're coming from a `bayesrules`/`rstanarm` workflow and are curious how the IID sampler compares.

u/Bucksswede — 5 days ago
▲ 15 r/rstats+1 crossposts

Very basic question: where does D3.js fit with R/Shiny?

i've been building some simple medical dashboards in shiny.... mostly for filtering data and making interactive plots. I’m not a web developer, but I’m trying to slowly understand how better data visualization tools work together

recently saw a developer influencer talking about D3.js, HTML, CSS, and JavaScript, and got me wondering bout it

guys who use Shiny: when does D3.js actually become useful?

is it mainly for making very custom visuals that normal R packages can’t handle well? Or is it usually too much work unless you are building a serious web app? not gonna replace my r workflow but i’m just wondering whether D3.js is useful

Would love to hear simple examples of when D3 was worth it, and when it was not.

reddit.com
u/Bad_Archer_69 — 5 days ago
▲ 50 r/rstats+1 crossposts

The 'Modified' Fisher Exact Test - R Package

Hi all.

For the past few months I've been working on the modifiedfisher R package. It's an R version of the SAS algorithm included in the van der Meulen EA, Raymond K, van der Meulen PJ (2021) paper (I am the latter author). The paper, and package, implements a non-conservative, size-α modified Fisher exact test for comparing two independent binomial proportions.

This modified test rejects at a borderline outcome if and only if its randomisation probability exceeds a single threshold, chosen in such a way to bring the actual size as close to α as possible. The p-value and confidence interval agree as they are both derived from this test.

GitHub and full docs: https://github.com/pvdmeulen/modifiedfisher

I was hoping folks in the biostats field are able try this out before I submit to CRAN in due course. I am an economist/econometrician so this is fairly out of my wheelhouse. Aware there's also plenty of debate re: the use of unconditional/conditional tests, but hopefully this is a useful addition to the toolbox available to (bio)statisticians, particularly in small samples when it is appropriate to condition on T. Even feedback on general R package etiquette and structure would be useful, of course.

---

On a more personal note - this is an important project to me, as my father (EA van der Meulen) passed away a few months after we published this paper. My contribution was mostly on the algorithm side, and the R package was always 'my' next step.

u/pvdmeulen — 6 days ago
▲ 10 r/rstats

Running furrr/future parallel workflows on Azure VM vs. dedicated workstation — anyone have experience with this?

My work laptop (Intel Ultra 7 268V, 32GB RAM) is hitting its ceiling running a furrr pipeline — RAM maxes out while CPU is only at ~50%, sometimes it crashes at the end. Scaling up soon so need a real solution.

Torn between two options:

  1. Azure VM (E16s_v5, 16 vCPU / 128GB RAM) — pay per hour, deallocate when done, data syncs via OneDrive. Worried about complicated initial setup and whether pick_workers() behaves sanely against availableCores() on a VM.
  2. Dedicated workstation (9950X, 64GB DDR5) — build here. Went AMD specifically because furrr uses a synchronization barrier and Intel's hybrid P/E core architecture creates straggler workers. 128 GB RAM would have been nice, but the prices are currently insane.

Leaning toward the desktop for now but the VM scales better as data size grows. Curious if anyone's running furrr workloads in either setup and what your worker count / RAM usage looks like in practice. If there are better alternatives, please share them as well.

reddit.com
u/fourcade23 — 6 days ago
▲ 36 r/rstats+1 crossposts

onet2r: archived O*NET releases, OEWS/PUMS weights, and reproducible occupation measures in R

I maintain onet2r, an R package for working with O*NET data, and just shipped a
larger update (the 0.4 line).

The problem it tries to handle: O*NET is useful but is not a clean longitudinal panel. The Web Services API serves the current release. Historical comparisons need the archived database files, O*NET-SOC taxonomy bridges, and some care about whether a changed value is a real update, a stale carryforward, a transition row, a suppressed estimate, or a taxonomy seam.

What it does:
- reads archived O*NET releases into one normalized panel
- keeps native 8-digit O*NET-SOC codes and derives 6-digit SOC codes for joins
- reconciles two releases and flags rows that are not safely comparable
- validates a user-supplied task or occupation measure against a pinned release
- rolls task scores up to occupations using O*NET task ratings
- builds OEWS or PUMS employment weight panels with coverage and provenance
- decomposes aggregate change into within, between, interaction, and unclassified

Docs with runnable examples: https://farach.github.io/onet2r/
GitHub: https://github.com/farach/onet2r
Blog: https://workforcefutures.net/blog/onet2r-release/

The hardest design question, and where I would value opinions: how much comparability checking should be automatic versus left visible for the analyst? Right now I lean toward visible, with explicit flags, because a clean-looking number hides too much. Curious whether people who use O*NET historically agree.
u/farach — 9 days ago
▲ 201 r/rstats+1 crossposts

ggwas — a ggplot2-native R package for GWAS visualization (17 plot types, journal themes, 9x faster than qqman)

I got tired of patching together qqman + ad hoc scripts for every GWAS paper, so I built ggwas — a single package covering the full visualization workflow.

Beyond standard Manhattan/QQ, it includes plots I couldn't find elsewhere: enrichment Manhattan with functional overlays, density-vs-signal comparison (to catch genotyping artifacts), multi-trait Manhattan with pleiotropy detection, PheWAS, colocalization, fine-mapping credible sets, and genetic correlation matrices.

It also supports broken y-axis for Manhattan plots with extreme p-values — a frequently requested feature missing from existing tools.

Everything returns a ggplot object so you can + theme_nature() or compose with patchwork. Smart downsampling handles biobank-scale data (tested on GIANT height GWAS, 1.37M variants in <1s).

GitHub: https://github.com/bczech/ggwas

Docs + gallery: https://bczech.github.io/ggwas/

Happy to hear what's missing or what could be improved.

u/bwczech — 12 days ago
▲ 50 r/rstats

R not runnin code and just repeating what i type in console?

so this may seem like a stupid question but i just decided to learn R so bear with me. but the things i type in the rscript window dont seem to run and instead repeat itself inn the console window. I took a break from learning for two days, it was working fine before but now this is happening. can anyone help me understand?

u/Senior_Tumbleweed320 — 10 days ago
▲ 8 r/rstats

Chi squared test or Fishers for large sample size but counts lower than 5

Hi everyone, more stats puzzles I can't quite figure out because of conflicting information I've read.

Essentially as the title says, I have a large sample size and I am creating 2x2 contigency tables where one cell often has counts <5 or even 0 sometimes. My understanding is that I be running Fishers on these tables right?

reddit.com
u/JillV09 — 9 days ago
▲ 45 r/rstats

Follow-up benchmark: where R data pipelines pay their cost: fread, readr, vroom, data.table and dplyr

I wrote a follow-up article after my previous post about benchmarking a Shiny dashboard pipeline for blog analytics.

The previous article was somewhat polarizing. Most feedback was positive, but some people disagreed with the benchmarking methodology. That criticism was useful, so I tried to make this new benchmark more transparent and reproducible.

The pipeline is still based on my real blog analytics use case:

  • read NGINX TSV logs
  • filter bot traffic
  • apply time-window filters
  • do ASN / Geo enrichment
  • compute read-time metrics

This time I benchmarked 6 pipeline configurations:

  • readr::read_tsv() + dplyr
  • vroom::vroom() + dplyr
  • fread() + dplyr
  • readr::read_tsv() + data.table
  • vroom::vroom() + data.table
  • fread() + data.table

The benchmark uses 20 generated log files, from 1× to 20× the original size, with increasing timestamp and IP cardinality instead of simply appending the same file repeatedly.

Methodology:

  • 20 log files, from ~557k rows to ~11.1M rows

  • 10 consecutive runs per file and per configuration (we will distinguish the cold-starts from the others runs)

  • execution time measured per pipeline step with proc.time(), so elapsed, user, and system time recorded

  • memory tracked with gc() counters: current/max NCells and VCells (more on that in the article)

A few things I found interesting:

  • fread + data.table is still the most predictable path when the pipeline eventually works on fully materialized data.

  • readr + dplyr is closer than I expected in several parts of the pipeline.

  • data.table becomes more clearly advantageous in grouped / index-like filtering steps.

  • vroom + dplyr is very interesting: it looks extremely cheap at ingestion because columns stay lazy / ALTREP-backed.

But vroom does not make parsing free; it moves the cost to later operations that force materialization.

Nevertheless, in this specific pipeline, that can still be a big memory win (and elapsed_time not dramatic), because the dataframe is filtered before all columns are fully materialized so later materialization happens on a smaller subset compared to the other configurations.

  • gc()-based memory results are useful, but they are not perfect per-operation allocation measurements because the R process is reused across reloads.

Article:

https://julienlargetpiet.tech/articles/where-r-data-pipelines-pay-their-cost-data-table-dplyr-fread-readr-and-vroom.html

I would be curious to hear how people here would improve the methodology further.

(PS: Thanks for the comments! It’s pretty late here, so I’m going to sleep now. I’ll come back and answer questions in around 8 hours.)

reddit.com
u/Medical-Common1034 — 12 days ago
▲ 13 r/rstats+1 crossposts

I built rpx and rrepo - a new package manager and registry.

I have spent a considerable amount of time debugging other package managers and the time has come to create my own!

Now I can tell you of the cool features I have like:

  • blazingly fast dependency resolution and installs
  • a pinned lockfile
  • optional system dependency management (with lockfile support!)
  • recorded R version
  • virtual environments
  • native support for private repositories

but let's be honest, that's the bare minimum.

My thesis is that all your issues with package installs are because of CRAN.

You see every package manager uses PACKAGES the index of the latest versions of all available packages and what dependencies they need. Whenever you install a package, R or any other package manager retrieves the index and checks what transitive dependencies you might need.

You might ask what would happen if the package you wanted said it required dplyr less than 1.0.0 because according to SemVer it contains a breaking change. Well now dependency resolution get's spotty. rv and uvr fail completely, renv falls back to crandb, an additional service most private repositories don't implement.

Thankfully you will never see this problem as no one in the R ecosystem actually sets upper bounds in their package dependencies. They all rely on CRAN testing the new package with all its dependencies. I don't think that's the right way to handle breaking changes, especially if you have private packages that don't get tested.

I made a complete solution to the problem.

rrepo.org hosts a public package repository mirroring CRAN in it's contents but with a completely revised api structure. It allows listing packages, and retrieving DESCRIPTION files directly. It also supports private repositories

rpx defaults to the rrepo CRAN mirror. It also set's version boundaries of current < x < next major by default so you don't have to think about it! For dependency resolution it uses pubgrub so the new but expected resolution failures always tell you exactly how to fix them. I also reluctantly support CRAN-like url's for compatibility purposes, though with limited usability due to its design.

I'd love to hear what the community thinks of my approach. Please try it and let me know how I can make it even better!

github.com
u/adam-smielewski — 12 days ago
▲ 14 r/rstats+2 crossposts

Hayashi – an open-source DSL for applied econometrics (with a 307-page book, free)

I've been building Hayashi, a domain-specific language for applied econometrics, for the past year. It's a solo project, open-source (GPL v3), written in Rust.

The goal is a language where econometric intent reads directly from the code — no boilerplate, no package hunting, no version conflicts. Something between Stata's expressiveness and a proper programming language.

What it covers so far:

OLS, IV/2SLS, panel data (FE/RE/FD), DiD, RDD, GMM, quantile regression, logit/probit, Poisson/NB, Tobit, survival analysis (Cox/KM), PSM, synthetic control, ARMA/ARIMA, VAR, cointegration/VECM, GARCH, ARDL/ECM, Kalman filter, SUR, Lasso/Ridge, bootstrap, PCA, structural breaks, regime switching, and more.

Book: a 307-page reference manual is available in both English and Portuguese (PT-BR), covering the full language and all estimators with worked examples.

GitHub: https://github.com/sheep-farm/hayashi

Still early — v0.2.4. I'm especially looking for people willing to test it on real datasets and report what breaks. The book has a whole section on this, but real-data testers are the biggest gap right now.

Happy to answer questions about design decisions, what's planned, or why I built this instead of just writing an R package.

One practical note: Hayashi ships as a single binary — no installation wizard, no external libraries, no dependency management. Just download and run. Works on Windows, macOS, and Linux. The only exception is ODBC connectivity, which requires the system ODBC driver if you need it.

u/UnlikelyFuel5610 — 9 days ago
▲ 1 r/rstats

Does anyone know if there's a complete instructor's solutions manual for Statistical Computing with R (2nd Edition)?

Hi everyone,

I'm currently using Statistical Computing with R (2nd Edition) and have been trying to find solutions to the exercises.

https://preview.redd.it/05yb6xp82h9h1.png?width=818&format=png&auto=webp&s=6bdac598040da3ca1b8a1a7507bb04bf3ecc51a2

I managed to find what appears to be an instructor's solutions manual online, but the exercise numbers and questions don't seem to match the ones in the 2nd edition textbook. My guess is that the manual might be for an earlier edition, or perhaps an incomplete version.

I'm wondering if a complete instructor's solutions manual exists for the 2nd edition, or if anyone knows where the exercise solutions can be found.

I've searched around quite a bit but haven't had much luck so far. If any former students, instructors, or anyone familiar with this book could point me in the right direction, I'd really appreciate it.

Thanks in advance!

reddit.com
u/SeafoodretailK1ng — 11 days ago
▲ 6 r/rstats

R shiny - version conflict with package in system library on shiny server

We have a shiny server where we can deploy our shiny apps, this has a system/default library path (/usr/lib64/R/library) which is only writable for the admins, not me.

I use my own library paths for the apps I make, setting them using .libPaths()

However, when accessing the shiny app through the browser it needs (and loads) the shiny package residing in the system path before getting to my .libPaths() method. This on it's turn loads rlang but the rlang version is too old for one of my packages.

So once my packages start loading (using the path I set using .libPAths()) I get an error:

Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
 namespace ‘rlang’ 1.1.2 is already loaded, but &gt;= 1.1.7 is required

Execution halted

I have tried reloading and also detaching (unloading) the old package, but this gives other issue due to the package being used by shiny (and others)

Error in detach(c("ellipsis", "lifecycle", "htmltools", "shiny"), unload = T) :
  invalid 'name' argument

Calls: &lt;Anonymous&gt; ... sourceUTF8 -&gt; eval -&gt; eval -&gt; ..stacktraceon.. -&gt; detach

Execution halted

Is there something I can do about this? Or does the admin really need to update the system wide packages.

Reason for using a library folder per shiny app is to prevent conflicts so I would really like to be able to somehow force it that way instead of needing to install/update system wide packages.

If I manually launch it from the terminal giving the .libPaths() command as an extra argument it seems to launch fine (can't access it through the browser though) but I can't do this when accessing it through the browser:

R -e ".libPaths('/srv/shiny-server/library/myapp/'); shiny::runApp('myapp')"

Any ideas?

reddit.com
u/dagrim1 — 12 days ago
▲ 5 r/rstats

Making Marriage-Specific Pedigrees in R

I'm using the Pedtools package in R to recreate pedigree charts from a set of handmade records for analysis and so I can generate chart images at different resolutions, colors, etc. I'm running into an issue where I want to make a pedigree with individuals who are married without kids and Pedtools locks out any individual that doesn't contribute to the family genetically.

I can see why this design choice makes sense for actual analysis of genetics and relatedness, but I've been specifically asked to illustrate the prevalence of a condition while including literally all members of the family where records are available, including those without kids.

Is there a different R package I should use for this task or is there a way to override the Pedtools plotting method that I missed?

reddit.com
u/Xenon_Chameleon — 11 days ago