Skip to content

Generate individual vectors of the types supported by vroom

Usage

gen_character(n, min = 5, max = 25, values = c(letters, LETTERS, 0:9), ...)

gen_double(n, f = stats::rnorm, ...)

gen_number(n, f = stats::rnorm, ...)

gen_integer(n, min = 1L, max = .Machine$integer.max, prob = NULL, ...)

gen_factor(
  n,
  levels = NULL,
  ordered = FALSE,
  num_levels = gen_integer(1L, 1L, 25L),
  ...
)

gen_time(n, min = 0, max = hms::hms(days = 1), fractional = FALSE, ...)

gen_date(n, min = as.Date("2001-01-01"), max = as.Date("2021-01-01"), ...)

gen_datetime(
  n,
  min = as.POSIXct("2001-01-01"),
  max = as.POSIXct("2021-01-01"),
  tz = "UTC",
  ...
)

gen_logical(n, ...)

gen_name(n)

Arguments

n

The size of the vector to generate

min

The minimum range for the vector

max

The maximum range for the vector

values

The explicit values to use.

...

Additional arguments passed to internal generation functions

f

The random function to use.

prob

a vector of probability weights for obtaining the elements of the vector being sampled.

levels

The explicit levels to use, if NULL random levels are generated using gen_name().

ordered

Should the factors be ordered factors?

num_levels

The number of factor levels to generate

fractional

Whether to generate times with fractional seconds

tz

The timezone to use for dates

Examples

# characters
gen_character(4)
#> [1] "vDXTB65ZzWK8cVQr"        "yKDmIL2nE4p64wcaXCWyJO0"
#> [3] "TjYAX"                   "IVQY2EoHG"              

# factors
gen_factor(4)
#> [1] different_jaguar  magnificent_snake worried_armadillo
#> [4] helpless_jaguar  
#> 13 Levels: helpless_jaguar hollow_bat wet_chimpanzee ... hissing_rooster

# logical
gen_logical(4)
#> [1] FALSE FALSE  TRUE  TRUE

# numbers
gen_double(4)
#> [1]  0.90376761  0.01140231 -0.38551473 -0.93018563
gen_integer(4)
#> [1] 2011655206 1442483574   26554727 1114092870

# temporal data
gen_time(4)
#> 21:15:28
#> 16:18:56
#> 03:26:27
#> 20:52:28
gen_date(4)
#> [1] "2008-12-19" "2011-05-30" "2002-12-27" "2009-02-27"
gen_datetime(4)
#> [1] "2002-09-12 06:39:32 UTC" "2008-10-15 12:43:41 UTC"
#> [3] "2019-11-21 18:56:06 UTC" "2002-09-29 11:32:58 UTC"