Easily create tables from data frames/matrices. Create/manipulate tables row-by-row, column-by-column or cell-by-cell. Use common formatting/styling to output rich tables as 'HTML', 'HTML widgets' or to 'Excel'.
basictabler package enables rich tables to be created and rendered/exported with just a few lines of R.
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 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)
Creating a tiny HTML table from a data frame and immediately rendering it as a htmlwidget:
Creating a table from a data frame, specifying column names and value formats:
# aggregate the sample data to make a small data framelibrary(basictabler)library(dplyr)tocsummary <- bhmsummary %>%group_by(TOC) %>%summarise(OnTimeArrivals=sum(OnTimeArrivals),OnTimeDepartures=sum(OnTimeDepartures),TotalTrains=sum(TrainCount)) %>%ungroup() %>%mutate(OnTimeArrivalPercent=OnTimeArrivals/TotalTrains*100,OnTimeDeparturePercent=OnTimeDepartures/TotalTrains*100) %>%arrange(TOC)# 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 widgetqhtbl(tocsummary, firstColumnAsRowHeaders=TRUE,explicitColumnHeaders=c("TOC", "On-Time Arrivals", "On-Time Departures","Total Trains", "On-Time Arrival %", "On-Time Departure %"),columnFormats=columnFormats)
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.
See the package vignettes for more information:
# to see a list of available package vignettes:vignette(package="basictabler")# to open a specific vignettevignette(topic="v01-introduction", package="basictabler")
The vignettes can also be read on CRAN at: https://cran.r-project.org/package=basictabler
No versions prior to 0.1.0 were released.