Skip to contents

Simulate a data frame with different data types. Provides the option of inserting base::NA or returning base::NULL or zero-length data frame.

Usage

sim_data.frame(
  x = list(logical = sim_logical(length = n), integer = sim_integer(length = n), double =
    sim_double(length = n), factor = sim_factor(length = n), character =
    sim_character(length = n), date = sim_date(length = n), datetime =
    sim_datetime(length = n)),
  n = 10L,
  prob_null = 0,
  prob_zero_length = 0
)

Arguments

x

(named list)
Will be converted to data.frame. All list elements must be equal length vectors. Use the bkcheck::sim_*() functions to fill in list elements.

n

(Scalar integer: [0, Inf])
A convenience argument to set the number of rows when using bkcheck::sim_*() in x.

prob_null

(Scalar numeric: [0, 1])
The probability of returning a NULL object.

prob_zero_length

(Scalar numeric: [0, 1])
The probability of returning a zero-row and zero-column data frame: data.frame().

Value

data.frame

Examples

#----------------------------------------------------------------------------
# sim_data.frame() examples
#----------------------------------------------------------------------------
library(bkcheck)

sim_data.frame()
#>    logical integer    double    factor character       date            datetime
#> 1    FALSE       0  4.386359   October    W4nv!e 2026-06-17 2026-06-18 15:00:00
#> 2    FALSE       0  0.000000 September    5-nPIE 2026-06-24 2026-06-17 15:00:00
#> 3    FALSE      -9  7.606181  November    xd*p~i 2026-06-16 2026-06-09 06:00:00
#> 4    FALSE      -2  4.015350       May    "IdaE6 2026-05-22 2026-06-13 03:00:00
#> 5     TRUE       6  1.331726   October    d'IeRU 2026-07-04 2026-06-11 04:00:00
#> 6    FALSE       0  3.929772       May    d'IeRU 2026-05-31 2026-06-12 09:00:00
#> 7    FALSE     -10  4.015350     April    !i/BMW 2026-06-09 2026-06-12 14:00:00
#> 8     TRUE       8  4.386359  February    d'IeRU 2026-07-03 2026-06-09 22:00:00
#> 9    FALSE      -8 -9.201187  February    !i/BMW 2026-05-18 2026-06-18 01:00:00
#> 10   FALSE       5  6.284627     April    qzoSOW 2026-06-09 2026-06-11 23:00:00
sim_data.frame(x = list(var1 = sim_double(length = 10)))
#>          var1
#> 1   1.3481264
#> 2  -5.7406507
#> 3  -0.3176101
#> 4   5.0790622
#> 5   0.0000000
#> 6   7.6431308
#> 7  -0.3176101
#> 8   7.6431308
#> 9   5.0790622
#> 10  5.1935592
sim_data.frame(x = list(logical = sim_logical(length = 10)))
#>    logical
#> 1     TRUE
#> 2     TRUE
#> 3     TRUE
#> 4     TRUE
#> 5     TRUE
#> 6    FALSE
#> 7    FALSE
#> 8     TRUE
#> 9     TRUE
#> 10    TRUE
sim_data.frame(prob_null = 1)
#> NULL
sim_data.frame(prob_zero_length = 1)
#> data frame with 0 columns and 0 rows