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())

Arguments

x

The tibble/dataframe to be converted into tribble code

show

Logical. Print code (otherwise, returned - print with cat() to get linebreaks etc)

digits

Number of digits to round numeric columns to.

to_clip

Should code for vector be copied into clipboard? Defaults to TRUE in interactive use, but only works when clipr package is installed

Examples

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
#> )