Tribbles are an easy way to legibly input data, and therefore helpful for teaching and interactive work. This function takes a tibble and returns code that can recreate it. Note that this function converts "NA" to NA and converts factors to characters to retain the levels.
to_tribble(x, show = FALSE, digits = 5, to_clip = interactive())
The tibble/dataframe to be converted into tribble code
Logical. Print code (otherwise, returned - print with cat()
to get linebreaks etc)
Number of digits to round numeric columns to.
Should code for vector be copied into clipboard? Defaults to TRUE in interactive use, but only works when clipr
package is installed
to_tribble(mtcars[1:5, 1:3], show = TRUE)
#> tibble::tribble(
#> ~mpg, ~cyl, ~disp,
#> 21, 6, 160,
#> 21, 6, 160,
#> 22.8, 4, 108,
#> 21.4, 6, 258,
#> 18.7, 8, 360
#> )