View source: R/interactive_programming.R
try.seed | R Documentation |
This function picks a random seed, announces what that seed is, and then uses it to
evaluate an expression. For example, if you are creating a network graph whose layout
is calculated from randomly-chosen starting positions, try.seed()
lets you run that
plotting function over and over with a new seed each time, until you find a layout that
you would like to keep.
try.seed(expr, seed = NULL)
expr |
(Expression) An expression. |
seed |
(Integer or |
This function will throw an error if you try to generate a new seed non-interactively
(e.g. in an Rmarkdown document that is being knitted, or an R script that is being
executed from the command line). This is because try.seed()
changes the random seed,
and that could affect the rest of your script in ways that you don't want. It is
allowed to run non-interactively if you set the seed
argument to a non-NULL
number.
When you find a seed that you want to keep, you should copy it from the console and
provide it as the seed
argument.
The evaluated expr
.
Desi Quintans (http://www.desiquintans.com)
## Not run:
try.seed(runif(5))
## End(Not run)
#> Seed is: 1605125467
#> [1] 0.2582169 0.9739978 0.4126912 0.1326866 0.1336819
#>
## Not run:
try.seed(runif(5),
seed = 1605125467) # The announced seed
## End(Not run)
#> [1] 0.2582169 0.9739978 0.4126912 0.1326866 0.1336819
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.