-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
115 lines (82 loc) · 3.16 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
fig.path = "man/figures/README-")
```
# btabler <img src='man/figures/logo.png' align="right" width="200">
`r badger::badge_custom("dev version", as.character(packageVersion("btabler")),
"blue", "https://github.com/CTU-Bern/btabler")`
[![R-CMD-fullcheck](https://github.com/CTU-Bern/btabler/actions/workflows/R-CMD-full.yaml/badge.svg)](https://github.com/CTU-Bern/btabler/actions/workflows/R-CMD-full.yaml)
`btabler` is a package which adds wraps the `xtable` package, adding additional
functionality such as merging header columns.
Note that `btabler` does not produce HTML tables. If using `.Rmd`, `output` should be
`pdf_document`.
## Example usage
### Installing the package
The package can be installed from the CTU Bern universe via
```{r gh-installation, eval = FALSE}
install.packages('btabler', repos = 'https://ctu-bern.r-universe.dev')
```
### Using the package
Load it as usual:
```{r, message=FALSE}
library(btabler)
```
Create your tables via whatever means and pass them to the `btable` function:
```{r basic, echo = TRUE, results='asis', eval = FALSE}
df <- data.frame(name = c("", "Row 1", "Row2"),
out_t = c("Total", "t1", "t1"),
out_1 = c("Group 1", "g11", "g12"),
out_2 = c("Group 2", "g21", "g22"))
btable(df, nhead = 1, nfoot = 0, caption = "Table1")
```
`btable` returns the latex code for the table you passed, which can be easily used
with sweave to create tables in reports.
```{r, echo=FALSE}
knitr::include_graphics("man/figures/basic.png")
```
As an example for further modifications, column widths can also be modified using
the `aligntot` argument:
```{r aligntot_width, echo = TRUE, eval = FALSE, results='asis'}
btable(df, nhead = 1, nfoot = 0,
caption = "Table1",
aligntot = "p{3cm}p{1.5cm}p{1.5cm}p{1.5cm}")
```
```{r, echo=FALSE, eval=TRUE}
knitr::include_graphics("man/figures/aligntot_width.png")
```
See the vignette for further examples of using `btabler`
```{r, eval = FALSE}
vignette("btabler")
```
## Requirements for the header
`btabler` tables are only interpretable by LaTeX when a few packages are loaded.
It is recommended to place the following code in the header of your `.tex` file
or `.Rmd`
```
# .tex
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{float}
\usepackage{array}
# .Rmd
header-includes:
- \usepackage{longtable}
- \usepackage{booktabs}
- \usepackage{float}
- \usepackage{array}
```
Other things like custom column types can also be added to the header (see the
vignette for an example)
```{r, eval = FALSE}
vignette("btabler")
```
`btabler` provides basic templates in `Rmd` and `Rnw` formats:
```{r, eval = FALSE}
use_btabletemplate("filename", "Rmd")
```
### Acknowledgements
The package logo was created with [`ggplot2`](https://ggplot2.tidyverse.org/) and [`hexSticker`](https://github.com/GuangchuangYu/hexSticker) with icons from [Font Awesome](https://fontawesome.com/) (via the [emojifont package](https://github.com/GuangchuangYu/emojifont)).