Attach a seed to one expression at the end of a pipeline, as in sample(x, 5) |> set_seed(123), or set it alone like Stata's set seed 123 with
set_seed(123).
Value
The expression's result, preserving its visibility. Used alone,
set_seed() returns NULL invisibly.
Details
Calls set.seed() before evaluating x once. The global random-number state
is changed and is not restored, including when x fails. Subsequent random
draws continue from the state left by x.
With only one argument, that argument is the seed and must be a single finite number. A pipeline that forgets the seed therefore errors, unless its result happens to be a single number, which is then used as the seed.