Package 'btabler'

Title: Nice Formatting For LaTeX Tables
Description: There are a number of packages for creating LaTeX tables from R, but they lack feature like merging cells. `btabler` provides a function to do just that.
Authors: Lukas Bütikofer [cre, aut], Alan G. Haynes [ctb]
Maintainer: Lukas Bütikofer <[email protected]>
License: MIT + file LICENSE
Version: 0.0.4
Built: 2025-02-12 03:10:28 UTC
Source: https://github.com/CTU-Bern/btabler

Help Index


btable

Description

btable is a wrapper for xtable and produces tables in latex format.

Usage

btable(
  dat,
  nhead,
  nfoot,
  caption,
  label = NULL,
  alignp = NA,
  aligntot = NA,
  alignh1 = "l",
  nnewline = 0,
  indent = 1,
  hlines = NA,
  fonts1 = 8,
  fonts2 = 12,
  rulelength = NULL,
  head_it = c(2),
  head_bf = NA,
  foot_it = NULL,
  foot_bf = NA,
  tab.env = "long",
  table.placement = "ht",
  middle_sep = NA,
  aggregate = TRUE,
  rephead = TRUE,
  mergerow = NA,
  sfile = "",
  print = TRUE,
  comment = FALSE,
  include.colnames = FALSE,
  ...
)

Arguments

dat

dataframe

nhead

number of header rows

nfoot

number of footer rows

caption

caption of table

label

label of table for referncing in latex

alignp

optional width of first column, to be entered with unit, e.g. "2cm"

aligntot

alignment of all columns, as string using latex syntax, e.g. "lccc"

alignh1

alignment of header of the first column (all other headers are centered)

nnewline

if given, a line break will be introduced for the first column before nnewline letters at a space (if possible)

indent

indent of line break

hlines

additional horizontal lines after specified rows

fonts1

font size of text, 8 by default

fonts2

font size of row, 12 by default

rulelength

optional width of footer

head_it

number of the header rows to be shown in italic, NA indicates none

head_bf

number of the header rows to be shown in bold, NA indicates none

foot_it

number of the footer rows to be shown in italic, NA indicates none

foot_bf

number of the footer rows to be shown in bold, NA indicates none

tab.env

tabular environment, "long" or "float", use float to suppress breaking across pages

table.placement

table placement if tab.env==float, contain only elements of "h","t","b","p","!","H", default value is "ht".

middle_sep

empty_column in table

aggregate

aggregation of header names TRUE/FALSE

rephead

repeating header after page break

mergerow

merge indicated row, show only first entry

sfile

sanitizing file for latex, dataframe with two columns, pattern and replacement

print

logical, indicates whether table should be printed, TRUE by default

comment

logical, indicates whether xtable should print it's comment, FALSE by default

include.colnames

logical, indicated whether the columns names are printed, FALSE by default.

...

further arguments passed to print.xtable()

Details

Required arguments are a data.frame with the table (dat), the number of header and footer lines (nhead, nfoot) and a caption for the table.

Value

table in latex format

Examples

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(df,nhead=1,nfoot=0,caption="Table1",aligntot="llll")

#two header lines
df<-data.frame(name=c("","","Row 1","Row2"),out_t=c("Total","mean (sd)","t1","t1"),
    out_1=c("Group 1","mean (sd)","g11","g12"),out_2=c("Group 2","mean (sd)","g21","g22"))
btable(df,nhead=2,nfoot=0,caption="Table1")
btable(df,nhead=2,nfoot=0,caption="Table1",head_it=NA)
btable(df,nhead=2,nfoot=0,caption="Table1",head_it=NA,aggregate=FALSE)

#footer
df<-data.frame(name=c("","Row 1","Row2","*Footer"),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=1,caption="Table1")

#floating table, no page break within table
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=1,caption="Table1",tab.env="float",table.placement="H")

#save table and print later
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"))
saved_table<-btable(df,nhead=1,nfoot=1,caption="Table1",print=FALSE)
cat(saved_table)

Open a basic template suitable for use with btable

Description

Open a basic template suitable for use with btable

Usage

use_btabletemplate(name, fmt = c("Rmd", "Rnw"), ..., open = TRUE)

Arguments

name

name to save the file under

fmt

character defining format (Rmd or Rnw are accepted)

...

other options passed to use_template

open

logical, whether to open the file

Value

(by default) saves and opens a script of the chosen format

Examples

## Not run: 
# Rmd file
use_btabletemplate("foo")
# Rnw file
use_btabletemplate("foo", fmt = "Rnw")

## End(Not run)