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] "QWP9lnnq2a7reBwSbdffr" "IXlKQRT"              
#> [3] "pcesnCqMA5hRKMqV"      "JdjeuOaRDaahwuFzn0AJu"

# factors
gen_factor(4)
#> [1] lively_turtle   rainy_starfish  ugliest_giraffe tender_skunk   
#> 24 Levels: embarrassed_ferret rainy_starfish ... chubby_beetle

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

# numbers
gen_double(4)
#> [1]  0.3262146 -0.3684538  0.6784908  1.4633546
gen_integer(4)
#> [1]  305638302 1614147531 1259613619 1132347176

# temporal data
gen_time(4)
#> 07:46:01
#> 06:08:48
#> 16:24:38
#> 02:00:56
gen_date(4)
#> [1] "2018-03-24" "2018-08-15" "2020-06-16" "2007-10-16"
gen_datetime(4)
#> [1] "2012-03-22 11:30:42 UTC" "2008-02-14 23:56:38 UTC"
#> [3] "2013-08-17 11:43:43 UTC" "2010-02-27 23:44:09 UTC"