Wraps table functions to provide a single user interface. A footer can be added but this requies rows to be merged once the document has been knit to word.
pretty_table(df, col_names = NULL, footer = NULL, cap_fun = pretty_tabref, label = NULL, caption = NULL, tab_fun = pander, ...)
df | A data frame to be converted to a markdown table. Optionally a vector can be passed, this will be reformatted into a data frame with the vectors names used in the firt column. |
---|---|
col_names | A character vector of replacement column names. |
footer | The desired footer as a character string. |
cap_fun | Caption function to wrap, if supplied pretty_table defaults to defining an empty caption. |
label | A character string of the reference label for the table |
caption | A character string of the required table caption. |
tab_fun | Table function to wrap. Supported functions are |
... | Pass additional arguements to the wrapped table function. |
A markdown table
## A simple table pretty_table(iris[1:5, 1:5])#>#> #> ------------------------------------------------------------------- #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> -------------- ------------- -------------- ------------- --------- #> 5.1 3.5 1.4 0.2 setosa #> #> 4.9 3 1.4 0.2 setosa #> #> 4.7 3.2 1.3 0.2 setosa #> #> 4.6 3.1 1.5 0.2 setosa #> #> 5 3.6 1.4 0.2 setosa #> ------------------------------------------------------------------- #> #> Table: Table 1: #>## Renaming columns pretty_table(iris[1:5, 1:5], col_names = as.character(1:5))#> #> -------------------------------- #> 1 2 3 4 5 #> ----- ----- ----- ----- -------- #> 5.1 3.5 1.4 0.2 setosa #> #> 4.9 3 1.4 0.2 setosa #> #> 4.7 3.2 1.3 0.2 setosa #> #> 4.6 3.1 1.5 0.2 setosa #> #> 5 3.6 1.4 0.2 setosa #> -------------------------------- #> #> Table: Table 2: #>## Adding a footer pretty_table(iris[1:5, 1:5], footer = 'Example footer')#> #> --------------------------------------------------------------------- #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> ---------------- ------------- -------------- ------------- --------- #> 5.1 3.5 1.4 0.2 1 #> #> 4.9 3 1.4 0.2 1 #> #> 4.7 3.2 1.3 0.2 1 #> #> 4.6 3.1 1.5 0.2 1 #> #> 5 3.6 1.4 0.2 1 #> #> Example footer #> --------------------------------------------------------------------- #> #> Table: Table 3: #>## Changing to a kable table library(knitr) pretty_table(iris[1:5, 1:5], tab_fun = kable)#> #> #> | Sepal.Length| Sepal.Width| Petal.Length| Petal.Width|Species | #> |------------:|-----------:|------------:|-----------:|:-------| #> | 5.1| 3.5| 1.4| 0.2|setosa | #> | 4.9| 3.0| 1.4| 0.2|setosa | #> | 4.7| 3.2| 1.3| 0.2|setosa | #> | 4.6| 3.1| 1.5| 0.2|setosa | #> | 5.0| 3.6| 1.4| 0.2|setosa |## Passing a named vector of values pretty_table(c(b = 1, c = 2, a = 3))#> #> ----------------- #> #> -------- -------- #> b 1 #> #> c 2 #> #> a 3 #> ----------------- #> #> Table: Table 5: #>