| Title: | R Bindings for FSRS Spaced Repetition Algorithm |
|---|---|
| Description: | R bindings for the fsrs-rs Rust library implementing the Free Spaced Repetition Scheduler (FSRS) algorithm. FSRS is a modern spaced repetition algorithm based on the DSR (Difficulty, Stability, Retrievability) model of memory. Includes parameter optimization to train custom parameters from your review history, achieving better scheduling accuracy than default parameters or traditional algorithms like SM-2. |
| Authors: | Christos Longros [aut, cre] |
| Maintainer: | Christos Longros <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.2 |
| Built: | 2026-05-20 10:05:57 UTC |
| Source: | https://github.com/open-spaced-repetition/r-fsrs |
R6 class representing a flashcard
new()
Create a new Card
Card$new(due = Sys.time())
dueInitial due date (default: now)
get_retrievability()
Get current retrievability
Card$get_retrievability(now = Sys.time())
nowReference time (default: Sys.time())
to_json()
Serialize card to JSON
Card$to_json()
deep_clone()
Clone the card
Card$deep_clone()
print()
Print card details
Card$print()
clone()
The objects of this class are cloneable with this method.
Card$clone(deep = FALSE)
deepWhether to make a deep clone.
Create Card from JSON
Card_from_json(json)Card_from_json(json)
json |
JSON string |
Card object
Converts an Anki review log (from ankiR or similar) to the format
required by fsrs_optimize.
fsrs_anki_to_reviews(revlog, min_reviews = 2)fsrs_anki_to_reviews(revlog, min_reviews = 2)
revlog |
A data.frame with Anki review data. Supports column names from
ankiR ( |
min_reviews |
Minimum number of reviews required per card (default 2). |
A data.frame with columns: card_id, rating, delta_t
## Not run: library(ankiR) revlog <- anki_revlog() reviews <- fsrs_anki_to_reviews(revlog, min_reviews = 3) result <- fsrs_optimize(reviews) ## End(Not run)## Not run: library(ankiR) revlog <- anki_revlog() reviews <- fsrs_anki_to_reviews(revlog, min_reviews = 3) result <- fsrs_optimize(reviews) ## End(Not run)
Evaluates how well FSRS parameters predict actual recall outcomes.
fsrs_evaluate(reviews, params = NULL)fsrs_evaluate(reviews, params = NULL)
reviews |
A data.frame with columns: card_id, rating, delta_t
(same format as |
params |
Optional vector of 21 FSRS parameters. Uses defaults if NULL. |
List with:
Log loss metric (may be NaN for some data)
Root mean square error of binned predictions (lower is better)
Logical indicating if evaluation succeeded
## Not run: # Compare default vs custom parameters default_metrics <- fsrs_evaluate(reviews, NULL) custom_metrics <- fsrs_evaluate(reviews, my_params) cat("Default RMSE:", default_metrics$rmse_bins, "\n") cat("Custom RMSE:", custom_metrics$rmse_bins, "\n") ## End(Not run)## Not run: # Compare default vs custom parameters default_metrics <- fsrs_evaluate(reviews, NULL) custom_metrics <- fsrs_evaluate(reviews, my_params) cat("Default RMSE:", default_metrics$rmse_bins, "\n") cat("Custom RMSE:", custom_metrics$rmse_bins, "\n") ## End(Not run)
Next review interval
fsrs_interval(stability, desired_retention = 0.9, params = NULL)fsrs_interval(stability, desired_retention = 0.9, params = NULL)
stability |
Memory stability in days (positive numeric). |
desired_retention |
Target recall probability, e.g. 0.9. |
params |
Optional vector of 21 FSRS parameters |
Recommended interval in days.
Replays a sequence of ratings and intervals to produce the
final FSRS memory state. When initial_stability and initial_difficulty
are both NULL, the first rating bootstraps the state as for a new card.
fsrs_memory_state_from_history( ratings, delta_ts, initial_stability = NULL, initial_difficulty = NULL, params = NULL )fsrs_memory_state_from_history( ratings, delta_ts, initial_stability = NULL, initial_difficulty = NULL, params = NULL )
ratings |
Integer vector of ratings (1=Again, 2=Hard, 3=Good, 4=Easy). |
delta_ts |
Integer vector of days elapsed before each rating, same
length as |
initial_stability |
Optional positive numeric scalar; starting
stability before the first rating. Must be supplied together with
|
initial_difficulty |
Optional numeric scalar between 1 and 10;
starting difficulty. Must be supplied together with |
params |
Optional numeric vector of length 21. |
Named list with stability and difficulty.
Migrate an SM-2 card to FSRS
fsrs_migrate_sm2(ease_factor, interval, sm2_retention = 0.9, params = NULL)fsrs_migrate_sm2(ease_factor, interval, sm2_retention = 0.9, params = NULL)
ease_factor |
SM-2 ease factor. |
interval |
Current SM-2 interval in days. |
sm2_retention |
Retention target used in SM-2 (default 0.9). |
params |
Optional vector of 21 FSRS parameters |
Named list with stability and difficulty.
Initial memory state for a new card
fsrs_new_card_state(rating, params = NULL)fsrs_new_card_state(rating, params = NULL)
rating |
Review rating: 1=Again, 2=Hard, 3=Good, 4=Easy. |
params |
Optional vector of 21 FSRS parameters |
Named list with stability and difficulty.
Memory state after a review
fsrs_next_memory_state( stability, difficulty, elapsed_days, rating, desired_retention = 0.9, params = NULL )fsrs_next_memory_state( stability, difficulty, elapsed_days, rating, desired_retention = 0.9, params = NULL )
stability |
Positive numeric. Current stability. |
difficulty |
Current difficulty (1-10). |
elapsed_days |
Days since last review. |
rating |
Review rating (1-4). |
desired_retention |
Target recall probability (default 0.9). |
params |
Optional vector of 21 FSRS parameters |
Named list with stability and difficulty.
Trains custom FSRS parameters from review history using machine learning. This typically improves prediction accuracy by 10-30% compared to defaults.
fsrs_optimize(reviews, enable_short_term = TRUE, verbose = TRUE)fsrs_optimize(reviews, enable_short_term = TRUE, verbose = TRUE)
reviews |
A data.frame with columns:
|
enable_short_term |
Whether to enable short-term memory modeling (default TRUE). |
verbose |
Print progress messages (default TRUE). |
List with:
Logical indicating if optimization succeeded
Numeric vector of 21 optimized parameters
Error message if failed, NULL otherwise
Number of cards used
Number of reviews used
## Not run: reviews <- data.frame( card_id = c(1, 1, 1, 2, 2, 2), rating = c(3, 3, 4, 2, 3, 3), delta_t = c(0, 1, 3, 0, 1, 5) ) result <- fsrs_optimize(reviews) if (result$success) { print(result$parameters) } ## End(Not run)## Not run: reviews <- data.frame( card_id = c(1, 1, 1, 2, 2, 2), rating = c(3, 3, 4, 2, 3, 3), delta_t = c(0, 1, 3, 0, 1, 5) ) result <- fsrs_optimize(reviews) if (result$success) { print(result$parameters) } ## End(Not run)
Returns the 21 default FSRS model weights.
fsrs_parameters()fsrs_parameters()
Numeric vector of length 21
Retrievability
fsrs_recall_probability(stability, elapsed_days)fsrs_recall_probability(stability, elapsed_days)
stability |
Memory stability in days (positive numeric). |
elapsed_days |
Days since last review. |
Recall probability between 0 and 1.
Vectorized retrievability
fsrs_recall_probability_vec(stability, elapsed_days)fsrs_recall_probability_vec(stability, elapsed_days)
stability |
Numeric vector of stability values. |
elapsed_days |
Numeric vector of elapsed days. |
Numeric vector of recall probabilities.
Simulate reviewing a card multiple times with given ratings
fsrs_simulate(ratings, params = NULL, desired_retention = 0.9)fsrs_simulate(ratings, params = NULL, desired_retention = 0.9)
ratings |
Vector of ratings for each review |
params |
Optional custom parameters |
desired_retention |
Target retention (default 0.9) |
data.frame with review history
Get the FSRS algorithm version used by this package
fsrs_version()fsrs_version()
Character string, e.g. "FSRS-6"
Rating values for card reviews
RatingRating
An object of class list of length 4.
R6 class representing a review log entry
new()
ReviewLog$new(rating, scheduled_days, elapsed_days, review_datetime, state)
to_json()
ReviewLog$to_json()
print()
ReviewLog$print()
clone()
The objects of this class are cloneable with this method.
ReviewLog$clone(deep = FALSE)
deepWhether to make a deep clone.
R6 class for scheduling card reviews using FSRS algorithm
new()
Create a new Scheduler
Scheduler$new( parameters = NULL, desired_retention = 0.9, maximum_interval = 36500L, enable_fuzzing = FALSE )
parametersOptional vector of 21 FSRS parameters. Uses defaults if NULL.
desired_retentionTarget retention rate (default 0.9)
maximum_intervalMaximum interval in days (default 36500 = 100 years)
enable_fuzzingWhether to add random fuzz to intervals (default FALSE)
preview_card()
Preview all four rating outcomes without modifying the card
Scheduler$preview_card(card, review_datetime = Sys.time())
cardCard object to preview
review_datetimeTime of review (default: now)
List with $again, $hard, $good, $easy outcomes
review_card()
Review a card and update its state
Scheduler$review_card(card, rating, review_datetime = Sys.time())
cardCard object to review (modified in place)
ratingRating: 1=Again, 2=Hard, 3=Good, 4=Easy (or use Rating$Good etc.)
review_datetimeTime of review (default: now)
List with $card (updated) and $review_log
get_card_retrievability()
Get current retrievability of a card
Scheduler$get_card_retrievability(card, now = Sys.time())
cardCard object
nowReference time (default: now)
to_json()
Serialize scheduler to JSON
Scheduler$to_json()
print()
Print scheduler details
Scheduler$print()
clone()
The objects of this class are cloneable with this method.
Scheduler$clone(deep = FALSE)
deepWhether to make a deep clone.
Create Scheduler from JSON
Scheduler_from_json(json)Scheduler_from_json(json)
json |
JSON string |
Scheduler object
Card states in the FSRS system
StateState
An object of class list of length 4.