https://github.com/ctu-bern/btabler

An R package for easy creation of latex tables

https://github.com/ctu-bern/btabler

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.5%) to scientific vocabulary

Keywords

latex tables
Last synced: 5 months ago · JSON representation

Repository

An R package for easy creation of latex tables

Basic Info
Statistics
  • Stars: 0
  • Watchers: 2
  • Forks: 2
  • Open Issues: 2
  • Releases: 0
Topics
latex tables
Created almost 5 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---



```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
                      fig.path = "man/figures/README-")
```

# btabler 


`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)).

Owner

  • Name: CTU Bern
  • Login: CTU-Bern
  • Kind: organization
  • Location: Switzerland

CTU Bern is the Clinical Trials Unit of the Faculty of Medicine of the University of Bern and the Inselspital, Bern University Hospital.

GitHub Events

Total
Last Year

Dependencies

DESCRIPTION cran
  • xtable * depends
  • usethis * imports
  • knitr * suggests
  • markdown * suggests
  • rmarkdown * suggests
  • testthat >= 3.0.0 suggests
.github/workflows/R-CMD-full.yaml actions
  • actions/cache v1 composite
  • actions/checkout v2 composite
  • actions/upload-artifact master composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
.github/workflows/R-CMD-release.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
.github/workflows/render-readme.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite