I’ve just released fsrsr, an R package that provides bindings to fsrs-rs, the Rust implementation of the Free Spaced Repetition Scheduler (FSRS) algorithm. This means you can now use the state-of-the-art spaced repetition algorithm directly in R without the maintenance burden of a native implementation.
What is FSRS?
FSRS is a modern spaced repetition algorithm that outperforms traditional algorithms like SM-2 (used in Anki’s default scheduler). It uses a model based on the DSR (Difficulty, Stability, Retrievability) framework to predict memory states and optimize review intervals for long-term retention.
Why Bindings Instead of Native R?
Writing and maintaining a native R implementation of FSRS would be challenging:
- The algorithm involves complex mathematical models that evolve with research
- Performance matters when scheduling thousands of cards
- Keeping pace with upstream changes requires ongoing effort
By using extendr to create Rust bindings, we get:
- Automatic updates: Just bump the fsrs-rs version to get algorithm improvements
- Native performance: Rust’s speed with R’s convenience
- Battle-tested code: The same implementation used by Anki and other major apps
Installation
You’ll need Rust installed (rustup.rs), then:
remotes::install_github("chrislongros/fsrsr")
Basic Usage
Here’s a simple example showing the core workflow:
library(fsrsr)
# Initialize a new card with a "Good" rating (3)
state <- fsrs_initial_state(3)
# $stability: 3.17
# $difficulty: 5.28
# After reviewing 3 days later with "Good" rating
new_state <- fsrs_next_state(
stability = state$stability,
difficulty = state$difficulty,
elapsed_days = 3,
rating = 3
)
# Calculate next interval for 90% target retention
interval <- fsrs_next_interval(new_state$stability, 0.9)
# Returns: days until next review
# Check recall probability after 5 days
prob <- fsrs_retrievability(new_state$stability, 5)
# Returns: 0.946 (94.6% chance of recall)
Available Functions
| Function | Description |
|---|---|
fsrs_default_parameters() | Get the 21 default FSRS parameters |
fsrs_initial_state(rating) | Initialize memory state for a new card |
fsrs_next_state(S, D, days, rating) | Calculate next memory state after review |
fsrs_next_interval(S, retention) | Get optimal interval for target retention |
fsrs_retrievability(S, days) | Calculate probability of recall |
Ratings follow Anki’s convention: 1 = Again, 2 = Hard, 3 = Good, 4 = Easy.
Use Cases
- Research: Analyze spaced repetition data using R’s statistical tools
- Custom SRS apps: Build R Shiny applications with proper scheduling
- Simulation: Model learning outcomes under different review strategies
- Data analysis: Process Anki export data with accurate FSRS calculations
Technical Details
The package uses extendr to generate R bindings from Rust code. The actual FSRS calculations happen in Rust via the fsrs-rs library (v2.0.4), with results passed back to R as native types.
Source code: github.com/chrislongros/fsrsr




