tibble() is a trimmed down version of data.frame() that:

  • Never coerces inputs (i.e. strings stay as strings!).

  • Never adds row.names.

  • Never munges column names.

  • Only recycles length 1 inputs.

  • Evaluates its arguments lazily and in order.

  • Adds tbl_df class to output.

  • Automatically adds column names.

data_frame() is an alias to tibble().

tibble_() and its alias data_frame_() use lazy evaluation and are deprecated. New code should use tibble() or data_frame() with quasiquotation.

lst() is similar to list(), but like tibble(), it evaluates its arguments lazily and in order, and automatically adds names.

lst_() uses lazy evaluation and is deprecated. New code should use lst() with quasiquotation.

tibble(...)

data_frame(...)

lst(...)

Arguments

...

A set of name-value pairs. Arguments are evaluated sequentially, so you can refer to previously created variables. These arguments are processed with rlang::quos() and support unquote via !! and unquote-splice via !!!.

See also

as_tibble() to turn an existing list into a data frame.

Examples

a <- 1:5 tibble(a, b = a * 2)
#> # A tibble: 5 x 2 #> a b #> <int> <dbl> #> 1 1 2 #> 2 2 4 #> 3 3 6 #> 4 4 8 #> 5 5 10
tibble(a, b = a * 2, c = 1)
#> # A tibble: 5 x 3 #> a b c #> <int> <dbl> <dbl> #> 1 1 2 1 #> 2 2 4 1 #> 3 3 6 1 #> 4 4 8 1 #> 5 5 10 1
tibble(x = runif(10), y = x * 2)
#> # A tibble: 10 x 2 #> x y #> <dbl> <dbl> #> 1 0.361 0.722 #> 2 0.653 1.31 #> 3 0.144 0.287 #> 4 0.681 1.36 #> 5 0.859 1.72 #> 6 0.839 1.68 #> 7 0.881 1.76 #> 8 0.238 0.475 #> 9 0.579 1.16 #> 10 0.898 1.80
lst(n = 5, x = runif(n))
#> $n #> [1] 5 #> #> $x #> [1] 0.3444290 0.7608582 0.7311036 0.8524324 0.9758180 #>
# tibble never coerces its inputs str(tibble(letters))
#> Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 26 obs. of 1 variable: #> $ letters: chr "a" "b" "c" "d" ...
str(tibble(x = list(diag(1), diag(2))))
#> Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 2 obs. of 1 variable: #> $ x:List of 2 #> ..$ : num [1, 1] 1 #> ..$ : num [1:2, 1:2] 1 0 0 1
# or munges column names tibble(`a + b` = 1:5)
#> # A tibble: 5 x 1 #> `a + b` #> <int> #> 1 1 #> 2 2 #> 3 3 #> 4 4 #> 5 5
# You can splice-unquote a list of quotes and formulas tibble(!!! list(x = rlang::quo(1:10), y = quote(x * 2)))
#> # A tibble: 10 x 2 #> x y #> <int> <dbl> #> 1 1 2 #> 2 2 4 #> 3 3 6 #> 4 4 8 #> 5 5 10 #> 6 6 12 #> 7 7 14 #> 8 8 16 #> 9 9 18 #> 10 10 20
# data frames can only contain 1d atomic vectors and lists # and can not contain POSIXlt
# NOT RUN { tibble(x = tibble(1, 2, 3)) tibble(y = strptime("2000/01/01", "%x")) # }
lst(n = 5, x = runif(n))
#> $n #> [1] 5 #> #> $x #> [1] 0.11304750 0.97026228 0.64808278 0.05607304 0.47313710 #>
# You can splice-unquote a list of quotes and formulas lst(!!! list(n = rlang::quo(2 + 3), y = quote(runif(n))))
#> $n #> [1] 5 #> #> $y #> [1] 0.2946250 0.6102996 0.1211089 0.6294165 0.7119553 #>