| Title: | Construct Rich Tables for Output to 'HTML'/'Excel' |
|---|---|
| Description: | 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'. |
| Authors: | Christopher Bailiss [aut, cre] |
| Maintainer: | Christopher Bailiss <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.4 |
| Built: | 2026-05-21 10:28:11 UTC |
| Source: | https://github.com/cbailiss/basictabler |
The 'BasicTable' class represents a table with styling and formatting that can be rendered to multiple output formats.
R6Class object.
argumentCheckModeThe level of argument checking to perform. One of "auto", "none", "minimal", "basic", "balanced" (default) or "full".
compatibilityA list containing compatibility options to force legacy behaviours. See the NEWS file for details.
traceEnabledA logical value indicating whether actions are logged to a trace file.
cellsA 'TableCells' object containing all of the cells in the body of the table.
allCellsA list of all of the cells in the table, where each element in the list is a 'TableCell' object.
mergedCellsA 'TableCellRanges' object describing the merged cells.
rowCountThe number of rows in the table.
columnCountThe number of columns in the table.
asCharacterThe plain-text representation of the table.
themeThe name of the theme used to style the table. If setting this property, either a theme name can be used, or a list can be used (which specifies a simple theme) or a 'TableStyles' object can be used. See the "Styling" vignette for details and examples.
stylesA 'TableStyles' object containing the styles used to theme the table.
allowExternalStylesDefault 'FALSE', which means the 'TableStyles' object checks that style names specified for styling the different parts of the table must exist in the styles collection. If they do not an error will occur. Specify 'TRUE' to disable this check, e.g. if the style definitions are not managed by 'basictabler' but instead in an external system.
allTimingsThe time taken for various activities related to constructing the table.
significantTimingsThe time taken for various activities related to constructing the table, where the elapsed time > 0.1 seconds.
new()
Create a new 'BasicTable' object.
BasicTable$new( argumentCheckMode = "auto", theme = NULL, replaceExistingStyles = FALSE, tableStyle = NULL, headingStyle = NULL, cellStyle = NULL, totalStyle = NULL, compatibility = NULL, traceEnabled = FALSE, traceFile = NULL )
argumentCheckModeThe level of argument checking to perform. Must be one of "auto", "none", "minimal", "basic", "balanced" (default) or "full".
themeA theme to use to style the table. Either:
(1) The name of a built in theme, or
(2) A list of simple style settings, or
(3) A 'TableStyles' object containing a full set of styles.
See the "Styling" vignette for many examples.
replaceExistingStylesDefault 'FALSE' to retain existing styles in the styles collection and add specified styles as new custom styles. Specify 'TRUE' to update the definitions of existing styles.
tableStyleStyling to apply to the table. Either:
(1) The name of a built in style, or
(2) A list of CSS style declarations, e.g.
'list("font-weight"="bold", "color"="#0000FF")', or
(3) A 'TableStyle' object.
headingStyleStyling to apply to the headings. See the 'tableStyle' argument for details.
cellStyleStyling to apply to the normal cells. See the 'tableStyle' argument for details.
totalStyleStyling to apply to the total cells. See the 'tableStyle' argument for details.
compatibilityA list containing compatibility options to force legacy behaviours. See the NEWS file for details.
traceEnabledDefault 'FALSE'. Specify 'TRUE' to generate a trace for debugging purposes.
traceFileIf tracing is enabled, the location to generate the trace file.
No return value.
getNextInstanceId()
Get the next unique object instance identifier.
BasicTable$getNextInstanceId()
R6 classes cannot be easily compared to check if two variables are both referring to the same object instance. Instance ids are a mechanism to work around this problem. Each cell is assigned an instance id during object creation, which enables reliable reference comparisons.
An integer instance id.
addData()
Populate the table from a data frame, specifying headers and value formatting.
BasicTable$addData( dataFrame = NULL, columnNamesAsColumnHeaders = TRUE, explicitColumnHeaders = NULL, rowNamesAsRowHeaders = FALSE, firstColumnAsRowHeaders = FALSE, explicitRowHeaders = NULL, numberOfColumnsAsRowHeaders = 0, columnFormats = NULL, fmtFuncArgs = NULL, columnCellTypes = NULL, baseStyleNames = NULL )
dataFrameThe data frame to generate the table from.
columnNamesAsColumnHeaders'TRUE' to use the data frame column names as column headings in the table. Default value 'TRUE.'
explicitColumnHeadersA character vector of column names to use as column headings in the table.
rowNamesAsRowHeaders'TRUE' to use the data frame row names as row headings in the table. Default value 'FALSE.'
firstColumnAsRowHeaders'TRUE' to use the first column in the data frame as row headings in the table. Default value 'FALSE.'
explicitRowHeadersA character vector of row names to use as row headings in the table.
numberOfColumnsAsRowHeadersThe number of columns to be set as row headers.
columnFormatsA list that is the same length as the number of columns in the data frame, where each list element specifies how to format the values. Each list element can be either a character format string to be used with 'sprintf()', a list of arguments to be used with 'base::format()' or a custom R function which will be invoked once per value to be formatted.
fmtFuncArgsA list that is the same length as the number of columns in the data frame, where each list element specifies a list of arguments to pass to custom R format functions.
columnCellTypesA vector that is the same length as the number of columns in the data frame, where each element is one of the following values that specifies the type of cell: root, rowHeader, columnHeader, cell, total. The cellType controls the default styling that is applied to the cell. Typically only rowHeader, cell or total would be used.
baseStyleNamesA character vector of style names (from the table theme) used to style the column values.
No return value.
addMatrix()
Populate the table from a matrix, specifying headers and value formatting.
BasicTable$addMatrix( matrix = NULL, columnNamesAsColumnHeaders = TRUE, explicitColumnHeaders = NULL, rowNamesAsRowHeaders = FALSE, explicitRowHeaders = NULL, columnFormats = NULL, baseStyleNames = NULL, fmtFuncArgs = NULL )
matrixThe matrix to generate the table from.
columnNamesAsColumnHeaders'TRUE' to use the matrix column names as column headings in the table. Default value 'TRUE.'
explicitColumnHeadersA character vector of column names to use as column headings in the table.
rowNamesAsRowHeaders'TRUE' to use the matrix row names as row headings in the table. Default value 'FALSE.'
explicitRowHeadersA character vector of row names to use as row headings in the table.
columnFormatsA list that is the same length as the number of columns in the matrix, where each list element specifies how to format the values. Each list element can be either a character format string to be used with 'sprintf()', a list of arguments to be used with 'base::format()' or a custom R function which will be invoked once per value to be formatted.
baseStyleNamesA character vector of style names (from the table theme) used to style the column values.
fmtFuncArgsA list that is the same length as the number of columns in the data frame, where each list element specifies a list of arguments to pass to custom R format functions.
firstColumnAsRowHeaders'TRUE' to use the first column in the matrix as row headings in the table. Default value 'FALSE.'
No return value.
mergeCells()
Merge table cells by specifying either:
The top left cell (rFrom, cFrom) and the merged cell size (rSpan, cSpan) or,
The top left cell (rFrom, cFrom) and bottom-right cell (rTo, cTo), or
The ranges of rows/columns as vectors using rowNumbers and columnNumbers.
BasicTable$mergeCells( rFrom = NULL, cFrom = NULL, rSpan = NULL, cSpan = NULL, rTo = NULL, cTo = NULL, rowNumbers = NULL, columnNumbers = NULL )
rFromThe row-number of the top-left cell being merged.
cFromThe column number of the top-left cell being merged.
rSpanThe number of rows that the merged cell spans.
cSpanThe number of columns that the merged cell spans.
rToThe row-number of the bottom-right cell being merged.
cToThe column-number of the bottom-right cell being merged.
rowNumbersA vector specifying the row numbers of the cells to be merged.
columnNumbersA vector specifying the columns numbers of the cells to be merged.
No return value.
unmergeCells()
Unmerge a set of merged cells by specifying any cell within the set of merged cells.
BasicTable$unmergeCells(r = NULL, c = NULL, errorIfNotFound = TRUE)
rThe row number of any cell within the merged cell.
cThe column number of any cell within the merged cell.
errorIfNotFound'TRUE' to ignore any attempt to unmerge a cell that is not merged. Default value 'TRUE.'
A new 'TableCell' object.
applyCellMerges()
Internal method that sets the 'isMerged' and 'mergeIndex' properties on each cell based on the cell merges that have been specified.
BasicTable$applyCellMerges()
No return value.
formatValue()
Format a value using a variety of different methods.
BasicTable$formatValue(value = NULL, format = NULL, fmtFuncArgs = NULL)
valueThe value to format.
formatEither a character format string to be used with 'sprintf()', a list of arguments to be used with 'base::format()' or a custom R function which will be invoked once per value to be formatted.
fmtFuncArgsIf 'format' is a custom R function, then 'fmtFuncArgs' specifies any additional arguments (in the form of a list) that will be passed to the custom function.
The formatted value if 'format' is specified, otherwise the 'value' converted to a character value.
addStyle()
Add a new named style to the table.
BasicTable$addStyle(styleName = NULL, declarations = NULL)
styleNameThe name of the new style.
declarationsCSS style declarations in the form of a list, e.g. 'list("font-weight"="bold", "color"="#0000FF")'
The newly created 'TableStyle' object.
createInlineStyle()
Create an inline style that can be used to override a base style. For general use cases, the 'setStyling()' method provides a simpler and more direct way of styling specific parts of a table.
BasicTable$createInlineStyle(baseStyleName = NULL, declarations = NULL)
baseStyleNameThe name of an existing style to base the new style on.
declarationsCSS style declarations in the form of a list, e.g. 'list("font-weight"="bold", "color"="#0000FF")'
Inline styles are typically used to override the style of some specific cells in a table. Inline styles have no name. In HTML, they are rendered as 'style' attributes on specific table cells, where as named styles are linked to cells using the 'class' attribute.
The newly created 'TableStyle' object.
setStyling()
Apply styling to a set of cells in the table.
BasicTable$setStyling( rFrom = NULL, cFrom = NULL, rTo = NULL, cTo = NULL, rowNumbers = NULL, columnNumbers = NULL, cells = NULL, cellType = NULL, visible = NULL, baseStyleName = NULL, style = NULL, declarations = NULL, applyBorderToAdjacentCells = FALSE )
rFromAn integer row number that specifies the start row for the styling changes.
cFromAn integer column number that specifies the start column for the styling changes.
rToAn integer row number that specifies the end row for the styling changes.
cToAn integer column number that specifies the end column for the styling changes.
rowNumbersAn integer vector that specifies the row numbers for the styling changes.
columnNumbersAn integer vector that specifies the column numbers for the styling changes.
cellsA list containing 'TableCell' objects.
cellTypeOne of the following values that specifies the type of cell: root, rowHeader, columnHeader, cell, total. The cellType controls the default styling that is applied to the cell.
visibleThe cell visibility to apply ('TRUE' or 'FALSE').
baseStyleNameThe name of a style to apply.
styleA 'TableStyle' object to apply.
declarationsCSS style declarations to apply in the form of a list, e.g. 'list("font-weight"="bold", "color"="#0000FF")'
applyBorderToAdjacentCellsTRUE to override the border in neighbouring cells, e.g. the left border of the current cell becomes the right border of the cell to the left.
There are five ways to specify the part(s) of a table to apply
styling to:
(1) By specifying a list of data groups using the 'groups' argument.
(2) By specifying a list of cells using the 'cells' argument.
(3) By specifying a single cell using the 'rFrom' and 'cFrom' arguments.
(4) By specifying a rectangular cell range using the 'rFrom', 'cFrom',
'rTo' and 'cTo' arguments.
(5) By specifying a vector of rowNumbers and/or columnNumbers. If both
rowNumbers and columnNumbers are specified, then the cells at the
intersection of the specified row numbers and column numbers are styled.
If both rFrom/rTo and rowNumbers are specified, then rFrom/rTo constrain
the row numbers specified in rowNumbers.
If both cFrom/cTo and columnNumbers are specified, then cFrom/cTo constrain
the column numbers specified in columnNumbers.
See the "Styling" and "Finding and Formatting" vignettes for more
information and many examples.
No return value.
mapStyling()
Apply styling to table cells based on the value of each cell.
BasicTable$mapStyling( styleProperty = NULL, cells = NULL, valueType = "text", mapType = "range", mappings = NULL, styleLowerValues = FALSE, styleHigherValues = TRUE )
stylePropertyThe name of the style property to set on the specified cells, e.g. background-color.
cellsA list containing 'TableCell' objects.
valueTypeThe type of style value to be set. Must be one of:
"text", "character", "number", "numeric", "color" or "colour".
"text" and "character" are equivalent. "number" and "numeric" are equivalent.
"color" and "colour" are equivalent.
mapTypeThe type of mapping to be performed. The following mapping
types are supported:
(1) "value" = a 1:1 mapping which maps each specified "from" value to the
corresponding "to" value, e.g. 100 -> "green".
(2) "logic" = each from value is logical criteria. See details.
(3) "range" = values between each pair of "from" values are mapped to the
corresponding "to" value, e.g. values in the range 80-100 -> "green" (more
specifically values greater than or equal to 80 and less than 100).
(4) "continuous" = rescales values between each pair of "from" values into
the range of the corresponding pair of "to" values, e.g. if the "from" range
is 80-100 and the corresponding "to" range is 0.8-1, then 90 -> 0.9.
"continuous" cannot be used with valueType="text"/"character".
mappingsThe mappings to be applied, specified in one of the following
three forms:
(1) a list containing pairs of values, e.g.
'list(0, "red", 0.4, "yellow", 0.8, "green")'.
(2) a list containing "from" and "to" vectors/lists, e.g.
'list(from=c(0, 0.4, 0.8), to=c("red", "yellow", "green"))'.
(3) a custom mapping function that will be invoked once per cell, e.g.
'function(v, cell) { if(isTRUE(v>0.8)) return("green") }'.
Mappings must be specified in ascending order when valueType="range" or
valueType="continuous".
If a custom mapping function is specified, then the valueType and mapType
parameters are ignored.
styleLowerValuesA logical value, default 'FALSE', that specifies whether values less than the lowest specified "from" value should be styled using the style specified for the lowest "from" value. Only applies when valueType="range" or valueType="continuous".
styleHigherValuesA logical value, default 'TRUE', that specifies whether values greater than the highest specified "from" value should be styled using the style specified for the highest "from" value. Only applies when valueType="range" or valueType="continuous".
'mapStyling()' is typically used to conditionally apply styling to cells
based on the value of each individual cell, e.g. cells with values less
than a specified number could be coloured red.
mapType="logic" maps values matching specified logical criteria to
specific "to" values. The logical criteria can be any of the following
forms (the first matching mapping is used):
(1) a specific value, e.g. 12.
(2) a specific value equality condition, e.g. "v==12", where v
represents the cell value.
(3) a value range expression using the following abbreviated form:
"value1<=v<value2", e.g. "10<=v<15". Only "<" or "<=" can be used
in these value range expressions.
(4) a standard R logical expression, e.g.
"10<=v && v<15".
Basic R functions that test the value can also be
used, e.g. is.na(v).
See the "Styling" and Finding and Formatting" vignettes for more
information and many examples.
No return value.
resetCells()
Clear the cells of the table.
BasicTable$resetCells()
The cells are reset automatically when structural changes are made to the table, so this method often doesn't needs to be called explicitly.
No return value.
getCells()
Retrieve cells by a combination of row and/or column numbers. See the "Finding and Formatting" vignette for graphical examples.
BasicTable$getCells( specifyCellsAsList = TRUE, rowNumbers = NULL, columnNumbers = NULL, cellCoordinates = NULL, excludeEmptyCells = FALSE, matchMode = "simple" )
specifyCellsAsListSpecify how cells are retrieved. Default 'TRUE'. More information is provided in the details section.
rowNumbersA vector of row numbers that specify the rows or cells to retrieve.
columnNumbersA vector of column numbers that specify the columns or cells to retrieve.
cellCoordinatesA list of two-element vectors that specify the coordinates of cells to retrieve. Ignored when 'specifyCellsAsList=FALSE'.
excludeEmptyCellsDefault 'FALSE'. Specify 'TRUE' to exclude empty cells.
matchModeEither "simple" (default) or "combinations":
"simple" specifies that row and column arguments are considered separately
(logical OR), e.g. rowNumbers=1 and columnNumbers=2 will match all cells in
row 1 and all cells in column 2.
"combinations" specifies that row and column arguments are considered together
(logical AND), e.g. rowNumbers=1 and columnNumbers=2 will match only the
cell single at location (1, 2).
Arguments 'rowNumbers' and 'columnNumbers' are
affected by the match mode. All other arguments are not.
When 'specifyCellsAsList=TRUE' (the default):
Get one or more rows by specifying the row numbers as a vector as
the rowNumbers argument and leaving the columnNumbers argument set
to the default value of 'NULL', or
Get one or more columns by specifying the column numbers as a vector
as the columnNumbers argument and leaving the rowNumbers argument
set to the default value of 'NULL', or
Get one or more individual cells by specifying the cellCoordinates
argument as a list of vectors of length 2, where each element in the
list is the row and column number of one cell,
e.g. 'list(c(1, 2), c(3, 4))' specifies two cells, the first located
at row 1, column 2 and the second located at row 3, column 4.
When 'specifyCellsAsList=FALSE':
Get one or more rows by specifying the row numbers as a vector as the
rowNumbers argument and leaving the columnNumbers argument set to the
default value of 'NULL', or
Get one or more columns by specifying the column numbers as a vector
as the columnNumbers argument and leaving the rowNumbers argument set
to the default value of 'NULL', or
Get one or more cells by specifying the row and column numbers as vectors
for the rowNumbers and columnNumbers arguments, or
a mixture of the above, where for entire rows/columns the element in the
other vector is set to 'NA', e.g. to retrieve whole rows, specify the row
numbers as the rowNumbers but set the corresponding elements in the
columnNumbers vector to 'NA'.
A list of 'TableCell' objects.
findCells()
Find cells matching specified criteria. See the "Finding and Formatting" vignette for graphical examples.
BasicTable$findCells( minValue = NULL, maxValue = NULL, exactValues = NULL, valueRanges = NULL, includeNull = TRUE, includeNA = TRUE, emptyCells = "include", rowNumbers = NULL, columnNumbers = NULL, cellCoordinates = NULL, cells = NULL, rowColumnMatchMode = "simple" )
minValueA numerical value specifying a minimum value threshold.
maxValueA numerical value specifying a maximum value threshold.
exactValuesA vector or list specifying a set of allowed values.
valueRangesA vector specifying one or more value range expressions which the cell values must match. If multiple value range expressions are specified, then the cell value must match any of one the specified expressions. See details.
includeNullspecify TRUE to include 'NULL' in the matched cells, FALSE to exclude 'NULL' values.
includeNAspecify TRUE to include 'NA' in the matched cells, FALSE to exclude 'NA' values.
emptyCellsA word that specifies how empty cells are matched - must be one of "include" (default), "exclude" or "only".
rowNumbersA vector of row numbers that specify the rows or cells to constrain the search.
columnNumbersA vector of column numbers that specify the columns or cells to constrain the search.
cellCoordinatesA list of two-element vectors that specify the coordinates of cells to constrain the search.
cellsA 'TableCell' object or a list of 'TableCell' objects to constrain the scope of the search.
rowColumnMatchModeEither "simple" (default) or "combinations":
"simple" specifies that row and column arguments are considered separately
(logical OR), e.g. rowNumbers=1 and columnNumbers=2 will match all cells in
row 1 and all cells in column 2.
"combinations" specifies that row and column arguments are considered together
(logical AND), e.g. rowNumbers=1 and columnNumbers=2 will match only the
cell single at location (1, 2).
Arguments 'rowNumbers', 'columnNumbers', 'rowGroups' and 'columnGroups' are
affected by the match mode. All other arguments are not.
The valueRanges parameter can be any of the following
forms:
(1) a specific value, e.g. 12.
(2) a specific value equality condition, e.g. "v==12", where v
represents the cell value.
(3) a value range expression using the following abbreviated form:
"value1<=v<value2", e.g. "10<=v<15". Only "<" or "<=" can be used
in these value range expressions.
(4) a standard R logical expression, e.g.
"10<=v && v<15".
Basic R functions that test the value can also be
used, e.g. is.na(v).
A list of 'TableCell' objects.
print()
Outputs a plain text representation of the table to the console or returns a character representation of the table.
BasicTable$print(asCharacter = FALSE)
asCharacter'FALSE' (default) outputs to the console, specify 'TRUE' to instead return a character value (does not output to console).
Plain text representation of the table.
asMatrix()
Convert the table to a matrix, with or without headings.
BasicTable$asMatrix( firstRowAsColumnNames = FALSE, firstColumnAsRowNames = FALSE, rawValue = FALSE )
firstRowAsColumnNames'TRUE' to use the first row of the table as the column names in the matrix. Default value 'FALSE'.
firstColumnAsRowNames'TRUE' to use the first column of the table as the row names in the matrix. Default value 'FALSE'.
rawValue'FALSE' (default) outputs the formatted (character) values. Specify 'TRUE' to output the raw cell values.
See the "Outputs" vignette for a comparison of outputs.
A matrix.
asDataFrame()
Convert the table to a data frame, with or without headings.
BasicTable$asDataFrame( firstRowAsColumnNames = FALSE, firstColumnAsRowNames = FALSE, rawValue = FALSE, stringsAsFactors = NULL )
firstRowAsColumnNames'TRUE' to use the first row of the table as the column names in the data frame Default value 'FALSE'.
firstColumnAsRowNames'TRUE' to use the first column of the table as the row names in the data frame. Default value 'FALSE'.
rawValue'FALSE' (default) outputs the formatted (character) values. Specify 'TRUE' to output the raw cell values.
stringsAsFactorsSpecify 'TRUE' to convert strings to factors, default is 'default.stringsAsFactors()' for R < 4.1.0 and 'FALSE' for R >= 4.1.0.
See the "Outputs" vignette for a comparison of outputs.
A matrix.
getCss()
Get the CSS declarations for the table.
BasicTable$getCss(styleNamePrefix = NULL)
styleNamePrefixA character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple tables exist.
See the "Outputs" vignette for more details and examples.
A character value containing the CSS style declaration.
getHtml()
Generate a HTML representation of the table.
BasicTable$getHtml(styleNamePrefix = NULL)
styleNamePrefixA character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple tables exist.
See the "Outputs" vignette for more details and examples.
A list containing HTML tags from the 'htmltools' package. Convert this to a character variable using 'as.character()'.
saveHtml()
Save a HTML representation of the table to file.
BasicTable$saveHtml( filePath = NULL, fullPageHTML = TRUE, styleNamePrefix = NULL )
filePathThe file to save the HTML to.
fullPageHTML'TRUE' (default) includes basic HTML around the table HTML so that the result file is a valid HTML file.
styleNamePrefixA character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple tables exist.
See the "Outputs" vignette for more details and examples.
No return value.
renderTable()
Render a HTML representation of the table as an HTML widget.
BasicTable$renderTable(width = NULL, height = NULL, styleNamePrefix = NULL)
widthThe width of the widget.
heightThe height of the widget.
styleNamePrefixA character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple tables exist.
See the "Outputs" vignette for more details and examples.
A HTML widget from the 'htmlwidgets' package.
writeToExcelWorksheet()
Write the table into the specified workbook and worksheet at the specified row-column location.
BasicTable$writeToExcelWorksheet( wb = NULL, wsName = NULL, topRowNumber = NULL, leftMostColumnNumber = NULL, outputValuesAs = "rawValue", useFormattedValueIfRawValueIsNull = TRUE, applyStyles = TRUE, mapStylesFromCSS = TRUE )
wbA 'Workbook' object representing the Excel file being written to.
wsNameA character value specifying the name of the worksheet to write to.
topRowNumberAn integer value specifying the row number in the Excel worksheet to write the table.
leftMostColumnNumberAn integer value specifying the column number in the Excel worksheet to write the table.
outputValuesAsMust be one of "rawValue" (default), "formattedValueAsText" or "formattedValueAsNumber" to specify how cell values are written into the Excel sheet.
useFormattedValueIfRawValueIsNull'TRUE' to use the formatted cell value instead of the raw cell value if the raw value is 'NULL'. 'FALSE' to always use the raw value. Default 'TRUE'.
applyStylesDefault 'TRUE' to write styling information to cells.
mapStylesFromCSSDefault 'TRUE' to automatically convert CSS style declarations to their Excel equivalents.
See the Excel Output vignette for more details.
No return value.
asFlexTable()
Convert table to a flextable table..
BasicTable$asFlexTable(applyStyles = TRUE, mapStylesFromCSS = TRUE)
applyStylesDefault 'TRUE' to write styling information for cells.
mapStylesFromCSSDefault 'TRUE' to automatically convert CSS style declarations to their flextable equivalents.
See the Outputs vignette for more details.
A table from the flextable package.
trace()
Capture a call for tracing purposes. This is an internal method.
BasicTable$trace(methodName, desc, detailList = NULL)
methodNameThe name of the method being invoked.
descShort description of method call.
detailListA list containing detail such as parameter values.
No return value.
asList()
Return the contents of the table as a list for debugging.
BasicTable$asList()
A list of various object properties..
asJSON()
Return the contents of the table as JSON for debugging.
BasicTable$asJSON()
A JSON representation of various object properties.
viewJSON()
Use the 'listviewer' package to view the table as JSON for debugging.
BasicTable$viewJSON()
No return value.
clone()
The objects of this class are cloneable with this method.
BasicTable$clone(deep = FALSE)
deepWhether to make a deep clone.
# The package vignettes have many more examples of working with the # BasicTable class. # Quickly rendering a table as an htmlwidget: library(basictabler) qhtbl(data.frame(a=1:2, b=3:4)) # Rendering a larger table as an htmlwidget: library(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) tbl <- BasicTable$new() columnHeaders <- c("TOC", "On-Time Arrivals", "On-Time Departures", "Total Trains", "On-Time Arrival %", "On-Time Departure %") columnFormats=list() columnFormats[[2]] <- list(big.mark=",") columnFormats[[3]] <- list(big.mark=",") columnFormats[[4]] <- list(big.mark=",") columnFormats[[5]] <- "%.1f" columnFormats[[6]] <- "%.1f" tbl$addData(tocsummary, columnNamesAsColumnHeaders=FALSE, firstColumnAsRowHeaders=TRUE, explicitColumnHeaders=columnHeaders, columnFormats=columnFormats) tbl$renderTable()# The package vignettes have many more examples of working with the # BasicTable class. # Quickly rendering a table as an htmlwidget: library(basictabler) qhtbl(data.frame(a=1:2, b=3:4)) # Rendering a larger table as an htmlwidget: library(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) tbl <- BasicTable$new() columnHeaders <- c("TOC", "On-Time Arrivals", "On-Time Departures", "Total Trains", "On-Time Arrival %", "On-Time Departure %") columnFormats=list() columnFormats[[2]] <- list(big.mark=",") columnFormats[[3]] <- list(big.mark=",") columnFormats[[4]] <- list(big.mark=",") columnFormats[[5]] <- "%.1f" columnFormats[[6]] <- "%.1f" tbl$addData(tocsummary, columnNamesAsColumnHeaders=FALSE, firstColumnAsRowHeaders=TRUE, explicitColumnHeaders=columnHeaders, columnFormats=columnFormats) tbl$renderTable()
The basictabler function is primarily intended for use with Shiny web
applications.
basictabler(bt, width = NULL, height = NULL, styleNamePrefix = NULL)basictabler(bt, width = NULL, height = NULL, styleNamePrefix = NULL)
bt |
The table to render. |
width |
The target width. |
height |
The target height. |
styleNamePrefix |
A text prefix to be prepennded to the CSS declarations (to ensure uniqueness). |
A HTML widget.
# See the Shiny vignette in this package for an example.# See the Shiny vignette in this package for an example.
Standard function for Shiny scaffolding.
basictablerOutput(outputId, width = "100%", height = "100%")basictablerOutput(outputId, width = "100%", height = "100%")
outputId |
The id of the html element that will contain the htmlwidget. |
width |
The target width of the htmlwidget. |
height |
The target height of the htmlwidget. |
# See the Shiny vignette in this package for an example.# See the Shiny vignette in this package for an example.
The basictablerSample function generates a sample basic table.
basictablerSample()basictablerSample()
Example basic table describing the performance of trains run by different train operating companies in Birmingham (UK).
# Generate sample table. basictablerSample()# Generate sample table. basictablerSample()
A dataset summarising all of the trains that either originated at, passed through or terminated at Birmingham New Street railway station in the UK between 1st December 2016 and 28th February 2017 inclusive.
bhmsummarybhmsummary
A data frame with 4839 rows and 14 variables:
Train status: A=Active, C=Cancelled, R=Reinstated
Train operating company
Express Passenger or Ordinary Passenger
DMU=Diesel Multiple Unit, EMU=Electrical Multiple Unit, HST=High Speed Train
Scheduled maximum speed (in miles per hour)
The month of the train in the Great Britain Train Timetable (GBTT)
The week of the train in the Great Britain Train Timetable (GBTT)
3-letter code denoting the scheduled origin of the train
3-letter code denoting the scheduled destination of the train
The number of scheduled trains
The number of trains that arrived in Birmingham on time
The number of trains that departed Birmingham on time
The total number of delay minutes for arrivals
The total number of delay minutes for departures
https://www.recenttraintimes.co.uk/
checkArgument is a utility function that provides basic assurances
about function argument values and generates standardised error messages when
invalid values are encountered. This function should not be used outside the
basictabler package.
checkArgument( argumentCheckMode, checkDataTypes, className, methodName, argumentValue, isMissing, allowMissing = FALSE, allowNull = FALSE, allowedClasses = NULL, mustBeAtomic = FALSE, allowedListElementClasses = NULL, listElementsMustBeAtomic = FALSE, allowedValues = NULL, minValue = NULL, maxValue = NULL, maxLength = NULL )checkArgument( argumentCheckMode, checkDataTypes, className, methodName, argumentValue, isMissing, allowMissing = FALSE, allowNull = FALSE, allowedClasses = NULL, mustBeAtomic = FALSE, allowedListElementClasses = NULL, listElementsMustBeAtomic = FALSE, allowedValues = NULL, minValue = NULL, maxValue = NULL, maxLength = NULL )
argumentCheckMode |
A number between 0 and 4 specifying the checks to perform. |
checkDataTypes |
A logical value specifying whether the data types should be checked when argumentCheckMode=3 |
className |
The name of the calling class, for inclusion in error messages. |
methodName |
The name of the calling method, for inclusion in error messages. |
argumentValue |
The value to check. |
isMissing |
Whether the argument is missing in the calling function. |
allowMissing |
Whether missing values are permitted. |
allowNull |
Whether null values are permitted. |
allowedClasses |
The names of the allowed classes for argumentValue. |
mustBeAtomic |
Whether the argument value must be atomic. |
allowedListElementClasses |
For argument values that are lists(), the names of the allowed classes for the elements in the list. |
listElementsMustBeAtomic |
For argument values that are lists(), whether the list elements must be atomic. |
allowedValues |
For argument values that must be one value from a set list, the list of allowed values. |
minValue |
For numerical values, the lowest allowed value. |
maxValue |
For numerical values, the highest allowed value. |
maxLength |
For character values, the maximum allowed length (in characters) of the value. |
No return value. If invalid values are encountered, the
stop() function is used to interrupt execution.
cleanCssValue is a utility function that performs some basic cleanup
on CSS attribute values. Leading and trailing whitespace is removed. The
CSS values "initial" and "inherit" are blocked. The function is vectorised
so can be used with arrays.
cleanCssValue(cssValue)cleanCssValue(cssValue)
cssValue |
The value to cleanup. |
The cleaned value.
containsText is a utility function returns TRUE if one text value is
present in another. Case sensitive. If textToSearch is a vector, returns
TRUE if any element contains textToFind.
containsText(textToSearch, textToFind)containsText(textToSearch, textToFind)
textToSearch |
The value to be searched. |
textToFind |
The value to find. |
TRUE if the textToFind value is found.
The 'FlexTableRenderer' class creates a representation of a table using the 'flextable' package. See the Output vignette for more details.
R6Class object.
new()
Create a new 'FlexTableRenderer' object.
FlexTableRenderer$new(parentTable)
parentTableOwning table.
No return value.
writeToCell()
Write a value to a cell, optionally with styling and cell merging.
FlexTableRenderer$writeToCell( ft = NULL, rowNumber = NULL, columnNumber = NULL, totalRowCount = NULL, totalColumnCount = NULL, value = NULL, applyStyles = TRUE, baseStyleName = NULL, style = NULL, mapFromCss = TRUE, mergeRows = NULL, mergeColumns = NULL )
ftThe flextable to write to.
rowNumberThe row number of the cell where the value is to be written.
columnNumberThe column number of the cell where the value is to be written.
totalRowCountUsed when writing the cell border.
totalColumnCountUsed when writing the cell border.
valueThe value to be written. Since the flextable is created from a data frame, this argument can be omitted.
applyStyles'TRUE' (default) to also set the styling of the cell, 'FALSE' to only write the value.
baseStyleNameThe name of the style from the table theme to apply to the cell.
styleA 'TableStyle' object that contains additional styling to apply to the cell.
mapFromCss'TRUE' (default) to map the basictabler CSS styles to corresponding Excel styles, 'FALSE' to apply only the specified xl styles.
mergeRowsIf the cell is to be merged with adjacent cells, then an integer or numeric vector specifying the row numbers of the merged cell. NULL (default) to not merge cells.
mergeColumnsIf the cell is to be merged with adjacent cells, then an integer or numeric vector specifying the column numbers of the merged cell. NULL (default) to not merge cells.
The updated flextable definition.
writeBorder()
Write the borders of a cell.
FlexTableRenderer$writeBorder( ft = NULL, rowNumber = NULL, columnNumber = NULL, totalRowCount = NULL, totalColumnCount = NULL, border = NULL, borderLeft = NULL, borderRight = NULL, borderTop = NULL, borderBottom = NULL )
ftThe flextable to write to.
rowNumberThe row number of the cell where the border is to be written.
columnNumberThe column number of the cell where the border is to be written.
totalRowCountThe total number of rows in the table.
totalColumnCountThe total number of columns in the table.
borderThe border to be applied to all sides of the cell (unless a border is specified using the other arguments).
borderLeftThe border to apply to the left side of the cell.
borderRightThe border to apply to the right side of the cell.
borderTopThe border to apply to the top side of the cell.
borderBottomThe border to apply to the bottom side of the cell.
The updated flextable definition.
asFlexTable()
Convert table to a flextable table.
FlexTableRenderer$asFlexTable(applyStyles = TRUE, mapStylesFromCSS = TRUE)
applyStyles'TRUE' (default) to also set the styling of the cells, 'FALSE' to only write the value.
mapStylesFromCSS'TRUE' (default) to map the basictabler CSS styles to corresponding flextable styles where possible, 'FALSE' to apply only the specified ft styles.
No return value.
clone()
The objects of this class are cloneable with this method.
FlexTableRenderer$clone(deep = FALSE)
deepWhether to make a deep clone.
# This class should not be used by end users. It is an internal class # created only by the BasicTable class. It is used when converting to a # flextable.# This class should not be used by end users. It is an internal class # created only by the BasicTable class. It is used when converting to a # flextable.
The 'FlexTableStyle' class specifies the styling for cells in a table from the flextable package.
R6Class object.
baseStyleNameThe name of the base style in the table.
isBaseStyle'TRUE' when this style is the equivalent of a named style in the table, 'FALSE' if this style has additional settings over and above the base style of the same name.
fontNameThe name of the font (single font name, not a CSS style list).
fontSizeThe size of the font (units: point).
boldTRUE' if text is bold.
italic'TRUE' if text is italic.
bgColorThe background colour for the cell (as a hex value, e.g. #00FF00).
textColorThe color of the text (as a hex value).
hAlignThe horizontal alignment of the text: left, center or right.
vAlignThe vertical alignment of the text: top, middle or bottom.
textRotationThe rotation angle of the text or 255 for vertical.
paddingAllThe padding to apply to all sides of each cell.
paddingLeftThe padding to apply to the left side of each cell.
paddingRightThe padding to apply to the right side of each cell.
paddingTopThe padding to apply to the top of each cell.
paddingBottomThe padding to apply to the bottom of each cell.
borderAllA list (with elements style, color and width) specifying the border settings for all four sides of each cell at once.
borderLeftA list (with elements style, color and width) specifying the border settings for the left border of each cell.
borderRightA list (with elements style, color and width) specifying the border settings for the right border of each cell.
borderTopA list (with elements style, color and width) specifying the border settings for the top border of each cell.
borderBottomA list (with elements style, color and width) specifying the border settings for the bottom border of each cell.
new()
Create a new 'FlexTableStyle' object.
FlexTableStyle$new( parentTable, baseStyleName = NULL, isBaseStyle = NULL, fontName = NULL, fontSize = NULL, bold = NULL, italic = NULL, bgColor = NULL, textColor = NULL, hAlign = NULL, vAlign = NULL, textRotation = NULL, paddingAll = NULL, paddingLeft = NULL, paddingRight = NULL, paddingTop = NULL, paddingBottom = NULL, borderAll = NULL, borderLeft = NULL, borderRight = NULL, borderTop = NULL, borderBottom = NULL )
parentTableOwning table.
baseStyleNameThe name of the base style in the table.
isBaseStyle'TRUE' when this style is the equivalent of a named style in the table, 'FALSE' if this style has additional settings over and above the base style of the same name.
fontNameThe name of the font (single font name, not a CSS style list).
fontSizeThe size of the font (units: point).
bold'TRUE' if text is bold.
italic'TRUE' if text is italic.
bgColorThe background colour for the cell (as a hex value, e.g. #00FF00).
textColorThe color of the text (as a hex value).
hAlignThe horizontal alignment of the text: left, center or right.
vAlignThe vertical alignment of the text: top, middle or bottom.
textRotationThe rotation angle of the text or 255 for vertical.
paddingAllThe padding to apply to all sides of each cell.
paddingLeftThe padding to apply to the left side of each cell.
paddingRightThe padding to apply to the right side of each cell.
paddingTopThe padding to apply to the top of each cell.
paddingBottomThe padding to apply to the bottom of each cell.
borderAllA list (with elements style, color and width) specifying the border settings for all four sides of each cell at once.
borderLeftA list (with elements style, color and width) specifying the border settings for the left border of each cell.
borderRightA list (with elements style, color and width) specifying the border settings for the right border of each cell.
borderTopA list (with elements style, color and width) specifying the border settings for the top border of each cell.
borderBottomA list (with elements style, color and width) specifying the border settings for the bottom border of each cell.
No return value.
isBasicStyleNameMatch()
Check if this style matches the specified base style name.
FlexTableStyle$isBasicStyleNameMatch(baseStyleName = NULL)
baseStyleNameThe style name to compare to.
'TRUE' if the style name matches, 'FALSE' otherwise.
isFullStyleDetailMatch()
Check if this style matches the specified style properties.
FlexTableStyle$isFullStyleDetailMatch( baseStyleName = NULL, isBaseStyle = NULL, fontName = NULL, fontSize = NULL, bold = NULL, italic = NULL, bgColor = NULL, textColor = NULL, hAlign = NULL, vAlign = NULL, textRotation = NULL, paddingAll = NULL, paddingLeft = NULL, paddingRight = NULL, paddingTop = NULL, paddingBottom = NULL, borderAll = NULL, borderLeft = NULL, borderRight = NULL, borderTop = NULL, borderBottom = NULL )
baseStyleNameThe style name to compare to.
isBaseStyleWhether the style being compared to is a base style.
fontNameThe font name to compare to.
fontSizeThe font size to compare to.
boldThe style property bold to compare to.
italicThe style property italic to compare to.
bgColorThe style property bgColor to compare to.
textColorThe style property textColor to compare to.
hAlignThe style property hAlign to compare to.
vAlignThe style property vAlign to compare to.
textRotationThe style property textRotation to compare to.
paddingAllThe padding to apply to all sides of each cell.
paddingLeftThe padding to apply to the left side of each cell.
paddingRightThe padding to apply to the right side of each cell.
paddingTopThe padding to apply to the top of each cell.
paddingBottomThe padding to apply to the bottom of each cell.
borderAllThe style property borderAll to compare to.
borderLeftThe style property borderLeft to compare to.
borderRightThe style property borderRight to compare to.
borderTopThe style property borderTop to compare to.
borderBottomThe style property borderBottom to compare to.
valueFormatThe style value format to compare to.
minColumnWidthThe style property minColumnWidth to compare to.
minRowHeightThe style property minRowHeight to compare to.
'TRUE' if the style matches, 'FALSE' otherwise.
asList()
Return the contents of this object as a list for debugging.
FlexTableStyle$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
FlexTableStyle$asJSON()
A JSON representation of various object properties.
asString()
Return the contents of this object as a string for debugging.
FlexTableStyle$asString()
A character representation of various object properties.
clone()
The objects of this class are cloneable with this method.
FlexTableStyle$clone(deep = FALSE)
deepWhether to make a deep clone.
# This class should only be created by using the functions in the table. # It is not intended to be created by users outside of the table.# This class should only be created by using the functions in the table. # It is not intended to be created by users outside of the table.
The 'FlexTableStyles' class stores a collection of 'FlexTableStyle' style objects.
R6Class object.
countThe number of styles in the collection.
stylesA list of 'FlexTableStyle' objects that comprise the collection.
new()
Create a new 'FlexTableStyles' object.
FlexTableStyles$new(parentTable)
parentTableOwning table.
No return value.
clearStyles()
Clear the collection removing all styles.
FlexTableStyles$clearStyles()
No return value.
findNamedStyle()
Find a style in the collection matching the specified base style name.
FlexTableStyles$findNamedStyle(baseStyleName)
baseStyleNameThe style name to find.
A 'TableTableFlexTbl' object that is the style matching the specified base style name or 'NULL' otherwise.
findOrAddStyle()
Find a style in the collection matching the specified base style name and style properties. If there is no matching style, then optionally add a new style.
FlexTableStyles$findOrAddStyle( action = "findOrAdd", baseStyleName = NULL, isBaseStyle = NULL, style = NULL, mapFromCss = TRUE )
actionThe action to carry out. Must be one of "find", "add" or "findOrAdd" (default).
baseStyleNameThe style name to find/add.
isBaseStyleIs the style to be found/added a base style?
styleA 'TableStyle' object specifying style properties to be found/added.
mapFromCss'TRUE' (default) to map the basictabler CSS styles to corresponding flextable styles, 'FALSE' to apply only the specified ft styles.
A 'TableTableFlexTbl' object that is the style matching the specified base style name or 'NULL' otherwise.
addNamedStyles()
Populate the FlexTbl styles based on the styles defined in the table.
FlexTableStyles$addNamedStyles(mapFromCss = TRUE)
mapFromCss'TRUE' (default) to map the basictabler CSS styles to corresponding Excel styles, 'FALSE' to apply only the specified ft styles.
No return value.
asList()
Return the contents of this object as a list for debugging.
FlexTableStyles$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
FlexTableStyles$asJSON()
A JSON representation of various object properties.
asString()
Return the contents of this object as a string for debugging.
FlexTableStyles$asString(seperator = ", ")
seperatorDelimiter used to combine multiple values into a string.
A character representation of various object properties.
clone()
The objects of this class are cloneable with this method.
FlexTableStyles$clone(deep = FALSE)
deepWhether to make a deep clone.
# This class should not be used by end users. It is an internal class # created only by the BasicTable class. It is used when converting to a # flextable.# This class should not be used by end users. It is an internal class # created only by the BasicTable class. It is used when converting to a # flextable.
Get an empty theme for applying no styling to a table.
getBlankTblTheme(parentTable, themeName = "blank")getBlankTblTheme(parentTable, themeName = "blank")
parentTable |
Owning table. |
themeName |
The name to use as the new theme name. |
A TableStyles object.
Get the compact theme for styling a table.
getCompactTblTheme(parentTable, themeName = "compact")getCompactTblTheme(parentTable, themeName = "compact")
parentTable |
Owning table. |
themeName |
The name to use as the new theme name. |
A TableStyles object.
Get the default theme for styling a table.
getDefaultTblTheme(parentTable, themeName = "default")getDefaultTblTheme(parentTable, themeName = "default")
parentTable |
Owning table. |
themeName |
The name to use as the new theme name. |
A TableStyles object.
getXlBorderFromCssBorder parses the CSS combined border declarations
(i.e. border, border-left, border-right, border-top, border-bottom) and
returns a list containing an openxlsx border style and color as separate
elements.
getFtBorderFromCssBorder(text)getFtBorderFromCssBorder(text)
text |
The border declaration to parse. |
A list containing two elements: width, style and color.
getFtBorderStyleFromCssBorder takes border parameters expressed as a
list (must contain an element named style) and returns a border style that
is compatible with the flextable package.
getFtBorderStyleFromCssBorder(border)getFtBorderStyleFromCssBorder(border)
border |
A list containing an element named style. |
A flextable border style.
getFtBorderStyleFromCssBorder takes border parameters expressed as a
list (must contain an element named style) and returns a border style that
is compatible with the flextable package.
getFtBorderWidthFromCssBorder(border)getFtBorderWidthFromCssBorder(border)
border |
A list containing an element named style. |
A flextable border style.
Get the large plain theme for styling a table.
getLargePlainTblTheme(parentTable, themeName = "largeplain")getLargePlainTblTheme(parentTable, themeName = "largeplain")
parentTable |
Owning table. |
themeName |
The name to use as the new theme name. |
A TableStyles object.
getNextPosition is a utility function that helps when parsing strings
that contain delimiters.
getNextPosition(positions, afterPosition)getNextPosition(positions, afterPosition)
positions |
An ordered numeric vector. |
afterPosition |
The value to start searching after. |
The first value in the array larger than afterPosition.
Get a simple coloured theme that can be used to style a table into a custom colour scheme.
getSimpleColoredTblTheme( parentTable, themeName = "coloredTheme", colors = NULL, fontName = NULL, theme = NULL )getSimpleColoredTblTheme( parentTable, themeName = "coloredTheme", colors = NULL, fontName = NULL, theme = NULL )
parentTable |
Owning table. |
themeName |
The name to use as the new theme name. |
colors |
The set of colours to use when generating the theme (see the Styling vignette for details). This parameter exists for backward compatibility. |
fontName |
The name of the font to use, or a comma separated list (for font-fall-back). This parameter exists for backward compatibility. |
theme |
A simple theme specified in the form of a list. See example for supported list elements (all other elements will be ignored). |
A TableStyles object.
simpleOrangeTheme <- list( fontName="Verdana, Arial", fontSize="0.75em", headerBackgroundColor = "rgb(237, 125, 49)", headerColor = "rgb(255, 255, 255)", cellBackgroundColor = "rgb(255, 255, 255)", cellColor = "rgb(0, 0, 0)", totalBackgroundColor = "rgb(248, 198, 165)", totalColor = "rgb(0, 0, 0)", borderColor = "rgb(198, 89, 17)" ) library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) # then tbl$theme <- simpleOrangeTheme # or theme <- getSimpleColoredTblTheme(tbl, theme=simpleOrangeTheme) # make further changes to the theme tbl$theme <- simpleOrangeTheme # theme set, now render table tbl$renderTable()simpleOrangeTheme <- list( fontName="Verdana, Arial", fontSize="0.75em", headerBackgroundColor = "rgb(237, 125, 49)", headerColor = "rgb(255, 255, 255)", cellBackgroundColor = "rgb(255, 255, 255)", cellColor = "rgb(0, 0, 0)", totalBackgroundColor = "rgb(248, 198, 165)", totalColor = "rgb(0, 0, 0)", borderColor = "rgb(198, 89, 17)" ) library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) # then tbl$theme <- simpleOrangeTheme # or theme <- getSimpleColoredTblTheme(tbl, theme=simpleOrangeTheme) # make further changes to the theme tbl$theme <- simpleOrangeTheme # theme set, now render table tbl$renderTable()
getTblTheme returns the specified theme.
getTblTheme(parentTable, themeName = NULL)getTblTheme(parentTable, themeName = NULL)
parentTable |
Owning table. |
themeName |
The name of the theme to retrieve. |
A TableStyles object.
library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) tbl$theme <- getTblTheme(tbl, "largeplain") tbl$renderTable()library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) tbl$theme <- getTblTheme(tbl, "largeplain") tbl$renderTable()
getXlBorderFromCssBorder parses the CSS combined border declarations
(i.e. border, border-left, border-right, border-top, border-bottom) and
returns a list containing an openxlsx border style and color as separate
elements.
getXlBorderFromCssBorder(text)getXlBorderFromCssBorder(text)
text |
The border declaration to parse. |
A list containing two elements: style and color.
getXlBorderStyleFromCssBorder takes border parameters expressed as a
list (containing elements: width and style) and returns a border style that
is compatible with the openxlsx package.
getXlBorderStyleFromCssBorder(border)getXlBorderStyleFromCssBorder(border)
border |
A list containing elements width and style. |
An openxlsx border style.
isNumericValue is a utility function returns TRUE only when a numeric value
is present. NULL, NA, numeric(0) and integer(0) all return FALSE.
isNumericValue(value)isNumericValue(value)
value |
The value to check. |
TRUE if a numeric value is present.
isTextValue is a utility function returns TRUE only when a text value
is present. NULL, NA, character(0) and "" all return FALSE.
isTextValue(value)isTextValue(value)
value |
The value to check. |
TRUE if a non-blank text value is present.
oneToNull is a utility function that returns NULL when a value of
0 or 1 is passed to it, otherwise it returns the original value.
oneToNULL(value, convertOneToNULL)oneToNULL(value, convertOneToNULL)
value |
The value to check. |
convertOneToNULL |
TRUE to convert 1 to NULL. |
NULL if value==1, otherwise value.
parseColor converts a colour value specified in CSS to a hex based
colour code. Example supported input values/formats/named colours are:
#0080FF, rgb(0, 128, 255), rgba(0, 128, 255, 0.5) and red, green, etc.
parseColor(color)parseColor(color)
color |
The colour to convert. |
The colour as a hex code, e.g. #FF00A0.
parseCssBorder parses the CSS combined border declarations (i.e.
border, border-left, border-right, border-top, border-bottom) and returns a
list containing the width, style and color as separate elements.
parseCssBorder(text)parseCssBorder(text)
text |
The border declaration to parse. |
A list containing three elements: width, style and color.
parseCssSizeToPt will take a CSS style and convert it to points.
Supported input size units are in, cm, mm, pt, pc, px, em,
are converted exactly: in, cm, mm, pt, pc: using 1in = 2.54cm = 25.4mm =
72pt = 6pc. The following are converted approximately: px, em,
approx 1em=16px=12pt and 100
parseCssSizeToPt(size)parseCssSizeToPt(size)
size |
A size specified in common CSS units. |
The size converted to points.
parseCssSizeToPx will take a CSS style and convert it to pixels
Supported input size units are in, cm, mm, pt, pc, px, em,
are converted exactly: in, cm, mm, pt, pc: using 1in = 2.54cm = 25.4mm =
72pt = 6pc. The following are converted approximately: px, em,
approx 1em=16px=12pt and 100
parseCssSizeToPx(size)parseCssSizeToPx(size)
size |
A size specified in common CSS units. |
The size converted to pixels.
parseCssString is a utility function that splits a string into a
vector/array. The function pays attention to text qualifiers (single and
double quotes) so won't split if the delimiter occurs inside a value.
parseCssString(text, separator = ",", removeEmptyString = TRUE)parseCssString(text, separator = ",", removeEmptyString = TRUE)
text |
The text to split. |
separator |
The field separator, default comma. |
removeEmptyString |
TRUE to not return empty string / whitespace values. |
An R vector containing the values from text split up.
parseFtBorder parses the combined ft border declarations (i.e.
ft-border, ft-border-left, ft-border-right, ft-border-top, ft-border-bottom)
and returns a list containing width, style and color as separate elements.
parseFtBorder(text)parseFtBorder(text)
text |
The border declaration to parse. |
A list containing two elements: width, style and color.
parseXlBorder parses the combined xl border declarations (i.e.
xl-border, xl-border-left, xl-border-right, xl-border-top, xl-border-bottom)
and returns a list containing style and color as separate elements.
parseXlBorder(text)parseXlBorder(text)
text |
The border declaration to parse. |
A list containing two elements: style and color.
PxToPt converts pixels to points.
1inch = 72pt = 96px according to W3C.
Ref: https://www.w3.org/TR/css3-values/#absolute-lengths
PxToPt(px)PxToPt(px)
px |
The number of pixels convert. |
The corresponding number of points.
The qhpvt function renders a basic table as a HTML widget with
one line of R.
qhtbl( dataFrameOrMatrix, columnNamesAsColumnHeaders = TRUE, explicitColumnHeaders = NULL, rowNamesAsRowHeaders = FALSE, firstColumnAsRowHeaders = FALSE, explicitRowHeaders = NULL, numberOfColumnsAsRowHeaders = 0, columnFormats = NULL, columnCellTypes = NULL, theme = NULL, replaceExistingStyles = FALSE, tableStyle = NULL, headingStyle = NULL, cellStyle = NULL, totalStyle = NULL, ... )qhtbl( dataFrameOrMatrix, columnNamesAsColumnHeaders = TRUE, explicitColumnHeaders = NULL, rowNamesAsRowHeaders = FALSE, firstColumnAsRowHeaders = FALSE, explicitRowHeaders = NULL, numberOfColumnsAsRowHeaders = 0, columnFormats = NULL, columnCellTypes = NULL, theme = NULL, replaceExistingStyles = FALSE, tableStyle = NULL, headingStyle = NULL, cellStyle = NULL, totalStyle = NULL, ... )
dataFrameOrMatrix |
The data frame or matrix containing the data to be displayed in the table. |
columnNamesAsColumnHeaders |
TRUE to use the data frame column names as the column headers in the table. |
explicitColumnHeaders |
A character vector of column headers. |
rowNamesAsRowHeaders |
TRUE to use the data frame row names as the row headers in the table. |
firstColumnAsRowHeaders |
TRUE to use the first column in the data frame as row headings. |
explicitRowHeaders |
A character vector of row headers. |
numberOfColumnsAsRowHeaders |
The number of columns to be set as row headers. |
columnFormats |
A list containing format specifiers, each of which is either an sprintf() character value, a list of format() arguments or an R function that provides custom formatting logic. |
columnCellTypes |
A vector that is the same length as the number of columns in the data frame, where each element is one of the following values that specifies the type of cell: root, rowHeader, columnHeader, cell, total. The cellType controls the default styling that is applied to the cell. Typically only rowHeader, cell or total would be used. |
theme |
Either the name of a built-in theme (default, largeplain, compact or blank/none) or a list which specifies the default formatting for the table. |
replaceExistingStyles |
TRUE to completely replace the default styling with the specified tableStyle, headingStyle, cellStyle and/or totalStyle |
tableStyle |
A list of CSS style declarations that apply to the table. |
headingStyle |
A list of CSS style declarations that apply to the heading cells in the table. |
cellStyle |
A list of CSS style declarations that apply to the normal cells in the table. |
totalStyle |
A list of CSS style declarations that apply to the total cells in the table. |
... |
Additional arguments, currently compatibility, argumentCheckMode and/or styleNamePrefix. |
A basic table.
qhtbl(bhmsummary[1:5, c("GbttWeekDate", "Origin", "Destination", "TrainCount", "OnTimeArrivals")]) qhtbl(bhmsummary[1:5, c("GbttWeekDate", "Origin", "Destination", "TrainCount", "OnTimeArrivals")], columnNamesAsColumnHeaders=FALSE, explicitColumnHeaders=c("Week", "From", "To", "Trains", "On-Time"))qhtbl(bhmsummary[1:5, c("GbttWeekDate", "Origin", "Destination", "TrainCount", "OnTimeArrivals")]) qhtbl(bhmsummary[1:5, c("GbttWeekDate", "Origin", "Destination", "TrainCount", "OnTimeArrivals")], columnNamesAsColumnHeaders=FALSE, explicitColumnHeaders=c("Week", "From", "To", "Trains", "On-Time"))
The qtbl function builds a basic table with one line of R.
qtbl( dataFrameOrMatrix, columnNamesAsColumnHeaders = TRUE, explicitColumnHeaders = NULL, rowNamesAsRowHeaders = FALSE, firstColumnAsRowHeaders = FALSE, explicitRowHeaders = NULL, numberOfColumnsAsRowHeaders = 0, columnFormats = NULL, columnCellTypes = NULL, theme = NULL, replaceExistingStyles = FALSE, tableStyle = NULL, headingStyle = NULL, cellStyle = NULL, totalStyle = NULL, ... )qtbl( dataFrameOrMatrix, columnNamesAsColumnHeaders = TRUE, explicitColumnHeaders = NULL, rowNamesAsRowHeaders = FALSE, firstColumnAsRowHeaders = FALSE, explicitRowHeaders = NULL, numberOfColumnsAsRowHeaders = 0, columnFormats = NULL, columnCellTypes = NULL, theme = NULL, replaceExistingStyles = FALSE, tableStyle = NULL, headingStyle = NULL, cellStyle = NULL, totalStyle = NULL, ... )
dataFrameOrMatrix |
The data frame or matrix containing the data to be displayed in the table. |
columnNamesAsColumnHeaders |
TRUE to use the data frame column names as the column headers in the table. |
explicitColumnHeaders |
A character vector of column headers. |
rowNamesAsRowHeaders |
TRUE to use the data frame row names as the row headers in the table. |
firstColumnAsRowHeaders |
TRUE to use the first column in the data frame as row headings. |
explicitRowHeaders |
A character vector of row headers. |
numberOfColumnsAsRowHeaders |
The number of columns to be set as row headers. |
columnFormats |
A list containing format specifiers, each of which is either an sprintf() character value, a list of format() arguments or an R function that provides custom formatting logic. |
columnCellTypes |
A vector that is the same length as the number of columns in the data frame, where each element is one of the following values that specifies the type of cell: root, rowHeader, columnHeader, cell, total. The cellType controls the default styling that is applied to the cell. Typically only rowHeader, cell or total would be used. |
theme |
Either the name of a built-in theme (default, largeplain, compact or blank/none) or a list which specifies the default formatting for the table. |
replaceExistingStyles |
TRUE to completely replace the default styling with the specified tableStyle, headingStyle, cellStyle and/or totalStyle |
tableStyle |
A list of CSS style declarations that apply to the table. |
headingStyle |
A list of CSS style declarations that apply to the heading cells in the table. |
cellStyle |
A list of CSS style declarations that apply to the normal cells in the table. |
totalStyle |
A list of CSS style declarations that apply to the total cells in the table. |
... |
Additional arguments, currently compatibility and/or argumentCheckMode. |
A basic table.
qtbl(bhmsummary[1:5, c("GbttWeekDate", "Origin", "Destination", "TrainCount", "OnTimeArrivals")]) qtbl(bhmsummary[1:5, c("GbttWeekDate", "Origin", "Destination", "TrainCount", "OnTimeArrivals")], columnNamesAsColumnHeaders=FALSE, explicitColumnHeaders=c("Week", "From", "To", "Trains", "On-Time"))qtbl(bhmsummary[1:5, c("GbttWeekDate", "Origin", "Destination", "TrainCount", "OnTimeArrivals")]) qtbl(bhmsummary[1:5, c("GbttWeekDate", "Origin", "Destination", "TrainCount", "OnTimeArrivals")], columnNamesAsColumnHeaders=FALSE, explicitColumnHeaders=c("Week", "From", "To", "Trains", "On-Time"))
Standard function for Shiny scaffolding.
renderBasictabler(expr, env = parent.frame(), quoted = FALSE)renderBasictabler(expr, env = parent.frame(), quoted = FALSE)
expr |
The R expression to execute and render in the Shiny web application. |
env |
Standard shiny argument for a render function. |
quoted |
Standard shiny argument for a render function. |
# See the Shiny vignette in this package for an example.# See the Shiny vignette in this package for an example.
The 'TableCell' class represents a cell in a table. Both header cells and body cells are represented by this class.
R6Class object.
instanceIdAn integer value that uniquely identifies this cell. NB: This number is guaranteed to be unique within the table, but the method of generation of the values may change in future, so you are advised not to base any logic on specific values.
cellTypeOne of the following values that specifies the type of cell: root, rowHeader, columnHeader, cell, total. The cellType controls the default styling that is applied to the cell.
rowNumberThe row number of the cell. 1 = the first (i.e. top) data row.
columnNumberThe column number of the cell. 1 = the first (i.e. leftmost) data column.
visibleTRUE or FALSE to specify whether the cell is rendered.
rawValueThe original unformatted value.
formattedValueThe formatted value (i.e. normally of character data type).
asNBSPTRUE or FALSE to specify whether cells with no formatted value be output as html nbsp.
fValueOrNBSPFor internal use by the renderers only.
isMergedFor internal use by the renderers only.
isMergeRootFor internal use by the renderers only.
mergeIndexFor internal use by the renderers only.
baseStyleNameThe name of the style applied to this cell (a character value). The style must exist in the TableStyles object associated with the table.
styleA TableStyle object that can apply overrides to the base style for this cell.
new()
Create a new 'TableCell' object.
TableCell$new( parentTable, rowNumber = NULL, columnNumber = NULL, cellType = "cell", visible = TRUE, rawValue = NULL, formattedValue = NULL, baseStyleName = NULL, styleDeclarations = NULL, asNBSP = FALSE )
parentTableOwning table.
rowNumberThe row number of the cell. 1 = the first (i.e. top) data row.
columnNumberThe column number of the cell. 1 = the first (i.e. leftmost) data column.
cellTypeOne of the following values that specifies the type of cell: root, rowHeader, columnHeader, cell, total. The cellType controls the default styling that is applied to the cell.
visible'TRUE' or 'FALSE' to specify whether the cell is rendered.
rawValueThe original unformatted value.
formattedValueThe formatted value (i.e. normally of character data type).
baseStyleNameThe name of the style applied to this cell (a character value). The style must exist in the TableStyles object associated with the table.
styleDeclarationsA list containing CSS style declarations.
asNBSP'TRUE' or 'FALSE' to specify whether cells with no formatted value be output as html nbsp.
No return value.
updatePosition()
Set the cell location in the table. Mainly exists for internal use. Typically used after rows/columns/cells are inserted or deleted (which shifts other cells).
TableCell$updatePosition(rowNumber = NULL, columnNumber = NULL)
rowNumberThe row number of the cell. 1 = the first (i.e. top) data row.
columnNumberThe column number of the cell. 1 = the first (i.e. leftmost) data column.
No return value.
getCopy()
Stub only (ignore).
TableCell$getCopy()
No return value.
asList()
Return the contents of this object as a list for debugging.
TableCell$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
TableCell$asJSON()
A JSON representation of various object properties.
clone()
The objects of this class are cloneable with this method.
TableCell$clone(deep = FALSE)
deepWhether to make a deep clone.
# This class should only be created by using the functions in the table. # It is not intended to be created by users outside of the table. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) cell1 <- tbl$cells$setCell(r=4, c=1, cellType="cell", rawValue=5) cell2 <- tbl$cells$setCell(r=4, c=2, cellType="cell", rawValue=6) tbl$renderTable()# This class should only be created by using the functions in the table. # It is not intended to be created by users outside of the table. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) cell1 <- tbl$cells$setCell(r=4, c=1, cellType="cell", rawValue=5) cell2 <- tbl$cells$setCell(r=4, c=2, cellType="cell", rawValue=6) tbl$renderTable()
The 'TableCellRanges' class contains a list of cell ranges and provides basic utility methods such as finding intersecting ranges to support the functioning of the 'BasicTable' class.
R6Class object.
rangesA list of cell ranges - where each element in the list is another list containing the range extent.
new()
Create a new 'TableCellRanges' object.
TableCellRanges$new(parentTable)
parentTableOwning table.
No return value.
addRange()
Add a cell range to the list of cell ranges. It is not necessary to specify all parameters. rFrom and cFrom must be specified. Only one of rSpan and rTo needs to be specified. Only one of cSpan and cTo needs to be specified.
TableCellRanges$addRange( rFrom = NULL, cFrom = NULL, rSpan = NULL, cSpan = NULL, rTo = NULL, cTo = NULL )
rFromRow number of the top-left cell in the cell range.
cFromColumn number of the top-left cell in the cell range.
rSpanNumber of rows spanned by the cell range.
cSpanNumber of columns spanned by the cell range.
rToRow number of the bottom-right cell in the cell range.
cToColumn number of the bottom-right cell in the cell range.
No return value.
findIntersectingRange()
Find a cell range in the list of cell ranges that intersects with the specified cell range. It is not necessary to specify all parameters. rFrom and cFrom must be specified. Only one of rSpan and rTo needs to be specified. Only one of cSpan and cTo needs to be specified.
TableCellRanges$findIntersectingRange( rFrom = NULL, cFrom = NULL, rSpan = NULL, cSpan = NULL, rTo = NULL, cTo = NULL )
rFromRow number of the top-left cell in the cell range.
cFromColumn number of the top-left cell in the cell range.
rSpanNumber of rows spanned by the cell range.
cSpanNumber of columns spanned by the cell range.
rToRow number of the bottom-right cell in the cell range.
cToColumn number of the bottom-right cell in the cell range.
No return value.
deleteRange()
Delete the cell range from the list that contains the specified cell.
TableCellRanges$deleteRange(r = NULL, c = NULL)
rRow number of a cell in the cell range to be deleted.
cColumn number of a cell in the cell range to be deleted.
No return value.
clear()
Clear the list of cell ranges.
TableCellRanges$clear()
No return value.
updateAfterRowInsert()
Internal use only.
TableCellRanges$updateAfterRowInsert(r = NULL)
rRow number.
No return value.
updateAfterRowDelete()
Internal use only.
TableCellRanges$updateAfterRowDelete(r = NULL)
rRow number.
No return value.
updateAfterColumnInsert()
Internal use only.
TableCellRanges$updateAfterColumnInsert(c = NULL)
cColumn number.
No return value.
updateAfterColumnDelete()
Internal use only.
TableCellRanges$updateAfterColumnDelete(c = NULL)
cColumn number.
No return value.
asList()
Return the contents of this object as a list for debugging.
TableCellRanges$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
TableCellRanges$asJSON()
A JSON representation of various object properties.
clone()
The objects of this class are cloneable with this method.
TableCellRanges$clone(deep = FALSE)
deepWhether to make a deep clone.
# TableCellRanges objects are never created outside of the BasicTable class. # For examples of working with merged cells, see the Introduction vignette.# TableCellRanges objects are never created outside of the BasicTable class. # For examples of working with merged cells, see the Introduction vignette.
The 'TableCells' manages the 'TableCell' objects that comprise a 'BasicTable' object.
R6Class object.
rowCountThe number of rows in the table.
columnCountThe number of columns in the table.
rowsThe rows of cells in the table - represented as a list, each element of which is a list of 'TableCell' objects.
allA list of the cells in the table. Each element in this list is a 'TableCell' object.
new()
Create a new 'TableCells' object.
TableCells$new(parentTable = NULL)
parentTableOwning table.
No return value.
reset()
Clear all cells from the table.
TableCells$reset()
No return value.
getCell()
Retrieve a specific 'TableCell' object at the specified location in the table.
TableCells$getCell(r = NULL, c = NULL)
rThe row number of the cell to retrieve.
cThe column number of the cell to retrieve.
A 'TableCell' object.
getValue()
Retrieve the value of a specific 'TableCell' object at the specified location in the table.
TableCells$getValue(r = NULL, c = NULL, formattedValue = FALSE)
rThe row number of the cell value to retrieve.
cThe column number of the cell value to retrieve.
formattedValue'TRUE' to retrieve the formatted (character) cell value, 'FALSE' (default) to retrieve the raw cell value (typically numeric).
The value of the cell.
getRowValues()
Get a vector or list of the values in a row for the entire row or a subset of columns.
TableCells$getRowValues( rowNumber = NULL, columnNumbers = NULL, formattedValue = FALSE, asList = FALSE, rebase = TRUE )
rowNumberThe row number to retrieve the values for (a single row number).
columnNumbersThe column numbers of the cell value to retrieve (can be a vector of column numbers).
formattedValue'TRUE' to retrieve the formatted (character) cell value, 'FALSE' (default) to retrieve the raw cell value (typically numeric).
asList'TRUE' to retrieve the values as a list, 'FALSE' (default) to retrieve the values as a vector.
rebase'TRUE' to rebase the list/vector so that the first element is at index 1, 'FALSE' to retain the original column numbers.
A vector or list of the cell values.
getColumnValues()
Get a vector or list of the values in a column for the entire column or a subset of rows.
TableCells$getColumnValues( columnNumber = NULL, rowNumbers = NULL, formattedValue = FALSE, asList = FALSE, rebase = TRUE )
columnNumberThe column number to retrieve the values for (a single column number).
rowNumbersThe row numbers of the cell value to retrieve (can be a vector of row numbers).
formattedValue'TRUE' to retrieve the formatted (character) cell value, 'FALSE' (default) to retrieve the raw cell value (typically numeric).
asList'TRUE' to retrieve the values as a list, 'FALSE' (default) to retrieve the values as a vector.
rebase'TRUE' to rebase the list/vector so that the first element is at index 1, 'FALSE' to retain the original row numbers.
A vector or list of the cell values.
setCell()
Create a cell in the table and set the details of the cell.
TableCells$setCell( r = NULL, c = NULL, cellType = "cell", rawValue = NULL, formattedValue = NULL, visible = TRUE, baseStyleName = NULL, styleDeclarations = NULL, rowSpan = NULL, colSpan = NULL )
rThe row number of the cell.
cThe column number of the cell.
cellTypeThe type of the cell - must be one of the following values: root, rowHeader, columnHeader, cell, total.
rawValueThe raw value of the cell - typically a numeric value.
formattedValueThe formatted value of the cell - typically a character value.
visible'TRUE' (default) to specify that the cell is visible, 'FALSE' to specify that the cell will be invisible.
baseStyleNameThe name of a style from the table theme that will be used to style this cell.
styleDeclarationsA list of CSS style definitions.
rowSpanA number greater than 1 to indicate that this cell is merged with cells below. 'NULL' (default) or 1 means the cell is not merged across rows.
colSpanA number greater than 1 to indicate that this cell is merged with cells to the right. 'NULL' (default) or 1 means the cell is not merged across columns.
A vector or list of the cell values.
setBlankCell()
Create an empty cell in the table and set the details of the cell.
TableCells$setBlankCell( r = NULL, c = NULL, cellType = "cell", visible = TRUE, baseStyleName = NULL, styleDeclarations = NULL, rowSpan = NULL, colSpan = NULL, asNBSP = FALSE )
rThe row number of the cell.
cThe column number of the cell.
cellTypeThe type of the cell - must be one of the following values: root, rowHeader, columnHeader, cell, total.
visible'TRUE' (default) to specify that the cell is visible, 'FALSE' to specify that the cell will be invisible.
baseStyleNameThe name of a style from the table theme that will be used to style this cell.
styleDeclarationsA list of CSS style definitions.
rowSpanA number greater than 1 to indicate that this cell is merged with cells below. 'NULL' (default) or 1 means the cell is not merged across rows.
colSpanA number greater than 1 to indicate that this cell is merged with cells to the right. 'NULL' (default) or 1 means the cell is not merged across columns.
asNBSP'TRUE' if the cell should be rendered as in HTML, 'FALSE' (default) otherwise.
A vector or list of the cell values.
deleteCell()
Replace the 'TableCell' object at the specified location in the table with a blank cell.
TableCells$deleteCell(r = NULL, c = NULL)
rThe row number of the cell value to delete
cThe column number of the cell value to delete
The 'TableCell' object that is the new blank cell.
setValue()
Update the value of a cell in the table.
TableCells$setValue(r = NULL, c = NULL, rawValue = NULL, formattedValue = NULL)
rThe row number of the cell.
cThe column number of the cell.
rawValueThe raw value of the cell - typically a numeric value.
formattedValueThe formatted value of the cell - typically a character value.
No return value.
setRow()
Create multiple cells in one row of a table.
TableCells$setRow( rowNumber = NULL, startAtColumnNumber = 1, cellTypes = "cell", rawValues = NULL, formattedValues = NULL, formats = NULL, visiblity = TRUE, baseStyleNames = NULL, fmtFuncArgs = NULL )
rowNumberThe row number where the cells will be created.
startAtColumnNumberThe column number to start generating cells at. Default value 1.
cellTypesThe types of the cells - either a single value or a vector of the same length as rawValues. Each cellType must be one of the following values: root, rowHeader, columnHeader, cell, total.
rawValuesA vector or list of values. A cell will be generated in the table for each element in the vector/list.
formattedValuesA vector or list of formatted values. Must be either 'NULL', a single value or a vector/list of the same length as rawValues.
formatsA vector or list of formats. Must be either 'NULL', a single value or a vector/list of the same length as rawValues.
visiblityA logical vector. Must be either a single logical value or a vector/list of the same length as rawValues.
baseStyleNamesA character vector. Must be either a single style name (from the table theme) or a vector of style names of the same length as rawValues.
fmtFuncArgsA list that is length 1 or the same length as the number of columns in the row, where each list element specifies a list of arguments to pass to custom R format functions.
No return value.
setColumn()
Create multiple cells in one column of a table.
TableCells$setColumn( columnNumber = NULL, startAtRowNumber = 2, cellTypes = "cell", rawValues = NULL, formattedValues = NULL, formats = NULL, visiblity = TRUE, baseStyleNames = NULL, fmtFuncArgs = NULL )
columnNumberThe column number where the cells will be created.
startAtRowNumberThe row number to start generating cells at. Default value 2.
cellTypesThe types of the cells - either a single value or a vector of the same length as rawValues. Each cellType must be one of the following values: root, rowHeader, columnHeader, cell, total.
rawValuesA vector or list of values. A cell will be generated in the table for each element in the vector/list.
formattedValuesA vector or list of formatted values. Must be either 'NULL', a single value or a vector of the same length as rawValues.
formatsA vector or list of formats. Must be either 'NULL', a single value or a vector of the same length as rawValues.
visiblityA logical vector. Must be either a single logical value or a vector of the same length as rawValues.
baseStyleNamesA character vector. Must be either a single style name (from the table theme) or a vector of style names of the same length as rawValues.
fmtFuncArgsA list that is length 1 or the same length as the number of rows in the column, where each list element specifies a list of arguments to pass to custom R format functions.
No return value.
extendCells()
Enlarge a table to the specified size.
TableCells$extendCells(rowCount = NULL, columnCount = NULL)
rowCountThe number of rows in the enlarged table.
columnCountThe number of columns in the enlarged table.
No return value.
moveCell()
Move a table cell to a different location in the table.
TableCells$moveCell(r = NULL, c = NULL, cell = NULL)
rThe new row number to move the cell to.
cThe new column number to move the cell to.
cellThe 'TableCell' object to move.
No return value.
insertRow()
Insert a new row in the table at the specified row number and shift existing cells on/below this row down by one row.
TableCells$insertRow( rowNumber = NULL, insertBlankCells = TRUE, headerCells = 1, totalCells = 0 )
rowNumberThe row number where the new row is to be inserted.
insertBlankCells'TRUE' (default) to insert blank cells in the new row, 'FALSE' to create no cells in the new row.
headerCellsThe number of header cells to create at the start of the row. Default value 1.
totalCellsThe number of total cells to create at the end of the row. Default value 0.
No return value.
deleteRow()
Delete the row in the table at the specified row number and shift existing cells below this row up by one row.
TableCells$deleteRow(rowNumber = NULL)
rowNumberThe row number of the row to be deleted.
No return value.
insertColumn()
Insert a new column in the table at the specified column number and shift existing cells in/to the right of this column across by one row.
TableCells$insertColumn( columnNumber = NULL, insertBlankCells = TRUE, headerCells = 1, totalCells = 0 )
columnNumberThe column number where the new column is to be inserted.
insertBlankCells'TRUE' (default) to insert blank cells in the new column, 'FALSE' to create no cells in the new column
headerCellsThe number of header cells to create at the top of the column. Default value 1.
totalCellsThe number of total cells to create at the bottom of the column. Default value 0.
No return value.
deleteColumn()
Delete the column in the table at the specified column number and shift existing cells to the right of this column to the left by one column.
TableCells$deleteColumn(columnNumber = NULL)
columnNumberThe column number of the column to be deleted.
No return value.
getCells()
Retrieve cells by a combination of row and/or column numbers. See the "Finding and Formatting" vignette for graphical examples.
TableCells$getCells( specifyCellsAsList = TRUE, rowNumbers = NULL, columnNumbers = NULL, cellCoordinates = NULL, excludeEmptyCells = FALSE, matchMode = "simple" )
specifyCellsAsList'TRUE'/'FALSE' to specify how cells are retrieved. Default 'TRUE'. More information is provided in the details section.
rowNumbersA vector of row numbers that specify the rows or cells to retrieve.
columnNumbersA vector of row numbers that specify the columns or cells to retrieve.
cellCoordinatesA list of two-element vectors that specify the coordinates of cells to retrieve. Ignored when 'specifyCellsAsList=FALSE'.
excludeEmptyCellsDefault 'FALSE'. Specify 'TRUE' to exclude empty cells.
matchModeEither "simple" (default) or "combinations"
"simple" specifies that row and column arguments are considered separately
(logical OR), e.g. rowNumbers=1 and columnNumbers=2 will match all cells in
row 1 and all cells in column 2.
"combinations" specifies that row and column arguments are considered together
(logical AND), e.g. rowNumbers=1 and columnNumbers=2 will match only the
cell single at location (1, 2).
Arguments 'rowNumbers', 'columnNumbers', 'rowGroups' and 'columnGroups' are
affected by the match mode. All other arguments are not.
When 'specifyCellsAsList=TRUE' (the default):
Get one or more rows by specifying the row numbers as a vector as
the rowNumbers argument and leaving the columnNumbers argument set
to the default value of 'NULL', or
Get one or more columns by specifying the column numbers as a vector
as the columnNumbers argument and leaving the rowNumbers argument
set to the default value of 'NULL', or
Get one or more individual cells by specifying the cellCoordinates
argument as a list of vectors of length 2, where each element in the
list is the row and column number of one cell,
e.g. 'list(c(1, 2), c(3, 4))' specifies two cells, the first located
at row 1, column 2 and the second located at row 3, column 4.
When 'specifyCellsAsList=FALSE':
Get one or more rows by specifying the row numbers as a vector as the
rowNumbers argument and leaving the columnNumbers argument set to the
default value of 'NULL', or
Get one or more columns by specifying the column numbers as a vector
as the columnNumbers argument and leaving the rowNumbers argument set
to the default value of 'NULL', or
Get one or more cells by specifying the row and column numbers as vectors
for the rowNumbers and columnNumbers arguments, or
a mixture of the above, where for entire rows/columns the element in the
other vector is set to 'NA', e.g. to retrieve whole rows, specify the row
numbers as the rowNumbers but set the corresponding elements in the
columnNumbers vector to 'NA'.
A list of 'TableCell' objects.
findCells()
Find cells matching specified criteria. See the "Finding and Formatting" vignette for graphical examples.
TableCells$findCells( minValue = NULL, maxValue = NULL, exactValues = NULL, valueRanges = NULL, includeNull = TRUE, includeNA = TRUE, emptyCells = "include", rowNumbers = NULL, columnNumbers = NULL, cellCoordinates = NULL, cells = NULL, rowColumnMatchMode = "simple" )
minValueA numerical value specifying a minimum value threshold.
maxValueA numerical value specifying a maximum value threshold.
exactValuesA vector or list specifying a set of allowed values.
valueRangesA vector specifying one or more value range expressions which the cell values must match. If multiple value range expressions are specified, then the cell value must match any of one the specified expressions.
includeNullSpecify TRUE to include 'NULL' in the matched cells, FALSE to exclude 'NULL' values.
includeNASpecify TRUE to include 'NA' in the matched cells, FALSE to exclude 'NA' values.
emptyCellsA word that specifies how empty cells are matched - must be one of "include" (default), "exclude" or "only".
rowNumbersA vector of row numbers that specify the rows or cells to constrain the search.
columnNumbersA vector of column numbers that specify the columns or cells to constrain the search.
cellCoordinatesA list of two-element vectors that specify the coordinates of cells to constrain the search.
cellsA 'TableCell' object or a list of 'TableCell' objects to constrain the scope of the search.
rowColumnMatchModeEither "simple" (default) or "combinations":
"simple" specifies that row and column arguments are considered separately
(logical OR), e.g. rowNumbers=1 and columnNumbers=2 will match all cells in
row 1 and all cells in column 2.
"combinations" specifies that row and column arguments are considered together
(logical AND), e.g. rowNumbers=1 and columnNumbers=2 will match only the
cell single at location (1, 2).
Arguments 'rowNumbers', 'columnNumbers', 'rowGroups' and 'columnGroups' are
affected by the match mode. All other arguments are not.
A list of 'TableCell' objects.
getColumnWidths()
Retrieve the width of the longest value (in characters) in each column.
TableCells$getColumnWidths()
The width of the column in characters.
asList()
Return the contents of this object as a list for debugging.
TableCells$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
TableCells$asJSON()
A JSON representation of various object properties.
clone()
The objects of this class are cloneable with this method.
TableCells$clone(deep = FALSE)
deepWhether to make a deep clone.
# This class should only be created by the table. # It is not intended to be created outside of the table. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) cells <- tbl$cells cells$setCell(r=4, c=1, cellType="cell", rawValue=5) cells$setCell(r=4, c=2, cellType="cell", rawValue=6) tbl$renderTable()# This class should only be created by the table. # It is not intended to be created outside of the table. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) cells <- tbl$cells cells$setCell(r=4, c=1, cellType="cell", rawValue=5) cells$setCell(r=4, c=2, cellType="cell", rawValue=6) tbl$renderTable()
The 'TableHtmlRenderer' class creates a HTML representation of a table.
R6Class object.
new()
Create a new 'TableHtmlRenderer' object.
TableHtmlRenderer$new(parentTable)
parentTableOwning table.
No return value.
getTableHtml()
Generate a HTML representation of the table.
TableHtmlRenderer$getTableHtml(styleNamePrefix = NULL)
styleNamePrefixA character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple tables exist.
A list containing HTML tags from the 'htmltools' package. Convert this to a character variable using 'as.character()'.
clone()
The objects of this class are cloneable with this method.
TableHtmlRenderer$clone(deep = FALSE)
deepWhether to make a deep clone.
# This class is for internal use only. It is # created only by the BasicTable class when rendering to HTML. # See the package vignettes for more information about outputs. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) tbl$renderTable()# This class is for internal use only. It is # created only by the BasicTable class when rendering to HTML. # See the package vignettes for more information about outputs. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) tbl$renderTable()
The 'TableOpenXlsxRenderer' class creates a representation of a table in an Excel file using the 'openxlsx' package. See the Excel Output vignette for more details.
R6Class object.
new()
Create a new 'TableOpenXlsxRenderer' object.
TableOpenXlsxRenderer$new(parentTable)
parentTableOwning table.
No return value.
writeToCell()
Write a value to a cell, optionally with styling and cell merging.
TableOpenXlsxRenderer$writeToCell( wb = NULL, wsName = NULL, rowNumber = NULL, columnNumber = NULL, value = NULL, applyStyles = TRUE, baseStyleName = NULL, style = NULL, mapFromCss = TRUE, mergeRows = NULL, mergeColumns = NULL )
wbA workbook object from the openxlsx package.
wsNameThe name of the worksheet where the value is to be written.
rowNumberThe row number of the cell where the value is to be written.
columnNumberThe column number of the cell where the value is to be written.
valueThe value to be written.
applyStyles'TRUE' (default) to also set the styling of the cell, 'FALSE' to only write the value.
baseStyleNameThe name of the style from the table theme to apply to the cell.
styleA 'TableStyle' object that contains additional styling to apply to the cell.
mapFromCss'TRUE' (default) to map the basictabler CSS styles to corresponding Excel styles, 'FALSE' to apply only the specified xl styles.
mergeRowsIf the cell is to be merged with adjacent cells, then an integer or numeric vector specifying the row numbers of the merged cell. NULL (default) to not merge cells.
mergeColumnsIf the cell is to be merged with adjacent cells, then an integer or numeric vector specifying the column numbers of the merged cell. NULL (default) to not merge cells.
No return value.
writeToWorksheet()
Write a table to an Excel worksheet.
TableOpenXlsxRenderer$writeToWorksheet( wb = NULL, wsName = NULL, topRowNumber = NULL, leftMostColumnNumber = NULL, outputValuesAs = "rawValue", useFormattedValueIfRawValueIsNull = TRUE, applyStyles = TRUE, mapStylesFromCSS = TRUE )
wbA workbook object from the openxlsx package.
wsNameThe name of the worksheet where the value is to be written.
topRowNumberThe row number of the top-left cell where the table is to be written.
leftMostColumnNumberThe column number of the top-left cell where the table is to be written.
outputValuesAsSpecify whether the raw or formatted values should be written to the worksheet. Value must be one of "rawValue", "formattedValueAsText", "formattedValueAsNumber".
useFormattedValueIfRawValueIsNull'TRUE' to use the formatted cell value instead of the raw cell value if the raw value is 'NULL'. 'FALSE' to always use the raw value. Default 'TRUE'.
applyStyles'TRUE' (default) to also set the styling of the cells, 'FALSE' to only write the value.
mapStylesFromCSS'TRUE' (default) to map the basictabler CSS styles to corresponding Excel styles, 'FALSE' to apply only the specified xl styles.
No return value.
clone()
The objects of this class are cloneable with this method.
TableOpenXlsxRenderer$clone(deep = FALSE)
deepWhether to make a deep clone.
# This class is for internal use only. It is # created only by the BasicTable class when rendering to Excel. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) library(openxlsx) wb <- createWorkbook(creator = Sys.getenv("USERNAME")) addWorksheet(wb, "Data") tbl$writeToExcelWorksheet(wb=wb, wsName="Data", topRowNumber=1, leftMostColumnNumber=1, applyStyles=TRUE, mapStylesFromCSS=TRUE) # Use saveWorkbook() to save the Excel file.# This class is for internal use only. It is # created only by the BasicTable class when rendering to Excel. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) library(openxlsx) wb <- createWorkbook(creator = Sys.getenv("USERNAME")) addWorksheet(wb, "Data") tbl$writeToExcelWorksheet(wb=wb, wsName="Data", topRowNumber=1, leftMostColumnNumber=1, applyStyles=TRUE, mapStylesFromCSS=TRUE) # Use saveWorkbook() to save the Excel file.
The 'TableOpenXlsxStyle' class specifies the styling for cells in an Excel worksheet.
R6Class object.
baseStyleNameThe name of the base style in the table.
isBaseStyle'TRUE' when this style is the equivalent of a named style in the table, 'FALSE' if this style has additional settings over and above the base style of the same name.
fontNameThe name of the font (single font name, not a CSS style list).
fontSizeThe size of the font (units: point).
boldTRUE' if text is bold.
italic'TRUE' if text is italic.
underline'TRUE' if text is underlined.
strikethrough'TRUE' if text has a line through it.
superscript'TRUE' if text is small and raised.
subscript'TRUE' if text is small and lowered.
fillColorThe background colour for the cell (as a hex value, e.g. #00FF00).
textColorThe color of the text (as a hex value).
hAlignThe horizontal alignment of the text: left, center or right.
vAlignThe vertical alignment of the text: top, middle or bottom.
wrapTextTRUE if the text is allowed to wrap onto multiple lines.
textRotationThe rotation angle of the text or 255 for vertical.
indentThe text indentation.
borderAllA list (with elements style and color) specifying the border settings for all four sides of each cell at once.
borderLeftA list (with elements style and color) specifying the border settings for the left border of each cell.
borderRightA list (with elements style and color) specifying the border settings for the right border of each cell.
borderTopA list (with elements style and color) specifying the border settings for the top border of each cell.
borderBottomA list (with elements style and color) specifying the border settings for the bottom border of each cell.
valueFormatThe Excel formatting applied to the field value. One of the following values: "GENERAL", "NUMBER", "CURRENCY", "ACCOUNTING", "DATE", "LONGDATE", TIME, "PERCENTAGE", "FRACTION", "SCIENTIFIC", "TEXT", "COMMA". Or for dates/datetimes, a combination of d, m, y. Or for numeric values, use 0.00 etc.
minColumnWidthThe minimum width of this column.
minRowHeightThe minimum height of this row.
openxlsxStyleThe return value from openxlsx::createStyle().
new()
Create a new 'TableOpenXlsxStyle' object.
TableOpenXlsxStyle$new( parentTable, baseStyleName = NULL, isBaseStyle = NULL, fontName = NULL, fontSize = NULL, bold = NULL, italic = NULL, underline = NULL, strikethrough = NULL, superscript = NULL, subscript = NULL, fillColor = NULL, textColor = NULL, hAlign = NULL, vAlign = NULL, wrapText = NULL, textRotation = NULL, indent = NULL, borderAll = NULL, borderLeft = NULL, borderRight = NULL, borderTop = NULL, borderBottom = NULL, valueFormat = NULL, minColumnWidth = NULL, minRowHeight = NULL )
parentTableOwning table.
baseStyleNameThe name of the base style in the table.
isBaseStyle'TRUE' when this style is the equivalent of a named style in the table, 'FALSE' if this style has additional settings over and above the base style of the same name.
fontNameThe name of the font (single font name, not a CSS style list).
fontSizeThe size of the font (units: point).
bold'TRUE' if text is bold.
italic'TRUE' if text is italic.
underline'TRUE' if text is underlined.
strikethrough'TRUE' if text has a line through it.
superscript'TRUE' if text is small and raised.
subscript'TRUE' if text is small and lowered.
fillColorThe background colour for the cell (as a hex value, e.g. #00FF00).
textColorThe color of the text (as a hex value).
hAlignThe horizontal alignment of the text: left, center or right.
vAlignThe vertical alignment of the text: top, middle or bottom.
wrapText'TRUE' if the text is allowed to wrap onto multiple lines.
textRotationThe rotation angle of the text or 255 for vertical.
indentThe text indentation.
borderAllA list (with elements style and color) specifying the border settings for all four sides of each cell at once.
borderLeftA list (with elements style and color) specifying the border settings for the left border of each cell.
borderRightA list (with elements style and color) specifying the border settings for the right border of each cell.
borderTopA list (with elements style and color) specifying the border settings for the top border of each cell.
borderBottomA list (with elements style and color) specifying the border settings for the bottom border of each cell.
valueFormatThe Excel formatting applied to the field value. One of the following values: "GENERAL", "NUMBER", "CURRENCY", "ACCOUNTING", "DATE", "LONGDATE", TIME, "PERCENTAGE", "FRACTION", "SCIENTIFIC", "TEXT", "COMMA". Or for dates/datetimes, a combination of d, m, y. Or for numeric values, use 0.00 etc.
minColumnWidthThe minimum width of this column.
minRowHeightThe minimum height of this row.
No return value.
isBasicStyleNameMatch()
Check if this style matches the specified base style name.
TableOpenXlsxStyle$isBasicStyleNameMatch(baseStyleName = NULL)
baseStyleNameThe style name to compare to.
'TRUE' if the style name matches, 'FALSE' otherwise.
isFullStyleDetailMatch()
Check if this style matches the specified style properties.
TableOpenXlsxStyle$isFullStyleDetailMatch( baseStyleName = NULL, isBaseStyle = NULL, fontName = NULL, fontSize = NULL, bold = NULL, italic = NULL, underline = NULL, strikethrough = NULL, superscript = NULL, subscript = NULL, fillColor = NULL, textColor = NULL, hAlign = NULL, vAlign = NULL, wrapText = NULL, textRotation = NULL, indent = NULL, borderAll = NULL, borderLeft = NULL, borderRight = NULL, borderTop = NULL, borderBottom = NULL, valueFormat = NULL, minColumnWidth = NULL, minRowHeight = NULL )
baseStyleNameThe style name to compare to.
isBaseStyleWhether the style being compared to is a base style.
fontNameThe font name to compare to.
fontSizeThe font size to compare to.
boldThe style property bold to compare to.
italicThe style property italic to compare to.
underlineThe style property underline to compare to.
strikethroughThe style property strikethrough to compare to.
superscriptThe style property superscript to compare to.
subscriptThe style property subscript to compare to.
fillColorThe style property fillColor to compare to.
textColorThe style property textColor to compare to.
hAlignThe style property hAlign to compare to.
vAlignThe style property vAlign to compare to.
wrapTextThe style property wrapText to compare to.
textRotationThe style property textRotation to compare to.
indentThe style property indent to compare to.
borderAllThe style property borderAll to compare to.
borderLeftThe style property borderLeft to compare to.
borderRightThe style property borderRight to compare to.
borderTopThe style property borderTop to compare to.
borderBottomThe style property borderBottom to compare to.
valueFormatThe style value format to compare to.
minColumnWidthThe style property minColumnWidth to compare to.
minRowHeightThe style property minRowHeight to compare to.
'TRUE' if the style matches, 'FALSE' otherwise.
createOpenXslxStyle()
Create the 'openxlsx' style based on the specified style properties.
TableOpenXlsxStyle$createOpenXslxStyle()
No return value.
asList()
Return the contents of this object as a list for debugging.
TableOpenXlsxStyle$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
TableOpenXlsxStyle$asJSON()
A JSON representation of various object properties.
asString()
Return the contents of this object as a string for debugging.
TableOpenXlsxStyle$asString()
A character representation of various object properties.
clone()
The objects of this class are cloneable with this method.
TableOpenXlsxStyle$clone(deep = FALSE)
deepWhether to make a deep clone.
# This class should only be created by using the functions in the table. # It is not intended to be created by users outside of the table. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) library(openxlsx) wb <- createWorkbook(creator = Sys.getenv("USERNAME")) addWorksheet(wb, "Data") tbl$writeToExcelWorksheet(wb=wb, wsName="Data", topRowNumber=1, leftMostColumnNumber=1, applyStyles=TRUE, mapStylesFromCSS=TRUE) # Use saveWorkbook() to save the Excel file.# This class should only be created by using the functions in the table. # It is not intended to be created by users outside of the table. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) library(openxlsx) wb <- createWorkbook(creator = Sys.getenv("USERNAME")) addWorksheet(wb, "Data") tbl$writeToExcelWorksheet(wb=wb, wsName="Data", topRowNumber=1, leftMostColumnNumber=1, applyStyles=TRUE, mapStylesFromCSS=TRUE) # Use saveWorkbook() to save the Excel file.
The 'TableOpenXlsxStyles' class stores a collection of 'TableTableOpenXlsx' style objects.
R6Class object.
countThe number of styles in the collection.
stylesA list of 'TableOpenXlsxStyle' objects that comprise the collection.
new()
Create a new 'TableOpenXlsxStyles' object.
TableOpenXlsxStyles$new(parentTable)
parentTableOwning table.
No return value.
clearStyles()
Clear the collection removing all styles.
TableOpenXlsxStyles$clearStyles()
No return value.
findNamedStyle()
Find a style in the collection matching the specified base style name.
TableOpenXlsxStyles$findNamedStyle(baseStyleName)
baseStyleNameThe style name to find.
A 'TableTableOpenXlsx' object that is the style matching the specified base style name or 'NULL' otherwise.
findOrAddStyle()
Find a style in the collection matching the specified base style name and style properties. If there is no matching style, then optionally add a new style.
TableOpenXlsxStyles$findOrAddStyle( action = "findOrAdd", baseStyleName = NULL, isBaseStyle = NULL, style = NULL, mapFromCss = TRUE )
actionThe action to carry out. Must be one of "find", "add" or "findOrAdd" (default).
baseStyleNameThe style name to find/add.
isBaseStyleIs the style to be found/added a base style?
styleA 'TableStyle' object specifying style properties to be found/added.
mapFromCss'TRUE' (default) to map the basictabler CSS styles to corresponding Excel styles, 'FALSE' to apply only the specified xl styles.
A 'TableTableOpenXlsx' object that is the style matching the specified base style name or 'NULL' otherwise.
addNamedStyles()
Populate the OpenXlsx styles based on the styles defined in the table.
TableOpenXlsxStyles$addNamedStyles(mapFromCss = TRUE)
mapFromCss'TRUE' (default) to map the basictabler CSS styles to corresponding Excel styles, 'FALSE' to apply only the specified xl styles.
No return value.
asList()
Return the contents of this object as a list for debugging.
TableOpenXlsxStyles$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
TableOpenXlsxStyles$asJSON()
A JSON representation of various object properties.
asString()
Return the contents of this object as a string for debugging.
TableOpenXlsxStyles$asString(seperator = ", ")
seperatorDelimiter used to combine multiple values into a string.
A character representation of various object properties.
clone()
The objects of this class are cloneable with this method.
TableOpenXlsxStyles$clone(deep = FALSE)
deepWhether to make a deep clone.
# This class should not be used by end users. It is an internal class # created only by the BasicTable class. It is used when rendering to Excel. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) library(openxlsx) wb <- createWorkbook(creator = Sys.getenv("USERNAME")) addWorksheet(wb, "Data") tbl$writeToExcelWorksheet(wb=wb, wsName="Data", topRowNumber=1, leftMostColumnNumber=1, applyStyles=TRUE, mapStylesFromCSS=TRUE) # Use saveWorkbook() to save the Excel file.# This class should not be used by end users. It is an internal class # created only by the BasicTable class. It is used when rendering to Excel. library(basictabler) tbl <- qtbl(data.frame(a=1:2, b=3:4)) library(openxlsx) wb <- createWorkbook(creator = Sys.getenv("USERNAME")) addWorksheet(wb, "Data") tbl$writeToExcelWorksheet(wb=wb, wsName="Data", topRowNumber=1, leftMostColumnNumber=1, applyStyles=TRUE, mapStylesFromCSS=TRUE) # Use saveWorkbook() to save the Excel file.
The 'TableStyle' class specifies the styling for headers and cells in a table. Styles are specified in the form of Cascading Style Sheet (CSS) name-value pairs.
R6Class object.
nameThe unique name of the style (must be unique among the style names in the table theme).
declarationsA list containing CSS style declarations. Example: 'declarations = list(font="...", color="...")'
new()
Create a new 'TableStyle' object.
TableStyle$new(parentTable, styleName = NULL, declarations = NULL)
parentTableOwning table.
styleNameA unique name for the style.
declarationsA list containing CSS style declarations. Example: 'declarations = list(font="...", color="...")'
No return value.
setPropertyValue()
Set the value of a single style property.
TableStyle$setPropertyValue(property = NULL, value = NULL)
propertyThe CSS style property name, e.g. color.
valueThe value of the style property, e.g. red.
No return value.
setPropertyValues()
Set the values of multiple style properties.
TableStyle$setPropertyValues(declarations = NULL)
declarationsA list containing CSS style declarations. Example: 'declarations = list(font="...", color="...")'
No return value.
getPropertyValue()
Get the value of a single style property.
TableStyle$getPropertyValue(property = NULL)
propertyThe CSS style property name, e.g. color.
No return value.
asCSSRule()
Generate a CSS style rule from this table style.
TableStyle$asCSSRule(selector = NULL)
selectorThe CSS selector name. Default value 'NULL'.
The CSS style rule, e.g. { text-align: center; color: red; }
asNamedCSSStyle()
Generate a named CSS style from this table style.
TableStyle$asNamedCSSStyle(styleNamePrefix = NULL)
styleNamePrefixA character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple tables exist.
The CSS style rule, e.g. cell { text-align: center; color: red; }
getCopy()
Create a copy of this 'TableStyle' object.
TableStyle$getCopy(newStyleName = NULL)
newStyleNameThe name of the new style.
The new 'TableStyle' object.
asList()
Return the contents of this object as a list for debugging.
TableStyle$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
TableStyle$asJSON()
A JSON representation of various object properties.
clone()
The objects of this class are cloneable with this method.
TableStyle$clone(deep = FALSE)
deepWhether to make a deep clone.
# TableStyle objects are normally created indirectly via one of the helper # methods. # For an example, see the `TableStyles` class.# TableStyle objects are normally created indirectly via one of the helper # methods. # For an example, see the `TableStyles` class.
The 'TableStyles' class defines all of the base styles needed to style/theme a table. It defines the names of the styles that are used for styling the different parts of the table.
R6Class object.
countThe number of styles in this styles collection.
themeThe name of the theme.
stylesThe collection of 'TableStyle' objects in this styles collection.
allowExternalStylesEnable integration scenarios where an external system is supplying the CSS definitions.
tableStyleThe name of the style for the HTML table element.
rootStyleThe name of the style for the HTML cell at the top left of the table (when both row and column headers are displayed).
rowHeaderStyleThe name of the style for the row headers in the table.
colHeaderStyleThe name of the style for the column headers in the table.
cellStyleThe name of the cell style for the non-total cells in the body of the table.
totalStyleThe name of the cell style for the total cells in the table.
new()
Create a new 'TableStyles' object.
TableStyles$new(parentTable, themeName = NULL, allowExternalStyles = FALSE)
parentTableOwning table.
themeNameThe name of the theme.
allowExternalStylesEnable integration scenarios where an external system is supplying the CSS definitions.
No return value.
isExistingStyle()
Check whether a style with the specified name exists in the collection.
TableStyles$isExistingStyle(styleName = NULL)
styleNameThe style name.
'TRUE' if a style with the specified name exists, 'FALSE' otherwise.
getStyle()
Retrieve a style with the specified name from the collection.
TableStyles$getStyle(styleName = NULL)
styleNameThe style name.
A 'TableStyle' object if a style with the specified name exists in the collection, an error is raised otherwise.
addStyle()
Add a new style to the collection of styles.
TableStyles$addStyle(styleName = NULL, declarations = NULL)
styleNameThe style name of the new style.
declarationsA list containing CSS style declarations. Example: 'declarations = list(font="...", color="...")'
The newly created 'TableStyle' object.
copyStyle()
Create a copy of an exist style.
TableStyles$copyStyle(styleName = NULL, newStyleName = NULL)
styleNameThe style name of the style to copy.
newStyleNameThe name of the new style.
The newly created 'TableStyle' object.
asCSSRule()
Generate a CSS style rule from the specified table style.
TableStyles$asCSSRule(styleName = NULL, selector = NULL)
styleNameThe style name.
selectorThe CSS selector name. Default value 'NULL'.
The CSS style rule, e.g. { text-align: center; color: red; }
asNamedCSSStyle()
Generate a named CSS style from the specified table style.
TableStyles$asNamedCSSStyle(styleName = NULL, styleNamePrefix = NULL)
styleNameThe style name.
styleNamePrefixA character variable specifying a prefix for all named CSS styles, to avoid style name collisions where multiple tables exist.
The CSS style rule, e.g. cell { text-align: center; color: red; }
asList()
Return the contents of this object as a list for debugging.
TableStyles$asList()
A list of various object properties.
asJSON()
Return the contents of this object as JSON for debugging.
TableStyles$asJSON()
A JSON representation of various object properties.
asString()
Return the contents of this object as a string for debugging.
TableStyles$asString(seperator = ", ")
seperatorDelimiter used to combine multiple values into a string.
A character representation of various object properties.
clone()
The objects of this class are cloneable with this method.
TableStyles$clone(deep = FALSE)
deepWhether to make a deep clone.
# Creating styles is part of defining a theme for a table. # Multiple styles must be created for each theme. # The example below shows how to create one style. # For an example of creating a full theme please # see the Styling vignette. tbl <- BasicTable$new() # ... TableStyles <- TableStyles$new(tbl, themeName="compact") TableStyles$addStyle(styleName="MyNewStyle", list( font="0.75em arial", padding="2px", border="1px solid lightgray", "vertical-align"="middle", "text-align"="center", "font-weight"="bold", "background-color"="#F2F2F2" ))# Creating styles is part of defining a theme for a table. # Multiple styles must be created for each theme. # The example below shows how to create one style. # For an example of creating a full theme please # see the Styling vignette. tbl <- BasicTable$new() # ... TableStyles <- TableStyles$new(tbl, themeName="compact") TableStyles$addStyle(styleName="MyNewStyle", list( font="0.75em arial", padding="2px", border="1px solid lightgray", "vertical-align"="middle", "text-align"="center", "font-weight"="bold", "background-color"="#F2F2F2" ))
A reference dataset listing the codes, names and locations of trains stations in Great Britain.
trainstationstrainstations
A data frame with 2568 rows and 7 variables:
3-letter code for the station
The name of the station
The UK Ordnance Survey Easting coordinate for the station
The UK Ordnance Survey Northing coordinate for the station
Grid reference for the station
Latitude of the station location
Longitude of the station location
https://www.recenttraintimes.co.uk/
vreConvertSimpleNumericRange is a utility function that converts
a simple range expression of the form "value1<=v<value2" to a standard
R logical expression of the form "value1<=v && v<value2".
vreConvertSimpleNumericRange(vre)vreConvertSimpleNumericRange(vre)
vre |
The value range expression to examine. |
A standard R logical expression.
vreGetSingleValue is a utility function reads the single value
from a value range expression (it assumes the specified
is either numeric, a number expressed as
text or an expression of the form "v=" or "v==").
vreGetSingleValue(vre)vreGetSingleValue(vre)
vre |
The value range expression to examine. |
The value read from the expression.
vreHexToClr converts a colour in hex format
(#RRGGBB) into a list of three element (r, g and b).
vreHexToClr(hexclr)vreHexToClr(hexclr)
hexclr |
The colour to convert. |
The converted colour.
vreIsEqual tests whether two values are equal
within sqrt(.Machine$double.eps).
vreIsEqual(value1, value2)vreIsEqual(value1, value2)
value1 |
The first value to compare. |
value2 |
The second value to compare. |
'TRUE' if the two numbers are equal, 'FALSE' otherwise.
vreIsMatch tests a value (e.g. from a cell) matches
the criteria specified in a value range expression.
vreIsMatch(vre, v, testOnly = FALSE)vreIsMatch(vre, v, testOnly = FALSE)
vre |
The value range expression. |
v |
The value. |
testOnly |
'TRUE' if this comparison is just a test. |
'TRUE' if v matches the criteria specified in the value range expression, 'FALSE' otherwise.
vreIsSingleValue is a utility function that returns 'TRUE' if the
specified value range expression is a simple range expression of the
form "value1<=v<value2", where the logical comparisons can be < or <= only
and the values must be numbers.
vreIsSimpleNumericRange(vre)vreIsSimpleNumericRange(vre)
vre |
The value range expression to examine. |
'TRUE' if vre is a simple range expression, 'FALSE' otherwise.
vreIsSingleValue is a utility function that returns 'TRUE' if the
specified value range expression is either numeric, a number expressed as
text or an expression of the form "v=" or "v==".
vreIsSingleValue(vre)vreIsSingleValue(vre)
vre |
The value range expression to examine. |
'TRUE' if vre is a single value, 'FALSE' otherwise.
vreScale2Colours takes a value from a range and
scales it proportionally into a colour from a colour gradient.
vreScale2Colours(clr1, clr2, vMin, vMax, value)vreScale2Colours(clr1, clr2, vMin, vMax, value)
clr1 |
The colour representing the lower value of the target range. |
clr2 |
The colour representing the upper value of the target range. |
vMin |
The lower value of the source range. |
vMax |
The upper value of the source range. |
value |
The source value to rescale into the target range. |
The value scaled into the target colour gradient.
vreScaleNumber takes a value from one range and
scales it proportionally into another range.
vreScaleNumber(n1, n2, vMin, vMax, value, decimalPlaces = 3)vreScaleNumber(n1, n2, vMin, vMax, value, decimalPlaces = 3)
n1 |
The lower value of the target range. |
n2 |
The upper value of the target range. |
vMin |
The lower value of the source range. |
vMax |
The upper value of the source range. |
value |
The source value to rescale into the target range. |
decimalPlaces |
The number of decimal places to round the result to. |
The value rescaled into the target range.