Skip to content

Commit

Permalink
Merge pull request #955 from mitchelloharawild/rng-attach
Browse files Browse the repository at this point in the history
Add withr preserve seed for .onAttach random tip
  • Loading branch information
robjhyndman committed Mar 13, 2024
2 parents d143826 + 910ddec commit e565f31
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Imports:
timeDate,
tseries,
urca,
withr,
zoo
Suggests:
forecTheta,
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# forecast (development version)
* Prevented RNG state changing when the package is attached (#954, #955).

# forecast 8.22.0
* hfitted now much faster for ARIMA models (danigiro, #949)
Expand Down
4 changes: 2 additions & 2 deletions R/attach.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.onAttach <- function(...) {
if (!interactive() || stats::runif(1) > 0.2) return()
if (!interactive() || withr::with_preserve_seed(stats::runif(1)) > 0.2) return()

tips <- c(
"Use suppressPackageStartupMessages() to eliminate package startup messages.",
Expand All @@ -9,7 +9,7 @@
"Want to stay up-to-date? Read the Hyndsight blog:\n https://robjhyndman.com/hyndsight/",
"Want to meet other forecasters? Join the International Institute of Forecasters:\n http://forecasters.org/"
)
tip <- sample(tips, 1)
tip <- withr::with_preserve_seed(sample(tips, 1))
msg <- paste("This is forecast", packageVersion("forecast"), "\n ", tip)
packageStartupMessage(msg)
}
Expand Down

0 comments on commit e565f31

Please sign in to comment.