r/rstats • u/davisvaughan • 16d ago
rray: An array focused R package, inspired by NumPy
After SEVEN LONG YEARS I am thrilled to be able to say that rray is back on CRAN!
rray is an array focused R package (not data frames, for once!), extremely inspired by NumPy.
- Broadcasting
- Combining and splitting
- Flexible slicing
- Long vectors
- And so much more!
Broadcasting is the idea of applying the tidyverse recycling rules (length 1 recycles to any other length) to all axes of an array. It allows you to, say, add a 2x1 array to a 1x3 array in a meaningful way, with a 2x3 result. Read about it in our broadcasting vignette:
https://rray.r-lib.org/articles/broadcasting.html
rray has a very powerful (and fast!!) family of functions for combining and splitting arrays. Like everything else in the package, they support broadcasting, allowing you to combine in ways that rbind() and cbind() don't allow:
https://rray.r-lib.org/articles/toolkit.html#combining
rray has "long vector" support throughout the entire package, meaning that it works with arrays longer than ~2 billion elements with no issues.
Array terminology can be highly confusing, so rray documents precise definitions exactly once, and uses them throughout the package. rray is intentionally very consistent! Once you learn one concept it tends to translate well to the other functions in the package:
https://rray.r-lib.org/articles/terminology.html
rray is an interesting experiment for me. It was created almost entirely from my phone using Claude's and Codex's remote-control features. But it is not slop! I personally vouch for every line of code, and ruthlessly interrogated each one. As an example, here's the development of `rray_if_else()`. After planning and creating with Claude, I followed up with ~30 corrections to forge it into something I felt met my high quality bar (I am a maintainer of both dplyr and vctrs, so my standard is extremely high). The result is that rray's R and C code don't "feel" AI written to me.
https://github.com/r-lib/rray/pull/137
I've created a neat visualization that tracks rray's development over time. You can see every conversation, in full, paired with the PR and function it generated. It also shows approximate cost at API prices (though I used a subscription).
6
u/PandaJunk 16d ago
Oooo, this will be super useful (and fast!) for posterior manipulation in the Bayesian world
6
u/A_random_otter 16d ago edited 14d ago
Just had a look at your pinned repos...
No worries, I don't think you are a person who produces slop :)
Regarding rray: I am not super sure what I would need it for yet but it looks cool
1
u/simonpcouch 16d ago
Woah, that visualization is super cool! Neat to show all of the changes that did not result in a new exported function. :)
1
u/OutdoorSportBoy 15d ago
Great work!
1
u/Hadamard1854 14d ago
Always been a fan.
1
u/josiah-rs 13d ago
I love this! I wanted to used rray back in 2018, but alas!!
Any chance that you’d be able to support _sparse_ arrays? Ideally, I’d like to be able to rewrite spdep’s listw object which is a list with two fields:
- neighbors
- weights
Former are sparse matrix index and the weights are the values.
1
u/sylfy 12d ago
I’m curious - why the inspiration from NumPy, rather than a more general tensor-handling library like Jax?