{"id":13733956,"url":"https://github.com/cbailiss/basictabler","last_synced_at":"2025-08-08T10:45:42.550Z","repository":{"id":143716734,"uuid":"104359939","full_name":"cbailiss/basictabler","owner":"cbailiss","description":"Construct Rich Tables for Output to HTML/Excel","archived":false,"fork":false,"pushed_at":"2025-04-26T14:06:29.000Z","size":2159,"stargazers_count":36,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-12T16:47:16.016Z","etag":null,"topics":["html","htmlwidget","r","tables","visualization"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cbailiss.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-09-21T14:39:37.000Z","updated_at":"2025-06-08T02:55:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"d48f4e47-bf6a-42b3-881b-642483f3e525","html_url":"https://github.com/cbailiss/basictabler","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/cbailiss/basictabler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbailiss%2Fbasictabler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbailiss%2Fbasictabler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbailiss%2Fbasictabler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbailiss%2Fbasictabler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cbailiss","download_url":"https://codeload.github.com/cbailiss/basictabler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbailiss%2Fbasictabler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269410045,"owners_count":24412147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","htmlwidget","r","tables","visualization"],"created_at":"2024-08-03T03:00:51.256Z","updated_at":"2025-08-08T10:45:42.506Z","avatar_url":"https://github.com/cbailiss.png","language":"R","funding_links":[],"categories":["R","UI Components"],"sub_categories":["Table"],"readme":"---\ntitle: \"basictabler\"\noutput: github_document\n---\n\n```{r setup, include=FALSE}\nknitr::opts_chunk$set(echo = TRUE)\n```\n\n[![R-CMD-check](https://github.com/cbailiss/basictabler/workflows/R-CMD-check/badge.svg)](https://github.com/cbailiss/basictabler/actions)\n[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/basictabler)](https://cran.r-project.org/package=basictabler)\n\nThe `basictabler` package enables rich tables to be created and rendered/exported with just a few lines of R.\n\nThe `basictabler` package:\n\n- Provides an easy way of creating basic tables, especially from data frames and matrices.\n- Provides flexibility so that the structure/content of the table can be easily built/modified. \n- Provides formatting options to simplify rendering/exporting data.\n- Provides styling options so the tables can be themed/branded as needed.\n\nThe tables are rendered as htmlwidgets or plain text. The HTML/text can be exported for use outside of R.\n\nThe 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.\n\nUsing the `flextabler` package it is also possible to output tables to Word and PowerPoint.\n\n`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.\n\nFor more information see http://www.basictabler.org.uk/.\n\n### Installation\n\nYou can install:\n\n* the latest released version from CRAN with\n\n```{r eval=FALSE}\ninstall.packages(\"basictabler\")\n```\n\n* the latest development version from github with\n\n```{r eval=FALSE}\ndevtools::install_github(\"cbailiss/basictabler\", build_vignettes = TRUE)\n```\n\n### Examples\n\n#### Trivial Example\n\nCreating a tiny HTML table from a data frame and immediately rendering it as a htmlwidget:\n\n```{r, message=FALSE, warning=FALSE, eval=FALSE, comment=\"\"}\nlibrary(basictabler)\nqhtbl(data.frame(a=1:2, b=3:4))\n```\n\n#### Another Example\n\nCreating a table from a data frame, specifying column names and value formats:\n\n```{r eval=FALSE}\n# aggregate the sample data to make a small data frame\nlibrary(basictabler)\nlibrary(dplyr)\ntocsummary \u003c- bhmsummary %\u003e%\n  group_by(TOC) %\u003e%\n  summarise(OnTimeArrivals=sum(OnTimeArrivals),\n            OnTimeDepartures=sum(OnTimeDepartures),\n            TotalTrains=sum(TrainCount)) %\u003e%\n  ungroup() %\u003e%\n  mutate(OnTimeArrivalPercent=OnTimeArrivals/TotalTrains*100,\n         OnTimeDeparturePercent=OnTimeDepartures/TotalTrains*100) %\u003e%\n  arrange(TOC)\n\n# To specify formatting, a list is created which contains one element for each column in \n# the data frame, i.e. tocsummary contains six columns so the columnFormats list has six elements.\n# The values in the first column in the data frame won't be formatted since NULL has been specified.\n# The values in the 2nd, 3rd and 4th columns will be formatted using format(value, big.mark=\",\")\n# The values in the 5th and 6th columns will be formatted using sprintf(value, \"%.1f\")\ncolumnFormats=list(NULL, list(big.mark=\",\"), list(big.mark=\",\"), list(big.mark=\",\"), \"%.1f\", \"%.1f\")\n\n# render the table directly as a html widget\nqhtbl(tocsummary, firstColumnAsRowHeaders=TRUE,\n            explicitColumnHeaders=c(\"TOC\", \"On-Time Arrivals\", \"On-Time Departures\",\n                                    \"Total Trains\", \"On-Time Arrival %\", \"On-Time Departure %\"),\n            columnFormats=columnFormats)\n```\n\n![http://cbailiss.me.uk/basictablerreadmeimgs/example1.png](http://cbailiss.me.uk/basictablerreadmeimgs/example1.png)\n\nIn the example above, the `qhtbl()` functions returns a html widget that is rendered immediately in the R-Studio viewer window.  An alternative is to use the `qtbl()` function which returns a BasicTable object that can be further manipulated.  The styling example further below demonstrates this.\n\n#### Changing a Table Example\n\nTables can also be built row-by-row, column-by-column and cell-by-cell.  Once built tables can be modified (adding/removing rows columns and cells, merging cells and changing styling).  The following example shows more granular ways of building and changing a table:\n\n```{r eval=FALSE}\n# data for the table\nsaleIds \u003c- c(5334, 5336, 5338)\nitems \u003c- c(\"Apple\", \"Orange\", \"Banana\")\nquantities \u003c- c(5, 8, 6)\nprices \u003c- c(0.34452354, 0.4732543, 1.3443243)\n\n# construct a table column by column\nlibrary(basictabler)\ntbl \u003c- BasicTable$new()\ntbl$cells$setCell(1, 1, cellType=\"root\", rawValue=\"Sale ID\")\ntbl$cells$setCell(1, 2, cellType=\"columnHeader\", rawValue=\"Item\")\ntbl$cells$setCell(1, 3, cellType=\"columnHeader\", rawValue=\"Quantity\")\ntbl$cells$setCell(1, 4, cellType=\"columnHeader\", rawValue=\"Price\")\ntbl$cells$setColumn(1, cellTypes=\"rowHeader\", rawValues=saleIds)\ntbl$cells$setColumn(2, cellTypes=\"cell\", rawValues=items)\ntbl$cells$setColumn(3, cellTypes=\"cell\", rawValues=quantities)\ntbl$cells$setColumn(4, cellTypes=\"cell\", rawValues=prices,\n                    formats=list(\"%.2f\"))\n\n# example of changing the table - appending a row\nformats \u003c- list(NULL, NULL, NULL, \"%.2f\")\ncellTypes=c(\"rowHeader\", \"cell\", \"cell\", \"cell\")\ntbl$cells$setRow(5, cellTypes=cellTypes, formats=formats, \n                 rawValues=list(5343, \"Pear\", 2, 1.0213424))\n\n# example of changing the table - inserting a row\ntbl$cells$insertRow(1)\ntbl$cells$setRow(1, cellTypes=\"columnHeader\",\n                 rawValues=list(\"Sale ID\", \"Sale Details\", \"\", \"\"))\n\n# example of changing the table - merging some cells\ntbl$mergeCells(rFrom=1, cFrom=1, rSpan=2, cSpan=1)\ntbl$mergeCells(rFrom=1, cFrom=2, rSpan=1, cSpan=3)\n\n# render the final table\ntbl$renderTable()\n```\n\n![http://cbailiss.me.uk/basictablerreadmeimgs/example4.png](http://cbailiss.me.uk/basictablerreadmeimgs/example4.png)\n\n#### Styling Example\n\nStyling can be specified when creating tables:\n\n```{r eval=FALSE}\n# aggregate the sample data to make a small data frame\nlibrary(basictabler)\nlibrary(dplyr)\ntocsummary \u003c- bhmsummary %\u003e%\n  group_by(TOC) %\u003e%\n  summarise(OnTimeArrivals=sum(OnTimeArrivals),\n            OnTimeDepartures=sum(OnTimeDepartures),\n            TotalTrains=sum(TrainCount)) %\u003e%\n  ungroup() %\u003e%\n  mutate(OnTimeArrivalPercent=OnTimeArrivals/TotalTrains*100,\n         OnTimeDeparturePercent=OnTimeDepartures/TotalTrains*100) %\u003e%\n  arrange(TOC)\n\n# column formats\ncolumnFormats=list(NULL, list(big.mark=\",\"), list(big.mark=\",\"), list(big.mark=\",\"), \"%.1f\", \"%.1f\")\n\n# create the table\ntbl \u003c- qtbl(tocsummary, firstColumnAsRowHeaders=FALSE,\n            explicitColumnHeaders=c(\"TOC\", \"On-Time Arrivals\", \"On-Time Departures\",\n                                    \"Total Trains\", \"On-Time Arrival %\", \"On-Time Departure %\"),\n            columnFormats=columnFormats, \n            tableStyle=list(\"border-color\"=\"maroon\"),\n            headingStyle=list(\"color\"=\"cornsilk\", \"background-color\"=\"maroon\", \n                              \"font-style\"=\"italic\", \"border-color\"=\"maroon\"), \n            cellStyle=list(\"color\"=\"maroon\", \"background-color\"=\"cornsilk\", \n                           \"border-color\"=\"maroon\"))\n\n# set column alignment of first column\n# the arguments are (rFrom, cFrom, rTo, cTo, declarations)\ntbl$setStyling(2, 1, 5, 1, declarations=list(\"text-align\"=\"left\"))\n\n# render table\ntbl$renderTable()\n```\n\n![http://cbailiss.me.uk/basictablerreadmeimgs/example3.png](http://cbailiss.me.uk/basictablerreadmeimgs/example3.png)\n\n#### Excel Output\n\nThe same styling/formatting used for the HTML output is also used when outputting to Excel - greatly reducing the amount of script that needs to be written to create Excel output.  The only additional formatting that typically needs applying is the Excel cell format strings.\n\n```{r eval=FALSE}\n# aggregate the sample data to make a small data frame\nlibrary(basictabler)\nlibrary(dplyr)\ntocsummary \u003c- bhmsummary %\u003e%\n  group_by(TOC) %\u003e%\n  summarise(OnTimeArrivals=sum(OnTimeArrivals),\n            OnTimeDepartures=sum(OnTimeDepartures),\n            TotalTrains=sum(TrainCount)) %\u003e%\n  ungroup() %\u003e%\n  mutate(OnTimeArrivalPercent=OnTimeArrivals/TotalTrains*100,\n         OnTimeDeparturePercent=OnTimeDepartures/TotalTrains*100) %\u003e%\n  arrange(TOC)\n\ncolumnFormats=list(NULL, list(big.mark=\",\"), list(big.mark=\",\"), list(big.mark=\",\"), \"%.1f\", \"%.1f\")\n\n# create the table\ntbl \u003c- qtbl(tocsummary, firstColumnAsRowHeaders=TRUE,\n            explicitColumnHeaders=c(\"TOC\", \"On-Time Arrivals\", \"On-Time Departures\",\n                                    \"Total Trains\", \"On-Time Arrival %\", \"On-Time Departure %\"),\n            columnFormats=columnFormats)\n\n# set the styling on the count cells\n# the arguments are (rFrom, cFrom, rTo, cTo, declarations)\ntbl$setStyling(2, 2, 5, 4, declarations=list(\"xl-value-format\"=\"#,##0\"))\n# set the styling on the average delay cells\ntbl$setStyling(2, 5, 5, 6, declarations=list(\"xl-value-format\"=\"##0.0\"))\n\n# render the table to an Excel workbook\nlibrary(openxlsx)\nwb \u003c- createWorkbook(creator = Sys.getenv(\"USERNAME\"))\naddWorksheet(wb, \"Data\")\ntbl$writeToExcelWorksheet(wb=wb, wsName=\"Data\", \n                          topRowNumber=2, leftMostColumnNumber=2, applyStyles=TRUE)\nsaveWorkbook(wb, file=\"C:\\\\test.xlsx\", overwrite = TRUE)\n\n```\n\n![http://cbailiss.me.uk/basictablerreadmeimgs/example2.png](http://cbailiss.me.uk/basictablerreadmeimgs/example2.png)\n\nIn the screenshot above, Gridlines have been made invisible to make the styling easier to see (by clearing the checkbox on the 'View' ribbon).  Columns were also auto-sized - though the widths of columns could also be manually specified from R.  See the Excel Export vignette for more details.\n\n### More Information\n\nIt is possible to create tables from data frames, matrices, row-by-row, column-by-column and/or cell-by-cell.\n\nTables can be further manipulated once created, including adding/removing cells/rows/columns and merging cells.  \n\nStyling and formatting can be specified for individual cells and ranges of cells.\n\nSee the package vignettes for more information:\n\n```{r eval=FALSE}\n# to see a list of available package vignettes:\nvignette(package=\"basictabler\")\n# to open a specific vignette\nvignette(topic=\"v01-introduction\", package=\"basictabler\")\n```\n\nThe vignettes can also be read on CRAN at:\nhttps://cran.r-project.org/package=basictabler\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbailiss%2Fbasictabler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcbailiss%2Fbasictabler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbailiss%2Fbasictabler/lists"}