Skip to content

[BUG] Handle random seed in R sessions where .Random.seed has not been set #258

@andrewherren

Description

@andrewherren

Description

The stochtree R package attempts to respect user-provided random seeds without modifying the global RNG state by caching the user's pre-existing .Random.seed and resetting the random number generator based on this seed after stochtree::bart() or stochtree::bcf() has run.

This is a problem if a user's session hasn't set .Random.seed (either by calling set.seed() or running a random number generation function like runif()).

Reproducing

  1. Save the following lines to an R script called example.R with
library(stochtree)
data(iris)
y <- iris$Sepal.Length
X <- iris[, c("Sepal.Width", "Petal.Length", "Petal.Width")]
bart_model <- bart(
  X_train = X,
  y_train = y,
  general_params = list(random_seed = 1234)
)
  1. Run at the command line
Rscript example.R

Expected behavior

This should not throw an error, bart() and bcf() should be robust to NULL-valued .Random.seed

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions