Skip to content

Commit

Permalink
Add set.seed() before runif(), rnorm(), and rpois() (#4844)
Browse files Browse the repository at this point in the history
  • Loading branch information
yutannihilation committed May 21, 2022
1 parent 68987fb commit 411f17b
Show file tree
Hide file tree
Showing 41 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/aes-colour-fill-alpha.r
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#'
#' # For large datasets with overplotting the alpha
#' # aesthetic will make the points more transparent.
#' set.seed(1)
#' df <- data.frame(x = rnorm(5000), y = rnorm(5000))
#' p <- ggplot(df, aes(x,y))
#' p + geom_point()
Expand Down
1 change: 1 addition & 0 deletions R/aes-position.r
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#'
#' # You can also use geom_segment() to recreate plot(type = "h")
#' # from base R:
#' set.seed(1)
#' counts <- as.data.frame(table(x = rpois(100, 5)))
#' counts$x <- as.numeric(as.character(counts$x))
#' with(counts, plot(x, Freq, type = "h", lwd = 10))
Expand Down
1 change: 1 addition & 0 deletions R/coord-transform.r
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#' geom_smooth(method = "lm")
#'
#' # Also works with discrete scales
#' set.seed(1)
#' df <- data.frame(a = abs(rnorm(26)),letters)
#' plot <- ggplot(df,aes(a,letters)) + geom_point()
#'
Expand Down
1 change: 1 addition & 0 deletions R/geom-boxplot.r
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#' \donttest{
#' # It's possible to draw a boxplot with your own computations if you
#' # use stat = "identity":
#' set.seed(1)
#' y <- rnorm(100)
#' df <- data.frame(
#' x = 1,
Expand Down
1 change: 1 addition & 0 deletions R/geom-point.r
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#'
#' # geom_point warns when missing values have been dropped from the data set
#' # and not plotted, you can turn this off by setting na.rm = TRUE
#' set.seed(1)
#' mtcars2 <- transform(mtcars, mpg = ifelse(runif(32) < 0.2, NA, mpg))
#' ggplot(mtcars2, aes(wt, mpg)) +
#' geom_point()
Expand Down
1 change: 1 addition & 0 deletions R/geom-polygon.r
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#' # Which seems like a lot of work, but then it's easy to add on
#' # other features in this coordinate system, e.g.:
#'
#' set.seed(1)
#' stream <- data.frame(
#' x = cumsum(runif(50, max = 0.1)),
#' y = cumsum(runif(50,max = 0.1))
Expand Down
1 change: 1 addition & 0 deletions R/geom-segment.r
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#' xlim(0.5, 2)
#'
#' # You can also use geom_segment to recreate plot(type = "h") :
#' set.seed(1)
#' counts <- as.data.frame(table(x = rpois(100,5)))
#' counts$x <- as.numeric(as.character(counts$x))
#' with(counts, plot(x, Freq, type = "h", lwd = 10))
Expand Down
2 changes: 2 additions & 0 deletions R/geom-spoke.r
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#' @export
#' @examples
#' df <- expand.grid(x = 1:10, y=1:10)
#'
#' set.seed(1)
#' df$angle <- runif(100, 0, 2*pi)
#' df$speed <- runif(100, 0, sqrt(0.1 * df$x))
#'
Expand Down
1 change: 1 addition & 0 deletions R/geom-tile.r
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#' \donttest{
#' # Justification controls where the cells are anchored
#' df <- expand.grid(x = 0:5, y = 0:5)
#' set.seed(1)
#' df$z <- runif(nrow(df))
#' # default is compatible with geom_tile()
#' ggplot(df, aes(x, y, fill = z)) +
Expand Down
1 change: 1 addition & 0 deletions R/limits.r
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#' # There are two ways of setting the axis limits: with limits or
#' # with coordinate systems. They work in two rather different ways.
#'
#' set.seed(1)
#' last_month <- Sys.Date() - 0:59
#' df <- data.frame(
#' date = last_month,
Expand Down
1 change: 1 addition & 0 deletions R/plot.r
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#' @examples
#' # Generate some sample data, then compute mean and standard deviation
#' # in each group
#' set.seed(1)
#' df <- data.frame(
#' gp = factor(rep(letters[1:3], each = 10)),
#' y = rnorm(30)
Expand Down
1 change: 1 addition & 0 deletions R/position-stack.r
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#' geom_histogram(binwidth = 500, position = "fill")
#'
#' # Stacking is also useful for time series
#' set.seed(1)
#' series <- data.frame(
#' time = c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4)),
#' type = rep(c('a', 'b', 'c', 'd'), 4),
Expand Down
1 change: 1 addition & 0 deletions R/quick-plot.r
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#' qplot(mpg, wt, data = mtcars, facets = vs ~ am)
#'
#' \donttest{
#' set.seed(1)
#' qplot(1:10, rnorm(10), colour = runif(10))
#' qplot(1:10, letters[1:10])
#' mod <- lm(mpg ~ wt, data = mtcars)
Expand Down
1 change: 1 addition & 0 deletions R/scale-continuous.r
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#'
#' # Typically you'll pass a function to the `labels` argument.
#' # Some common formats are built into the scales package:
#' set.seed(1)
#' df <- data.frame(
#' x = rnorm(10) * 100000,
#' y = seq(0, 1, length.out = 10)
Expand Down
1 change: 1 addition & 0 deletions R/scale-date.r
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#' @seealso [sec_axis()] for how to specify secondary axes
#' @examples
#' last_month <- Sys.Date() - 0:29
#' set.seed(1)
#' df <- data.frame(
#' date = last_month,
#' price = runif(30)
Expand Down
1 change: 1 addition & 0 deletions R/scale-gradient.r
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#' @rdname scale_gradient
#' @export
#' @examples
#' set.seed(1)
#' df <- data.frame(
#' x = runif(100),
#' y = runif(100),
Expand Down
1 change: 1 addition & 0 deletions R/scale-steps.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#' @family colour scales
#' @export
#' @examples
#' set.seed(1)
#' df <- data.frame(
#' x = runif(100),
#' y = runif(100),
Expand Down
1 change: 1 addition & 0 deletions R/stat-ecdf.r
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#' }
#' @export
#' @examples
#' set.seed(1)
#' df <- data.frame(
#' x = c(rnorm(100, 0, 3), rnorm(100, 0, 10)),
#' g = gl(2, 100)
Expand Down
2 changes: 2 additions & 0 deletions R/stat-summary.r
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ summarise_by_x <- function(data, summary, ...) {
#' @name hmisc
#' @examples
#' if (requireNamespace("Hmisc", quietly = TRUE)) {
#' set.seed(1)
#' x <- rnorm(100)
#' mean_cl_boot(x)
#' mean_cl_normal(x)
Expand Down Expand Up @@ -285,6 +286,7 @@ median_hilow <- wrap_hmisc("smedian.hilow")
#' }
#' @export
#' @examples
#' set.seed(1)
#' x <- rnorm(100)
#' mean_se(x)
mean_se <- function(x, mult = 1) {
Expand Down
2 changes: 2 additions & 0 deletions R/utilities-break.r
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#' table(cut_interval(1:100, 10))
#' table(cut_interval(1:100, 11))
#'
#' set.seed(1)
#'
#' table(cut_number(runif(1000), 10))
#'
#' table(cut_width(runif(1000), 0.1))
Expand Down
1 change: 1 addition & 0 deletions man/aes_colour_fill_alpha.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/aes_position.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/coord_trans.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/cut_interval.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/geom_boxplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/geom_point.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/geom_polygon.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/geom_segment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/geom_spoke.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/geom_tile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/ggplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/hmisc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/lims.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mean_se.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/position_stack.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/qplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/scale_continuous.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/scale_date.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/scale_gradient.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/scale_steps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/stat_ecdf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 411f17b

Please sign in to comment.