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.

tibble(...)

tibble_(xs)

Arguments

...

A set of name-value pairs. Arguments are evaluated sequentially, so you can refer to previously created variables.

xs

A list of unevaluated expressions created with ~, quote(), or lazyeval::lazy().

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 × 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 × 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 × 2 #> x y #> <dbl> <dbl> #> 1 0.52365044 1.04730087 #> 2 0.83706173 1.67412345 #> 3 0.03350404 0.06700807 #> 4 0.04332844 0.08665688 #> 5 0.79210294 1.58420589 #> 6 0.20269896 0.40539793 #> 7 0.06879545 0.13759090 #> 8 0.86444107 1.72888215 #> 9 0.07708986 0.15417972 #> 10 0.43100342 0.86200684
lst(n = 5, x = runif(n))
#> $n #> [1] 5 #> #> $x #> [1] 0.9736226 0.5709573 0.7544066 0.2424543 0.6271579 #>
# 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 × 1 #> `a + b` #> <int> #> 1 1 #> 2 2 #> 3 3 #> 4 4 #> 5 5
# With the SE version, you give it a list of formulas/expressions tibble_(list(x = ~1:10, y = quote(x * 2)))
#> # A tibble: 10 × 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")) })