Build Status CRAN_Status_Badge

The basictabler package enables rich tables to be created and rendered/exported with just a few lines of R.

The basictabler package:

The tables are rendered as htmlwidgets or plain text. The HTML/text can be exported for use outside of R.

The tables can also be exported to Excel, including the styling/formatting. The formatting/styling is specified once and can then be used when rendering to both HTML and Excel - i.e. it is not necessary to specify the formatting/styling separately for each output format.

basictabler is a companion package to the pivottabler package. pivottabler is focussed on generating pivot tables and can aggregate data. basictabler does not aggregate data but offers more control of table structure.


You can install:

devtools::install_github("cbailiss/basictabler", build_vignettes = TRUE)


Trivial Example

Creating a tiny HTML table from a data frame and immediately rendering it as a htmlwidget:

qhtbl(data.frame(a=1:2, b=3:4))

Another Example

Creating a table from a data frame, specifying column names and value formats:

# aggregate the sample data to make a small data frame
tocsummary <- bhmsummary %>%
  group_by(TOC) %>%
            TotalTrains=sum(TrainCount)) %>%
  ungroup() %>%
         OnTimeDeparturePercent=OnTimeDepartures/TotalTrains*100) %>%

# To specify formatting, a list is created which contains one element for each column in 
# the data frame, i.e. tocsummary contains six columns so the columnFormats list has six elements.
# The values in the first column in the data frame won't be formatted since NULL has been specified.
# The values in the 2nd, 3rd and 4th columns will be formatted using format(value, big.mark=",")
# The values in the 5th and 6th columns will be formatted using sprintf(value, "%.1f")
columnFormats=list(NULL, list(big.mark=","), list(big.mark=","), list(big.mark=","), "%.1f", "%.1f")

# render the table directly as a html widget
qhtbl(tocsummary, firstColumnAsRowHeaders=TRUE,
            explicitColumnHeaders=c("TOC", "On-Time Arrivals", "On-Time Departures",
                                    "Total Trains", "On-Time Arrival %", "On-Time Departure %"),

Tables can be further manipulated once created, including adding/removing cells/rows/columns and specifying styling and formatting.

It is also possible to create tables row-by-row, column-by-column and/or cell-by-cell.

More Information

See the package vignettes for more information:

# to see a list of available package vignettes:
# to open a specific vignette
vignette(topic="v01-introduction", package="basictabler")

The vignettes can also be read on CRAN at: