Title: | The Grammar of Tables |
---|---|
Description: | Provides an extensible formula system to quickly and easily create production quality tables. The processing steps are a formula parser, statistical content generation from data as defined by formula, followed by rendering into a table. Each step of the processing is separate and user definable thus creating a set of composable building blocks for highly customizable table generation. A user is not limited by any of the choices of the package creator other than the formula grammar. For example, one could chose to add a different S3 rendering function and output a format not provided in the default package, or possibly one would rather have Gini coefficients for their statistical content in a resulting table. Routines to achieve New England Journal of Medicine style, Lancet style and Hmisc::summaryM() statistics are provided. The package contains rendering for HTML5, Rmarkdown and an indexing format for use in tracing and tracking are provided. |
Authors: | Shawn Garbett [aut, cre], Thomas Stewart [ctb], Jennifer Thompson [ctb], Frank Harrell [ctb], Ahra Kim [ctb] |
Maintainer: | Shawn Garbett <[email protected]> |
License: | GPL-3 |
Version: | 0.8.2 |
Built: | 2024-10-31 03:04:35 UTC |
Source: | https://github.com/spgarbet/tangram |
The plus operator provides an rbind for tangram tables
## S3 method for class 'tangram' x + y
## S3 method for class 'tangram' x + y
x |
left argument for rbind |
y |
right argument for rbind |
A row wise merged tangram object
Add a footnote to a table
add_footnote(table, footnote)
add_footnote(table, footnote)
table |
tangram; the tangram table to modify |
footnote |
character; The footnote to add |
the modified table
Add indentations to left column row headers. Note: will only work on cell_header cells.
add_indent(table, amounts = 2, rows = NULL, columns = NULL)
add_indent(table, amounts = 2, rows = NULL, columns = NULL)
table |
Output of tangram::tangram() |
amounts |
numeric; Specifies number of spaces to add. A vector that is either a single value or vector of the same size as the height of the table. If positions is specified then it must be the same length. Defaults to 2, which each pair of spaces converts naturally in rendering to HTML, LaTeX, etc.. |
rows |
numeric; A vector of numeric row numbers for the rows that need to be indented. Defaults to NULL which indents all. |
columns |
numeric; Column to apply indent to, defaults to 1 |
the modified table
x <- tangram(drug ~ bili + albumin, pbc) add_indent(x) add_indent(x, amounts=10) add_indent(x, amounts=c(0, 0, 2, 4)) add_indent(x, rows=c(3)) add_indent(x, rows=c(3, 4), amounts=c(4, 2))
x <- tangram(drug ~ bili + albumin, pbc) add_indent(x) add_indent(x, amounts=10) add_indent(x, amounts=c(0, 0, 2, 4)) add_indent(x, rows=c(3)) add_indent(x, rows=c(3, 4), amounts=c(4, 2))
Take variable arguments, flatten vectors and lists, but do not flatten cells (which are lists) e.g. args_flatten(NA, list(1,2,3), 4:6, c(7,8,9))
args_flatten(...)
args_flatten(...)
... |
variable arguments |
a list of the arguments, with vectors and lists flattened
Convert data type to a factor if it's not already
as.categorical(x)
as.categorical(x)
x |
Data to convert to factor |
Data as a factor
as.categorical(1:3)
as.categorical(1:3)
A left/right branch in an Abstract Syntrax Tree. This inherits from ASTNode, and is intended to be a base class as well. Should never be instantiated directly as once again the semantic information is contained in the class name.
A left/right branch in an Abstract Syntrax Tree. This inherits from ASTNode, and is intended to be a base class as well. Should never be instantiated directly as once again the semantic information is contained in the class name.
R6Class
object.
tangram::ASTNode
-> ASTBranch
left
A pointer to the left node below this one
right
A pointer to the right node below this one
distribute()
Call to distribute multiplication nodes, just recursively calls left and right node distribute functions
ASTBranch$distribute()
reduce()
Attached data to nodes by processing data.frame appropriatly. Recursively calls left and right nodes to reduces on data.frame
ASTBranch$reduce(df)
df
(data.frame) Data frame to reduce over
clone()
The objects of this class are cloneable with this method.
ASTBranch$clone(deep = FALSE)
deep
Whether to make a deep clone.
A specified function call as an ASTNode
A specified function call as an ASTNode
R6Class
object.
tangram::ASTNode
-> ASTFunction
r_expr
A string containing the raw r expression from inside the parenthesis
data
Data stored as a result of reduction
new()
Construct a node representing a function call
ASTFunction$new(value, r_expr)
value
(character) The name of the function call
r_expr
Any r expression to be evaluated inside the call
factors()
Returns all terminal nodes, this is a terminal node so returns self
ASTFunction$factors()
name()
Returns the function call as character
ASTFunction$name()
string()
Returns a re-parsable representation of the node
ASTFunction$string()
reduce()
Given a data.frame execute the function in that environment and associate the result as data.
ASTFunction$reduce(data)
data
(data.frame) The data.frame to use as the enviroment for the function execution
clone()
The objects of this class are cloneable with this method.
ASTFunction$clone(deep = FALSE)
deep
Whether to make a deep clone.
ASTFunction$new("log", "x+2")$string()
ASTFunction$new("log", "x+2")$string()
The multiplication of two terms, as an ASTNode.
The multiplication of two terms, as an ASTNode.
R6Class
object.
tangram::ASTNode
-> tangram::ASTBranch
-> ASTMultiply
left
The AST tree to the left.
right
The AST tree to the right.
type
The specified type of this node
new()
Construct a multiplication node
ASTMultiply$new(left, right)
left
(ASTNode) nodes to the left of the multiplication
right
(ASTNode) nodes to the right of the multiplication
distribute()
Rearrange nodes distribution multiplication across parenthesis
ASTMultiply$distribute()
factors()
return all terminal nodes on left and right
ASTMultiply$factors()
string()
Return a re-parseable string
ASTMultiply$string()
clone()
The objects of this class are cloneable with this method.
ASTMultiply$clone(deep = FALSE)
deep
Whether to make a deep clone.
ASTMultiply$new(ASTVariable$new("x"), ASTVariable$new("y"))$string()
ASTMultiply$new(ASTVariable$new("x"), ASTVariable$new("y"))$string()
A Node in an Abstract Syntax Tree (AST)
A Node in an Abstract Syntax Tree (AST)
This is the root R6 class of any term of the AST which is created when parsing a table formula. This should only be used as a base class as the class information carries the semantic meaning of a given node.
format
Any formatting directive passed to this node.
value
A string of addtional information contained by the node.
terms()
Returns this node
ASTNode$terms()
distribute()
Distributes data across multiplications and rearranges nodes
ASTNode$distribute()
string()
Returns string representation of node
ASTNode$string()
reduce()
Given a set of data, associates it with AST nodes
ASTNode$reduce(data)
data
(data.frame) data to associate across nodes
set_format()
Override the formatting directive for this node
ASTNode$set_format(x)
x
(numeric,character) the formatting directive
clone()
The objects of this class are cloneable with this method.
ASTNode$clone(deep = FALSE)
deep
Whether to make a deep clone.
The addition of two terms, in an ASTNode.
The addition of two terms, in an ASTNode.
R6Class
object.
tangram::ASTNode
-> tangram::ASTBranch
-> ASTPlus
data
Just returns the R6 name 'ASTPlus'
left
The node to the left of this node
right
The node to the right of this node
new()
Construct a new node that represents addition
ASTPlus$new(left, right)
left
(ASTNode) Node on the left side of the addition
right
(ASTNode) Node on the right side of the addition
terms()
Returns a vector of the left and right terms
ASTPlus$terms()
string()
A reparsable string representation of this node.
ASTPlus$string()
clone()
The objects of this class are cloneable with this method.
ASTPlus$clone(deep = FALSE)
deep
Whether to make a deep clone.
ASTPlus$new(ASTVariable$new("x"), ASTVariable$new("y"))$string()
ASTPlus$new(ASTVariable$new("x"), ASTVariable$new("y"))$string()
The root ASTNode of a formula.
The root ASTNode of a formula.
R6Class
object.
tangram::ASTNode
-> tangram::ASTBranch
-> ASTTableFormula
left
The AST tree for the columns.
right
The AST tree for the rows.
new()
Create a new formula node
ASTTableFormula$new(left, right)
left
The left side of the "~" as an AST
right
The right side of the "~" as an AST
terms()
Returns all terminal nodes from left and right
ASTTableFormula$terms()
string()
A re-parseable string representing the AST
ASTTableFormula$string()
clone()
The objects of this class are cloneable with this method.
ASTTableFormula$clone(deep = FALSE)
deep
Whether to make a deep clone.
ASTTableFormula$new(ASTVariable$new("x"), ASTVariable$new("y"))$string()
ASTTableFormula$new(ASTVariable$new("x"), ASTVariable$new("y"))$string()
A Variable in an Abstract Syntax Tree (AST)
A Variable in an Abstract Syntax Tree (AST)
R6Class
object.
This node represents a variable of interest in the AST. A variable's name
is recorded in the value field, and must conform to the rules of identifiers
in R. This class inherits from ASTNode
.
new(identifier, format=NA, type=NA)
terms()
Returns the node
distribute()
Applies the distributive property to the node, and returns the resulting node.
string()
Returns the string formula of the node
name()
Return a human representation of a node
reduce(data)
Given a set of data, perform the logical reduction of the current node.
tangram::ASTNode
-> ASTVariable
data
The associated data post reduction
type
The identified type of this node (defaults: Categorical, Numeric)
new()
This method creates an AST node representing a variable of a given identifier. An optional format consisting of a string of a number or a c-style printf string. An option type denoting a forced type cast of that variable.
ASTVariable$new(identifier, format = NA, type = NA)
identifier
(character) Variable name
format
(character, numeric) Formatting directive
type
(character) any additional type information
factors()
Returns all terminal nodes under this. Since this is a terminal node, returns self
ASTVariable$factors()
name()
Returns the text name of this node. For an intercept, returns "All"
ASTVariable$name()
string()
Returns name of variable with optional format and type information
ASTVariable$string()
reduce()
Given a data.frame, associates correct variable with this node
ASTVariable$reduce(d)
d
(data.frame) data.frame to reduce
clone()
The objects of this class are cloneable with this method.
ASTVariable$clone(deep = FALSE)
deep
Whether to make a deep clone.
ASTVariable$new("x", "2", "Continuous")$string()
ASTVariable$new("x", "2", "Continuous")$string()
Execute the equivalent of an cbind for generated tables
## S3 method for class 'tangram' cbind(..., deparse.level = 1)
## S3 method for class 'tangram' cbind(..., deparse.level = 1)
... |
tangram objects to cbind |
deparse.level |
numeric; not used |
A merged tangram object
Any R object can be used as a cell value. Attributes are used to store additional classs of that cell attached to the object. This is a helper function to attach all the additional attributes to the provided object
cell(x, ...)
cell(x, ...)
x |
R object to attach attributes too |
... |
Each additional argument becomes an attribute for the object |
Certain attributes have special meaning: - 'names' is appended to the front of a value, e.g. "P=" for a p-value. - 'sep' is used to join values, e.g. ", " for a list of values. - 'class' denotes special rendering handling, e.g. generally passed as CSS class to HTML5 - 'reference' a list of reference symbols to put inside the cell - 'row' and 'col' should refer to the row / column if key generation is needed - 'subrow' and 'subcol' further delinate the key value of a cell for key generation
The modified R object
A cell_header object represents a label cell inside a table. It can also contain units.
cell_header(text, units = NULL, class = NULL, ...)
cell_header(text, units = NULL, class = NULL, ...)
text |
character; The text of the label. May include a subset of LaTeX greek or math. |
units |
character; An optional field that contains units |
class |
character; An optional field for additional S3 classes (e.g. could be used in html rendering for CSS) |
... |
optional extra information to attach |
A cell_header object
cell_header("Yahoo") cell_header("Concentration", "mg/dl") cell_header("Concentration", "mg/dl", src="A")
cell_header("Yahoo") cell_header("Concentration", "mg/dl") cell_header("Concentration", "mg/dl", src="A")
A cell_label object represents a label cell inside a table. It can also contain units.
cell_label(text, units = NULL, class = NULL, ...)
cell_label(text, units = NULL, class = NULL, ...)
text |
character; The text of the label. May include a subset of LaTeX greek or math. |
units |
character; An optional field that contains units |
class |
character; An optional field for additional S3 classes (e.g. could be used in html rendering for CSS) |
... |
optional extra information to attach |
A tangram object
cell_label("Compaction Method") cell_label("Concentration", "mg/dl") cell_label("Concentration", "mg/dl", subcol="A")
cell_label("Compaction Method") cell_label("Concentration", "mg/dl") cell_label("Concentration", "mg/dl", subcol="A")
A cell_n object contains an n value. Essentially, this is just a helper that appends the cell_n class to the given object and makes sure it's a cell S3 object as well.
cell_n(n, class = NULL, hdr = FALSE, possible = NULL, ...)
cell_n(n, class = NULL, hdr = FALSE, possible = NULL, ...)
n |
The numerical value |
class |
character; An optional field for additional S3 classes (e.g. could be used in html rendering for CSS) |
hdr |
logical; Construct an n value for a header (defaults to FALSE) |
possible |
numerical; The total N that was possible |
... |
optional extra information to attach |
A cell_n object.
cell_n(20)
cell_n(20)
A cell_subheader object represents a label cell inside a table. It can also contain units.
cell_subheader(text, units = NULL, class = NULL, ...)
cell_subheader(text, units = NULL, class = NULL, ...)
text |
character; The text of the label. May include a subset of LaTeX greek or math. |
units |
character; An optional field that contains units |
class |
character; An optional field for additional S3 classes (e.g. could be used in html rendering for CSS) |
... |
optional extra information to attach |
A cell_subheader object.
cell_subheader("Concentration") cell_subheader("Concentration", "mg/dl") cell_subheader("Concentration", "mg/dl", src="A")
cell_subheader("Concentration") cell_subheader("Concentration", "mg/dl") cell_subheader("Concentration", "mg/dl", src="A")
Given a function that operates on a table cell and returns the modified cell, return a function that given a table applies that function to all cells and returns the modified table.
cell_transform(FUN, ...)
cell_transform(FUN, ...)
FUN |
function to apply, must return the modified cell |
... |
additional arguments to pass into function |
a table modification function
A set of magrittr operators for tangram tables
col_header(table, ..., sub = TRUE) row_header(table, ..., sub = TRUE) write_cell(table, x, ...) home(table) cursor_up(table, n = 1) cursor_down(table, n = 1) cursor_left(table, n = 1) cursor_right(table, n = 1) cursor_pos(table, nrow, ncol) carriage_return(table) line_feed(table, n = 1) new_line(table) new_row(table) new_col(table) table_apply(table, x, FUN, ...) add_col(table, ...) add_row(table, ...) set_footnote(table, footnote) set_id(table, id) set_caption(table, caption) set_style(table, style) set_colspan(table, span) set_rowspan(table, span)
col_header(table, ..., sub = TRUE) row_header(table, ..., sub = TRUE) write_cell(table, x, ...) home(table) cursor_up(table, n = 1) cursor_down(table, n = 1) cursor_left(table, n = 1) cursor_right(table, n = 1) cursor_pos(table, nrow, ncol) carriage_return(table) line_feed(table, n = 1) new_line(table) new_row(table) new_col(table) table_apply(table, x, FUN, ...) add_col(table, ...) add_row(table, ...) set_footnote(table, footnote) set_id(table, id) set_caption(table, caption) set_style(table, style) set_colspan(table, span) set_rowspan(table, span)
table |
tangram; The tangram table being built |
... |
additional argument passed |
sub |
logical; Is this a subheader |
x |
object of focus in operation |
n |
numeric; number of times to perform operation |
nrow |
numeric; number of rows |
ncol |
numeric; number of columns |
FUN |
function; function to apply |
footnote |
character; footnote to add |
id |
character; id of table |
caption |
character; caption of table |
style |
character; styling in compiling table and in rendering |
span |
numeric; number of rows or columns to span |
Given a tangram object create an index representation.
csv(object, ...) ## S3 method for class 'tangram' csv(object, file = NULL, sep = ",", ...) ## Default S3 method: csv(object, ...)
csv(object, ...) ## S3 method for class 'tangram' csv(object, file = NULL, sep = ",", ...) ## Default S3 method: csv(object, ...)
object |
The cell header to render to HTML5 |
... |
additional arguments to renderer. Unused |
file |
File to write result into |
sep |
separator to use |
A string containing the csv file
Given a filename, this function will load the file name from the current working directory. If it is not found from the current working directory it will search in the package for a a matching filename and load that instead. If an id is specified, that will be prepended to all CSS selectors (TODO: make this substitution more robust). The result is returned as a string.
custom_css(filename, id = NA)
custom_css(filename, id = NA)
filename |
Name of the CSS file to load |
id |
CSS id to prepend to all entries |
String of possibly modified CSS file
custom_css("lancet.css", "tbl1")
custom_css("lancet.css", "tbl1")
Given a table, remove the specified column
del_col(table, col)
del_col(table, col)
table |
the table to modify |
col |
vector containing column(s) to drop |
the modified table
Given a table, remove the specified row
del_row(table, row)
del_row(table, row)
table |
the table to modify |
row |
vector with row numbers to drop |
the modified table
Determine the label of a given AST node. NOTE: Should have data attached via reduce before calling.
derive_label(node, capture_units = FALSE, ...)
derive_label(node, capture_units = FALSE, ...)
node |
Abstract syntax tree node. |
capture_units |
logical; Capture units from parenthesis ending a label |
... |
Other arguments, ignored |
A string with a label for the node
Delete from a table all columns that contain statistics
drop_statistics(table)
drop_statistics(table)
table |
the table to remove statistical columns |
the modified table
Given a vector of data, default to 3 significant digits or all if maximum is greater than zero
format_guess(x)
format_guess(x)
x |
numeric; basic math and quantile function must work on data passed in |
numeric; the digits past the decimal recommended for display
format_guess(rnorm(100)) format_guess(rnorm(100, sd=1e-6))
format_guess(rnorm(100)) format_guess(rnorm(100, sd=1e-6))
Determine data type of a vector loosely consistent with Hmisc.
hmisc_data_type(x, category_threshold = NA)
hmisc_data_type(x, category_threshold = NA)
x |
Vector to determine type of |
category_threshold |
The upper threshold of unique values for which a vector is considered categorical. |
One of the following strings: Binomial, Categorical, or Numerical.
hmisc_data_type(c(1,2,3)) hmisc_data_type(factor(c("A","B","C"))) hmisc_data_type(factor(c("A","B","B","A"))) hmisc_data_type(factor(c(TRUE, FALSE, TRUE, FALSE)))
hmisc_data_type(c(1,2,3)) hmisc_data_type(factor(c("A","B","C"))) hmisc_data_type(factor(c("A","B","B","A"))) hmisc_data_type(factor(c(TRUE, FALSE, TRUE, FALSE)))
Cleanup an intercept only table that was generated from the hmisc default transform. This drops the statistics column, and modifies the header to eliminate blank space.
hmisc_intercept_cleanup(table)
hmisc_intercept_cleanup(table)
table |
the table to modify |
the modified table
Each function here is called when a cell is generated. Overriding these in a formula call will allows one to customize exactly how each cell's contents are generated. While this serves as the base template for transforms, it is by no means required if one develops their own bundle of data transforms. One can create ay number of cell level styling choices.
hmisc_p(p, pformat = "%1.3f", include_p = TRUE) hmisc_iqr( x, format = NA, na.rm = TRUE, names = FALSE, type = 8, msd = FALSE, quant = c(0.25, 0.5, 0.75), ... ) hmisc_fraction(numerator, denominator, format = 3, ...) hmisc_fstat(f, df1, df2, p, class = NULL, ...) hmisc_chi2(chi2, df, p, class = NULL, ...) hmisc_spearman(S, rho, p, class = NULL, ...) hmisc_wilcox(V, p, class = NULL, ...) hmisc_cell
hmisc_p(p, pformat = "%1.3f", include_p = TRUE) hmisc_iqr( x, format = NA, na.rm = TRUE, names = FALSE, type = 8, msd = FALSE, quant = c(0.25, 0.5, 0.75), ... ) hmisc_fraction(numerator, denominator, format = 3, ...) hmisc_fstat(f, df1, df2, p, class = NULL, ...) hmisc_chi2(chi2, df, p, class = NULL, ...) hmisc_spearman(S, rho, p, class = NULL, ...) hmisc_wilcox(V, p, class = NULL, ...) hmisc_cell
p |
numeric; p-value to format |
pformat |
numeric or character; Significant digits or fmt to pass to sprintf |
include_p |
logical; include the leading P on the output string |
x |
numeric; whose sample quantiles are wanted. NA and NaN values are not allowed in numeric vectors unless na.rm is TRUE. |
format |
numeric or character; Significant digits or fmt to pass to sprintf |
na.rm |
logical; if true, any NA and NaN's are removed from x before the quantiles are computed. |
names |
logical; if true, the result has a names attribute. Set to FALSE for speedup with many probs. |
type |
integer; specify algorithm to use in constructing quantile. See quantile for more information. |
msd |
logical; compute an msd attribute containing mean and standard deviation |
quant |
numeric; The quantiles to display. Should be an odd length vector, since the center value is highlighted. |
... |
additional arguments passed |
numerator |
numeric; The value of the numerator |
denominator |
numeric; The value of the denominator |
f |
The value of the f-statistic |
df1 |
1st dimension degrees of freedom |
df2 |
2nd dimension degrees of freedom |
class |
character; An optional field for additional S3 classes (e.g. could be used in html rendering for CSS) |
chi2 |
The value of the X^2 statistic |
df |
degrees of freedom |
S |
The value of the spearman statistic |
rho |
The rho value of the test |
V |
The value of the Wilcoxon statistic |
An object of class list
of length 8.
A formatted string or cell as appropriate
hmisc_p
Given a style in number of digits or a sprintf style specifier it renders the p-value and checks to see if it's all zeros, then switches the output to a less than.
hmisc_iqr
Construct a cell which has the interquartile ranges specified.
hmisc_fraction
Construct a cell which has the fraction specified in an hmisc format
hmisc_fstat
Construct a cell which has the fstat specified in an hmisc format.
hmisc_chi2
Construct a cell which has the chi^2 specified in an hmisc format
hmisc_spearman
Construct a cell which has the spearman specified in an hmisc format
hmisc_wilcox
Construct a cell which has the Wilcoxon specified in an hmisc format
hmisc_cell
List of data transforms for a cell of a table.
hmisc_cell <- list( n = cell_n, iqr = hmisc_iqr, fraction = hmisc_fraction, fstat = hmisc_fstat, chi2 = hmisc_chi2, spearman = hmisc_spearman, wilcox = hmisc_wilcox, p = hmisc_p )
hmisc_p(1e-6) hmisc_p(0.234) hmisc_p(1.234e-6, 5) hmisc_p(1.234e-6, 6) require(stats) hmisc_iqr(rnorm(100), '3') hmisc_fraction(1, 4, 3) hmisc_fstat(4.0, 10, 20, 0.004039541) hmisc_chi2(5.33, 6, 0.2) hmisc_spearman(20, 0.2, 0.05) hmisc_wilcox(20, 0.2)
hmisc_p(1e-6) hmisc_p(0.234) hmisc_p(1.234e-6, 5) hmisc_p(1.234e-6, 6) require(stats) hmisc_iqr(rnorm(100), '3') hmisc_fraction(1, 4, 3) hmisc_fstat(4.0, 10, 20, 0.004039541) hmisc_chi2(5.33, 6, 0.2) hmisc_spearman(20, 0.2, 0.05) hmisc_wilcox(20, 0.2)
S3 html5 Method function for use on a tangram to generate HTML5
html5(object, id, ...)
html5(object, id, ...)
object |
The cell to render to HTML5 |
id |
A unique identifier for traceability in indexing |
... |
additional arguments to renderer. |
Given a cell class create an HTML5 representation.
## S3 method for class 'cell' html5(object, id, ..., class = NULL)
## S3 method for class 'cell' html5(object, id, ..., class = NULL)
object |
The cell to render to HTML5 |
id |
A unique identifier for traceability |
... |
additional arguments to renderer. Unused |
class |
An additional class attribute for the HTML5 element |
A text string rendering of the given cell as a <td> with several <span>'s.
Given a cell_header class create an HTML5 representation.
## S3 method for class 'cell_header' html5(object, id, ..., class = NULL)
## S3 method for class 'cell_header' html5(object, id, ..., class = NULL)
object |
The cell subheader to render to HTML5 |
id |
A unique identifier for traceability |
... |
additional arguments to renderer. Unused |
class |
additional class attributes for CSS rendering |
A text string rendering of the given subheader as a <td> with several <span>'s.
Given a cell_label class create an HTML5 representation.
## S3 method for class 'cell_label' html5(object, id, ..., class = NULL)
## S3 method for class 'cell_label' html5(object, id, ..., class = NULL)
object |
The cell label to render to HTML5 |
id |
A unique identifier for traceability |
... |
additional arguments to renderer. Unused |
class |
An additional class attribute for the HTML5 element |
A text string rendering of the given label as a <td> with several <span>'s.
Given a cell_n class create an HTML5 representation.
## S3 method for class 'cell_n' html5(object, id, ..., class = NULL)
## S3 method for class 'cell_n' html5(object, id, ..., class = NULL)
object |
The cell n to render to HTML5 |
id |
A unique identifier for traceability |
... |
additional arguments to renderer. Unused |
class |
An additional class attribute for the HTML5 element |
A text string rendering of the given n as a <td> with several <span>'s.
Given a cell_subheader class create an HTML5 representation.
## S3 method for class 'cell_subheader' html5(object, id, ..., class = NULL)
## S3 method for class 'cell_subheader' html5(object, id, ..., class = NULL)
object |
The cell subheader to render to HTML5 |
id |
A unique identifier for traceability |
... |
additional arguments to renderer. Unused |
class |
additional class attributes for CSS rendering |
A text string rendering of the given subheader as a <td> with several <span>'s.
Produces table cell
## S3 method for class 'character' html5(object, id, ..., class = NA)
## S3 method for class 'character' html5(object, id, ..., class = NA)
object |
The cell to render to HTML5 |
id |
A unique identifier for traceability |
... |
additional arguments to renderer. Unused |
class |
An additional class attribute for the HTML5 element |
An empty html5 td of the given class
Gives a warning and produces an empty <td></td> cell
## Default S3 method: html5(object, id, ..., class = NA)
## Default S3 method: html5(object, id, ..., class = NA)
object |
The cell to render to HTML5 |
id |
A unique identifier for traceability |
... |
additional arguments to renderer. Unused |
class |
An additional class attribute for the HTML5 element |
An empty html5 td of the given class
Produces table cell or nothing if it's an NA. This is useful for dealing with rowspan and colspan.
## S3 method for class 'logical' html5(object, id, ..., class = NA)
## S3 method for class 'logical' html5(object, id, ..., class = NA)
object |
The cell to render to HTML5 |
id |
A unique identifier for traceability |
... |
additional arguments to renderer. Unused |
class |
An additional class attribute for the HTML5 element |
An empty html5 td of the given class
Given a tangram class, a series of conversion creates an HTML5 representation of the table. It may be an HTML5 fragment or it may be a complete web page.
## S3 method for class 'tangram' html5( object, id = NULL, caption = NULL, fragment = NULL, style = NULL, footnote = NULL, inline = NULL, fixed_thead = NULL, ... )
## S3 method for class 'tangram' html5( object, id = NULL, caption = NULL, fragment = NULL, style = NULL, footnote = NULL, inline = NULL, fixed_thead = NULL, ... )
object |
The cell table to render to HTML5 |
id |
A unique identifier for the table (strongly recommended). If not provided, caption will be used. |
caption |
A string caption for the table |
fragment |
A boolean flag that determines whether a fragment or a complete HTML5 document is generatedf |
style |
A string containing a style filename to include as inline CSS. It first searches the drive for the file, if that fails it looks inside the package for a matching css file. |
footnote |
Any footnotes to include under the table. |
inline |
DEPRECATED |
fixed_thead |
logical; fixes the header using position sticky in CSS defaults to FALSE |
... |
additional arguments to renderer. Unused |
The package includes several css files for styling. At present the following exist: 'hmisc.css', 'lancet.css', 'lancet-stripped.css' and 'nejm.css'
A text string rendering of the given table in HTML5
Given a tangram object create an index representation.
index(object, ...)
index(object, ...)
object |
The cell header to render to HTML5 |
... |
additional arguments to renderer. Unused |
A matrix or list of strings containing key, source and value
Overrides to generate no indexing on labels
## S3 method for class 'cell_label' index(object, id = "tangram", key.len = 4, ...)
## S3 method for class 'cell_label' index(object, id = "tangram", key.len = 4, ...)
object |
cell; The cell for indexing |
id |
character; an additional specifier for the object key |
key.len |
numeric; length of key to generate |
... |
additional arguments to renderer. Unused |
A list of strings containing key, source and value
Given a cell class create an index representation. If no source is specified no index will be generated.
## Default S3 method: index(object, id = "tangram", name = NULL, key.len = 4, ...)
## Default S3 method: index(object, id = "tangram", name = NULL, key.len = 4, ...)
object |
cell; The cell for indexing |
id |
character; an additional specifier for the object key |
name |
character; optional names of elements inside object |
key.len |
numeric; length of generated key |
... |
additional arguments to renderer. Unused |
A list of strings containing key, source and value
Given a cell class create an index representation. If no source is specified no index will be generated.
## S3 method for class 'list' index(object, id = "tangram", key.len = 4, ...)
## S3 method for class 'list' index(object, id = "tangram", key.len = 4, ...)
object |
cell; The cell for indexing |
id |
character; an additional specifier for the object key |
key.len |
numeric; length of key to generate |
... |
additional arguments to renderer. Unused |
A list of strings containing key, source and value
Given a tangram class create an index representation.
## S3 method for class 'tangram' index(object, id = "tangram", key.len = 4, ...)
## S3 method for class 'tangram' index(object, id = "tangram", key.len = 4, ...)
object |
The tangram for indexing |
id |
an additional specifier for the object key |
key.len |
numeric; length of keys generated (affects collision probability) |
... |
additional arguments to renderer. Unused |
A matrix of strings containing key, source and value
Insert a column into a tangram table. Will fill with empty cells is not enough cells are specified.
insert_column(table, after, ..., class = NULL)
insert_column(table, after, ..., class = NULL)
table |
the table to modify |
after |
numeric; The column to position the new row after. Can be zero for inserting a new first row. |
... |
Table cells to insert. Cannot be larger than existing table. |
class |
character; Classes to apply as directives to renderers |
the modified table
Insert a row into a tangram table. Will fill with empty cells is not enough cells are specified.
insert_row(table, after, ..., class = NULL)
insert_row(table, after, ..., class = NULL)
table |
the table to modify |
after |
numeric; The row to position the new row after. Can be zero for inserting a new first row. |
... |
Table cells to insert. Cannot be larger than existing table. |
class |
character; Classes to apply as directives to renderers |
the modified table
Determine if a vector is binomial or not
is.binomial(x, threshold = NA)
is.binomial(x, threshold = NA)
x |
Vector to determine type of |
threshold |
The upper threshold of unique values for which a vector is considered categorical. |
a Boolean: TRUE / FALSE
is.binomial(c(1,2,3)) is.binomial(factor(c("A","B","C"))) is.binomial(factor(c("A","B","B","A"))) is.binomial(factor(c(TRUE, FALSE, TRUE, FALSE))) is.binomial(c('M', 'F', 'M', 'F'), 10)
is.binomial(c(1,2,3)) is.binomial(factor(c("A","B","C"))) is.binomial(factor(c("A","B","B","A"))) is.binomial(factor(c(TRUE, FALSE, TRUE, FALSE))) is.binomial(c('M', 'F', 'M', 'F'), 10)
Determine if a vector is categorical or not
is.categorical(x, threshold = NA)
is.categorical(x, threshold = NA)
x |
Vector to determine type of |
threshold |
The upper threshold of unique values for which a vector is considered categorical. |
A Boolean: TRUE / FALSE
is.categorical(c(1,2,3)) is.categorical(c(rep(1,20), rep(2, 20), rep(3, 20)), threshold=5) is.categorical(c("A","B","B")) is.categorical(factor(c("A","B","C"))) is.categorical(factor(c("A","B","B","A"))) is.categorical(factor(c(TRUE, FALSE, TRUE, FALSE)))
is.categorical(c(1,2,3)) is.categorical(c(rep(1,20), rep(2, 20), rep(3, 20)), threshold=5) is.categorical(c("A","B","B")) is.categorical(factor(c("A","B","C"))) is.categorical(factor(c("A","B","B","A"))) is.categorical(factor(c(TRUE, FALSE, TRUE, FALSE)))
This function should generate a string that uniquely identifies a piece of data present in a table. In a report with multiple tables the id is used to preserve uniqueness.
key(x, id)
key(x, id)
x |
cell object to derive key for |
id |
the unique id of the table being keyed |
This function relies on the object being keyed having at a minimum
character attributes for row
and col
. Additional
specifies for embedded tables are given with subrow
and
subcol
. The row
and col
are automatically
appended when using a table_builder
. However the
subrow
and subcol
must be added by the user to
a cell of a table.
List of lists, should contain a "Type" entry with a function to determine type of vector passed in. Next entries are keyed off returned types from function, and represent the type of a row. The returned list should contain the same list of types, and represents the type of a column. Thus it now returns a function to process the intersection of those two types.
lancet
lancet
An object of class list
of length 5.
Each function here is called when a cell is generated. Overriding these in a formula call will allows one to customize exactly how each cell's contents are generated.
lancet_cell
lancet_cell
An object of class list
of length 8.
A cell object contains a statistical result of a fraction/percentage in nejm style
lancet_fraction(numerator, denominator, format = NULL, ...)
lancet_fraction(numerator, denominator, format = NULL, ...)
numerator |
numeric; The value of the numerator |
denominator |
numeric; The value of the denominator |
format |
numeric or character; a string formatting directive |
... |
optional extra information to attach |
A cell_fraction object.
lancet_fraction(1, 4, 3)
lancet_fraction(1, 4, 3)
Create a mean/sd cell object of the given data in Lancet style.
lancet_mean_sd( x, format = NA, na.rm = TRUE, names = FALSE, type = 8, msd = FALSE, quant = c(0.25, 0.5, 0.75), ... )
lancet_mean_sd( x, format = NA, na.rm = TRUE, names = FALSE, type = 8, msd = FALSE, quant = c(0.25, 0.5, 0.75), ... )
x |
numeric vector whose sample quantiles are wanted. NA and NaN values are not allowed in numeric vectors unless na.rm is TRUE. |
format |
numeric or character; Significant digits or fmt to pass to sprintf |
na.rm |
logical; if true, any NA and NaN's are removed from x before the quantiles are computed. |
names |
logical; ignored. For compatibility with hmisc_iqr |
type |
integer; ignored. For compatibility with hmisc_iqr |
msd |
logical; ignored. For compatibility with hmisc_iqr |
quant |
numeric; ignored. For compatibility with hmisc_iqr |
... |
additional arguments to constructing cell |
A cell object.
require(stats) lancet_mean_sd(rnorm(100), '3')
require(stats) lancet_mean_sd(rnorm(100), '3')
Each of these methods will render the cell object as a LaTeX fragment
latex(object, ...) ## Default S3 method: latex(object, ...) ## S3 method for class 'cell' latex(object, na.blank = TRUE, ...) ## S3 method for class 'cell_label' latex(object, ...) ## S3 method for class 'logical' latex(object, ...) ## S3 method for class 'cell_header' latex(object, ...) ## S3 method for class 'cell_subheader' latex(object, ...) ## S3 method for class 'tangram' latex(object, fragment = TRUE, filename = NULL, append = FALSE, ...)
latex(object, ...) ## Default S3 method: latex(object, ...) ## S3 method for class 'cell' latex(object, na.blank = TRUE, ...) ## S3 method for class 'cell_label' latex(object, ...) ## S3 method for class 'logical' latex(object, ...) ## S3 method for class 'cell_header' latex(object, ...) ## S3 method for class 'cell_subheader' latex(object, ...) ## S3 method for class 'tangram' latex(object, fragment = TRUE, filename = NULL, append = FALSE, ...)
object |
object; the item to render to latex |
... |
additional arguments |
na.blank |
logical; Dispaly NAs as blanks. |
fragment |
logical; Is this a complete LaTeX document or just the table fragment |
filename |
character; filename to write LaTex into |
append |
logical; Should the write be an append operation or overwrite |
There are addition arguments possible to control the rendering, but due to some oddities between CRAN requirements and how R handles defaults (for full details see the source code) they are as follows
* cgroup.just character; The text of the column justification used in the table
* arraystretch numeric; The arraystretch parameter used for vertical spacing
* style character; can be null or "nejm" for different table styling
* rel_size numeric; a scaling to be applied to the entire table, e.g. rel_size=-2
* placement character; placement directive, defaults to "H"
the LaTeX rendering
latex(cell_label("123")) latex(hmisc_iqr(rnorm(20))) latex(hmisc_fraction(45, 137)) tbl <- tangram(drug~bili, pbc, "tbl") latex(tbl)
latex(cell_label("123")) latex(hmisc_iqr(rnorm(20))) latex(hmisc_fraction(45, 137)) tbl <- tangram(drug~bili, pbc, "tbl") latex(tbl)
Pandoc in the current version of RStudio does not allow for setting package options to xcolor and this has made it incompatible with the LaTeX generated by this package. This provides a known working template.
latex_template()
latex_template()
An example header would look like the following:
— title: "A Document Full of Beautiful Tables" output: pdf_document: "'r tangram::latex_template()'" —
filename of LaTeX template
latex_template()
latex_template()
LaTeX safe string conversion. This transforms a string handling Markdown characters and UNICODE as best it can with an automated pass.
latexify(x)
latexify(x)
x |
string to make LaTeX safe |
valid LaTeX code
List of lists, should contain a "Type" entry with a function to determine type of vector passed in. Next entries are keyed off returned types from function, and represent the type of a row. The returned list should contain the same list of types, and represents the type of a column. Thus it now returns a function to process the intersection of those two types.
nejm
nejm
An object of class list
of length 5.
Each function here is called when a cell is generated. Overriding these in a formula call will allows one to customize exactly how each cell's contents are generated.
nejm_cell
nejm_cell
An object of class list
of length 9.
While this serves as the base template for transforms, it is by no means required if one develops their own bundle of data transforms. One can create ay number of cell level styling choices.
A cell object contains a statistical result of a fraction/percentage in nejm style
nejm_fraction(numerator, denominator, format = NULL, ...)
nejm_fraction(numerator, denominator, format = NULL, ...)
numerator |
numeric; The value of the numerator |
denominator |
numeric; The value of the denominator |
format |
numeric or character; a string formatting directive |
... |
optional extra information to attach |
A cell_fraction object.
nejm_fraction(1, 4, 3)
nejm_fraction(1, 4, 3)
Construct a cell which has the 3 interquartile ranges specified.
nejm_iqr( x, format = NA, na.rm = TRUE, names = FALSE, type = 8, msd = FALSE, quant = c(0.25, 0.5, 0.75), ... )
nejm_iqr( x, format = NA, na.rm = TRUE, names = FALSE, type = 8, msd = FALSE, quant = c(0.25, 0.5, 0.75), ... )
x |
numeric vector whose sample quantiles are wanted. NA and NaN values are not allowed in numeric vectors unless na.rm is TRUE. |
format |
numeric or character; Significant digits or fmt to pass to sprintf |
na.rm |
logical; if true, any NA and NaN's are removed from x before the quantiles are computed. |
names |
logical; if true, the result has a names attribute. Set to FALSE for speedup with many probs. |
type |
integer; specify algorithm to use in constructing quantile. See quantile for more information. |
msd |
logical; compute an msd attribute containing mean and standard deviation |
quant |
numeric; The quantiles to display. Should be an odd length vector, since the center value is highlighted. |
... |
additional arguments to constructing cell |
A cell_quantile object.
require(stats) nejm_iqr(rnorm(100), '3')
require(stats) nejm_iqr(rnorm(100), '3')
Construct a cell which has the range of the given data in NEJM style
nejm_range(x, format, ...)
nejm_range(x, format, ...)
x |
numeric vector whose range is desired |
format |
numeric or character; an argument to pass to the formatting function |
... |
additional arguments to passed to cell() |
The parser class for generating abstract syntax trees for given table formulas.
The parser class for generating abstract syntax trees for given table formulas.
R6Class
object.
Aho, A. V., Lam, M. S., Sethi, R., and Ullman, J. D. (2006) Compilers: Principles, Techniques, and Tools, 2nd edition. Addison Wesley.
input
Storage for input string of a formula
pos
The current parsing position
len
The length of the input
new()
Create a parser
Parser$new()
expect()
Specify expectation of next token from lexer
Parser$expect(id)
id
The token id expected in stream, otherwise it's an error
peek()
Peek at the next token from parser
Parser$peek()
eat_whitespace()
Remove white space to find start of next token
Parser$eat_whitespace()
next_token()
Returns next lexical token
Parser$next_token()
format()
Return format string as token from lexical stream
Parser$format()
r_expression()
Return R expression as token from lexical stream
Parser$r_expression()
factor()
Return next factor as token.
Parser$factor()
term()
Parse and return next term in stream
Parser$term()
expression()
Parse and return next expression in stream
Parser$expression()
table_formula()
Parse and return table formula from stream
Parser$table_formula()
run()
Run the parser
Parser$run(x)
x
(character,formula) The table specification to parse
clone()
The objects of this class are cloneable with this method.
Parser$clone(deep = FALSE)
deep
Whether to make a deep clone.
Parser$new()$run("col1 + col2 + col3 ~ drug*age+spiders")
Parser$new()$run("col1 + col2 + col3 ~ drug*age+spiders")
D This data is from the Mayo Clinic trial in primary biliary cirrhosis (PBC) of the liver conducted between 1974 and 1984. A total of 424 PBC patients, referred to Mayo Clinic during that ten-year interval, met eligibility criteria for the randomized placebo controlled trial of the drug D-penicillamine. The first 312 cases in the data set participated in the randomized trial and contain largely complete data. The additional 112 cases did not participate in the clinical trial, but consented to have basic measurements recorded and to be followed for survival. Six of those cases were lost to follow-up shortly after diagnosis, so the data here are on an additional 106 cases as well as the 312 randomized participants.
pbc
pbc
An object of class data.frame
with 418 rows and 19 columns.
A nearly identical data set found in appendix D of Fleming and Harrington; this version has fewer missing values.
Included for use in example from Hmisc.
The pipe operator provides an cbind for tangram tables
## S3 method for class 'tangram' x | y
## S3 method for class 'tangram' x | y
x |
left argument for rbind |
y |
right argument for rbind |
A column wise merged tangram object
Print methods for tangram objects
## S3 method for class 'cell' print(x, ...) ## S3 method for class 'tangram' print(x, ...) ## S3 method for class 'summary.tangram' print(x, ...)
## S3 method for class 'cell' print(x, ...) ## S3 method for class 'tangram' print(x, ...) ## S3 method for class 'summary.tangram' print(x, ...)
x |
object; the item to render |
... |
additional arguments passed to summary |
the text summary
print(cell_label("123")) print(hmisc_iqr(rnorm(20))) print(hmisc_fraction(45, 137)) print(tangram(1,1) %>% row_header("row") %>% col_header(1,2,3) %>% add_col("A","B","C")) print(tangram(drug~bili, pbc))
print(cell_label("123")) print(hmisc_iqr(rnorm(20))) print(hmisc_fraction(45, 137)) print(tangram(1,1) %>% row_header("row") %>% col_header(1,2,3) %>% add_col("A","B","C")) print(tangram(drug~bili, pbc))
Given a function that produces a vector of tangram cells, will generate a table
proc_tab(table, row, column, fun = NULL, overall = FALSE, ...)
proc_tab(table, row, column, fun = NULL, overall = FALSE, ...)
table |
The table builder object |
row |
The row from the abstract syntax tree that parsed the formula |
column |
The column from the abstract syntax tree that parsed the formula |
fun |
The function to apply to the broken out categories |
overall |
Provide a summary of categorical breakdowns |
... |
additional arguments to pass to fun |
Execute the equivalent of an rbind for generated tables
## S3 method for class 'tangram' rbind(..., deparse.level = 1)
## S3 method for class 'tangram' rbind(..., deparse.level = 1)
... |
tangram objects to rbind |
deparse.level |
numeric; not used |
A merged tangram object
Given a vector of data return as strings formatted as requested
render_f(x, format)
render_f(x, format)
x |
numeric; the data to format. Must work with quantile function. |
format |
numeric or character; If numeric preserve that many position past the decimal, if character pass directly into sprintf as format string |
character; formatted values as character strings
render_f(rnorm(5), 3) render_f(round(rnorm(5), 2), "%010.03f")
render_f(rnorm(5), 3) render_f(round(rnorm(5), 2), "%010.03f")
This functions detects if knitr is loaded, and does it's best to determine the output format from knitr and returns the appropriate rendering function.
render_route_tangram()
render_route_tangram()
A rendering function to use
Replace a cell in a table
replace_cell(table, row, col, object, ...)
replace_cell(table, row, col, object, ...)
table |
the tangram table to modify |
row |
numeric; The row to modify |
col |
numeric; The column to modify |
object |
The cell or object to replace in a table |
... |
Additional parameters passed to cell function if not given a cell object |
the modified table
Given a cell object generate the corresponding piece of an Rmd table
rmd(object, key = FALSE, ...) ## Default S3 method: rmd(object, key = FALSE, ...) ## S3 method for class 'cell' rmd(object, key = FALSE, ...) ## S3 method for class 'cell_n' rmd(object, key = FALSE, ...) ## S3 method for class 'tangram' rmd(object, key = NULL, append = FALSE, pad = 10, ...)
rmd(object, key = FALSE, ...) ## Default S3 method: rmd(object, key = FALSE, ...) ## S3 method for class 'cell' rmd(object, key = FALSE, ...) ## S3 method for class 'cell_n' rmd(object, key = FALSE, ...) ## S3 method for class 'tangram' rmd(object, key = NULL, append = FALSE, pad = 10, ...)
object |
The cell_fstat for indexing |
key |
A filename to write key values into. Can be false if no key file is desired. |
... |
additional arguments to renderer. Unused |
append |
logical; Should the key file be appended too, or overwritten |
pad |
numeric; Minimum width of columns can be a single or vector of numerics. |
A string representation of the table
rmd(tangram(drug ~ bili, pbc))
rmd(tangram(drug ~ bili, pbc))
Number of rows/cols in provided object
rows(x) cols(x) ## S3 method for class 'list' rows(x) ## S3 method for class 'list' cols(x)
rows(x) cols(x) ## S3 method for class 'list' rows(x) ## S3 method for class 'list' cols(x)
x |
object; object to determine requested count |
S3 rtf Method function for use on abstract table class
rtf(object, id, ...)
rtf(object, id, ...)
object |
The cell to render to RTF |
id |
A unique identifier for the table (strongly recommended). If not provided, caption will be used. |
... |
additional arguments to renderer. Unused at present. |
A text string rendering of the given table
Gives a warning and produces an empty cell
## Default S3 method: rtf(object, id, ...)
## Default S3 method: rtf(object, id, ...)
object |
The cell to render to RTF |
id |
A unique identifier for traceability |
... |
additional arguments to renderer. Unused |
A RTF string rendering of the given cell
Given a tangram class, a series of conversion creates an rtf representation of the table.
## S3 method for class 'tangram' rtf( object, id = NA, caption = NA, fragment = FALSE, widths = NA, footnote = NA, filename = NA, append = FALSE, point = 9, ... )
## S3 method for class 'tangram' rtf( object, id = NA, caption = NA, fragment = FALSE, widths = NA, footnote = NA, filename = NA, append = FALSE, point = 9, ... )
object |
The cell table to render to RTF |
id |
A unique identifier for the table (strongly recommended). |
caption |
A string caption for the table |
fragment |
A boolean flag that determines whether a fragment or a complete RTF document is generatedf |
widths |
RTF requires specified left margin and column widths, this allows user control over these (inches) |
footnote |
Any footnotes to include under the table. |
filename |
A filename to write resulting rtf file to |
append |
A boolean for whether or not to append to given filename |
point |
Main font point size |
... |
additional arguments Fto renderer. Unused |
A text string rendering of the given table
Given a table, select the specified column(s)
select_col(table, col)
select_col(table, col)
table |
the table to modify |
col |
vector containing column(s) to select |
the modified table
Given a table, select the specified rows
select_row(table, row)
select_row(table, row)
table |
the table to modify |
row |
vector with row numbers to select |
the modified table
List of lists, should contain a "Type" entry with a function to determine type of vector passed in. Next entries are keyed off returned types from function, and represent the type of a row. The returned list should contain the same list of types, and represents the type of a column. Thus it now returns a function to process the intersection of those two types.
smd
smd
An object of class list
of length 5.
Each function here is called when a cell is generated. Overriding these in a formula call will allows one to customize exactly how each cell's contents are generated.
smd_cell
smd_cell
An object of class list
of length 7.
While this serves as the base template for transforms, it is by no means required if one develops their own bundle of data transforms. One can create ay number of cell level styling choices.
Given a row and column object from the parser apply a Kruskal test and output the results horizontally. 1 X (n + no. categories + test statistic)
smd_compare( table, row, column, cell_style, style, smdformat = NULL, pformat = NULL, weight = NULL, test = FALSE, ... )
smd_compare( table, row, column, cell_style, style, smdformat = NULL, pformat = NULL, weight = NULL, test = FALSE, ... )
table |
The table object to modify |
row |
The row variable object to use (numerical) |
column |
The column variable to use (categorical) |
cell_style |
list; cell styling functions |
style |
character; chosen styling to final table |
smdformat |
numeric, character or function; A formatting directive to be applied to smd |
pformat |
numeric, character or function; A formatting directive to be applied to p-values |
weight |
numeric; Vector of weights to apply to data when computing SMD |
test |
logical; include statistical test results |
... |
absorbs additional arugments. Unused at present. |
The modified table object
Create a contingency table with SMD given a row column of a formula
smd_contingency( table, row, column, cell_style, style, smdformat = NULL, collapse_single = TRUE, weight = NULL, test = FALSE, pformat = NULL, ... )
smd_contingency( table, row, column, cell_style, style, smdformat = NULL, collapse_single = TRUE, weight = NULL, test = FALSE, pformat = NULL, ... )
table |
The tablebuilder object |
row |
The row node from the parser of the formula |
column |
The column node provided by the parser of the formula |
cell_style |
A list of all individual cell stylings to apply |
style |
The global style to apply. |
smdformat |
The format command to apply to smd |
collapse_single |
Should single factor variables be collapsed |
weight |
Any weighting to apply to data for computation of SMD |
test |
logical; include statistical test results |
pformat |
numeric, character or function; A formatting directive to be applied to p-values |
... |
Additional arguments to provide cell generation functions |
The resulting sub table constructed
Create an SMD distance cell. It calls the smd function then formats the result. If the result rounds to all zeros then it appends a less than sign and bumps the least significant digit to one.
smd_dist(x, group, format, weight = NULL, ...)
smd_dist(x, group, format, weight = NULL, ...)
x |
vector; variable to evaluate with smd |
group |
factor; A grouping to apply. Must have 2 levels. |
format |
formatting to apply to result |
weight |
numeric; Weighting to apply to computation. Defaults to NULL. |
... |
additional arguments to pass to cell generation |
a tangram cell
Create a fraction cell in the smd transform. In this instance it print the numerator followed by percentage in parenthesis.
smd_fraction(num, den, format, ...)
smd_fraction(num, den, format, ...)
num |
numerator of fraction |
den |
denominator of fraction |
format |
formatting to apply to result |
... |
additional arguments to pass to cell generation |
a tangram cell
Create an SMD mean and standard deviation cell. In this case it prints the mean with the standard deviation in parenthesis
smd_meansd(x, format, ...)
smd_meansd(x, format, ...)
x |
vector; variable to evaluate with smd |
format |
formatting to apply to result |
... |
additional arguments to pass to cell generation |
a tangram cell
Compute the standardized mean distance between 2 groups for numerical or categorical information. Using method described in 'A unifed approach to measuring the effect size between two groups using SAS' by Dongsheng Yand and Jarrod E. Dalton, 2012. SAS Global Forum 2012
standard_difference(x, group, weight = NULL)
standard_difference(x, group, weight = NULL)
x |
vector; data to estimate effect size for groups |
group |
vector; the grouping variable. |
weight |
vector; weighting information for x |
List of lists, should contain a "Type" entry with a function to determine type of vector passed in. Next entries are keyed off returned types from function, and represent the type of a row. The returned list should contain the same list of types, and represents the type of a column. Thus it now returns a function to process the intersection of those two types. There are additionally a list of cell tranforms that can be overridden and a default footnote if none is specified.
summarize_kruskal_horz( table, row, column, cell_style, pformat = NULL, msd = FALSE, quant = c(0.25, 0.5, 0.75), overall = NULL, test = FALSE, ... ) summarize_kruskal_vert( table, row, column, cell_style, collapse_single = TRUE, pformat = NULL, msd = FALSE, test = FALSE, ... ) summarize_chisq( table, row, column, cell_style, pformat = NULL, collapse_single = TRUE, overall = NULL, test = FALSE, row_percents = FALSE, useNA = "no", ... ) summarize_spearman( table, row, column, cell_style, pformat = NULL, test = FALSE, ... ) hmisc
summarize_kruskal_horz( table, row, column, cell_style, pformat = NULL, msd = FALSE, quant = c(0.25, 0.5, 0.75), overall = NULL, test = FALSE, ... ) summarize_kruskal_vert( table, row, column, cell_style, collapse_single = TRUE, pformat = NULL, msd = FALSE, test = FALSE, ... ) summarize_chisq( table, row, column, cell_style, pformat = NULL, collapse_single = TRUE, overall = NULL, test = FALSE, row_percents = FALSE, useNA = "no", ... ) summarize_spearman( table, row, column, cell_style, pformat = NULL, test = FALSE, ... ) hmisc
table |
The table object to modify |
row |
The row variable object to use (numerical) |
column |
The column variable to use (categorical) |
cell_style |
list; cell styling functions |
pformat |
numeric, character or function; A formatting directive to be applied to p-values |
msd |
logical; Include mean and standard deviation with quantile statistics |
quant |
numeric; Vector of quantiles to include. Should be an odd number since the middle value is highlighted on display. |
overall |
logical or character; Include overall summary statistics for a categorical column. Character values are assumed to be true and used as column header. |
test |
logical or function; include statistical test results. Function signature must be function(row, col, cell_style, ...) |
... |
absorbs additional arugments. Unused at present. |
collapse_single |
logical; default TRUE. Categorical variables with a two values collapse to single row. |
row_percents |
logical; use denominator across rows instead of columns. |
useNA |
character; Specifies whether to include NA counts in the table. The allowed values correspond to never "no" (Default), only if the count is positive "ifany" and even for zero counts "always". An NA column is always excluded. |
An object of class list
of length 5.
The modified table object
summarize_kruskal_horz
Given a row and column object apply a Kruskal test and output the results horizontally. 1 X (n + no. categories + test statistic)
summarize_kruskal_vert
Given a row and column object from the parser apply a Kruskal test and output the results vertically (#Categories+1) X (N, Summary, Statistic)
summarize_chisq
Given a row and column object from the parser apply a chi^2 test and output the results
summarize_spearman
Given a row and column object from the parser apply a Spearman test and output the results in a 1X3 format.
hmisc
hmisc <- list( Type = hmisc_data_type, Numerical = list( Numerical = summarize_spearman, Categorical = summarize_kruskal_horz ), Categorical = list( Numerical = summarize_kruskal_vert, Categorical = summarize_chisq ), Cell = hmisc_cell, Footnote = "N is the number of non-missing value. ^1^Kruskal-Wallis. ^2^Pearson. ^3^Wilcoxon." )
hmisc_data_type
, tangram
, hmisc_cell
Given a row and column object from the parser apply a Kruskal test and output the results horizontally. 5 X (n + no. categories + test statistic)
summarize_nejm_horz( table, row, column, cell_style, pformat = NULL, msd = FALSE, quant = c(0.25, 0.5, 0.75), overall = NULL, test = FALSE, useNA = "no", ... )
summarize_nejm_horz( table, row, column, cell_style, pformat = NULL, msd = FALSE, quant = c(0.25, 0.5, 0.75), overall = NULL, test = FALSE, useNA = "no", ... )
table |
The table object to modify |
row |
The row variable object to use (numerical) |
column |
The column variable to use (categorical) |
cell_style |
list; cell styling functions |
pformat |
numeric, character or function; A formatting directive to be applied to p-values |
msd |
logical; Include mean and standard deviation with quantile statistics |
quant |
numeric; Vector of quantiles to include. Should be an odd number since the middle value is highlighted on display. |
overall |
logical or character; Include overall summary statistics for a categorical column. Character values are assumed to be true and used as column header. |
test |
logical or function; include statistical test results. Function signature must be function(row, col, cell_style, ...) |
useNA |
character; Specifies whether to include NA counts in the table. The allowed values correspond to never "no" (Default), only if the count is positive "ifany" and even for zero counts "always". An NA column is always excluded. |
... |
absorbs additional arugments. Unused at present. |
The modified table object
Given a row and column object from the parser apply a Kruskal test and output the results vertically (#Categories+1) X (N, Summary, Statistic)
summarize_nejm_vert( table, row, column, cell_style, collapse_single = TRUE, pformat = NULL, msd = FALSE, test = FALSE, quant = c(0.25, 0.5, 0.75), ... )
summarize_nejm_vert( table, row, column, cell_style, collapse_single = TRUE, pformat = NULL, msd = FALSE, test = FALSE, quant = c(0.25, 0.5, 0.75), ... )
table |
The table object to modify |
row |
The row variable object to use (categorical) |
column |
The column variable to use (numerical) |
cell_style |
list; cell styling functions |
collapse_single |
logical; default TRUE. Categorical variables with a two values collapse to single row. |
pformat |
numeric, character or function; A formatting directive to be applied to p-values |
msd |
logical; include msd in summary |
test |
logical; include statistical test results |
quant |
numeric; vector of quantiles to include. Should be an odd number since the middle value is highlighted on display. |
... |
absorbs additional arugments. Unused at present. |
The modified table object
A tangram is a summary, so it returns itself. Otherwise convert to a text representation.
## S3 method for class 'tangram' summary(object, ...) ## S3 method for class 'cell' summary(object, ...)
## S3 method for class 'tangram' summary(object, ...) ## S3 method for class 'cell' summary(object, ...)
object |
object; the item to render |
... |
additional arguments passed to summary |
the text summary
summary(cell_label("123")) summary(hmisc_iqr(rnorm(20))) summary(hmisc_fraction(45, 137)) summary(tangram(1,1) %>% row_header("row") %>% col_header(1,2,3) %>% add_col("A","B","C")) summary(tangram(drug~bili, pbc))
summary(cell_label("123")) summary(hmisc_iqr(rnorm(20))) summary(hmisc_fraction(45, 137)) summary(tangram(1,1) %>% row_header("row") %>% col_header(1,2,3) %>% add_col("A","B","C")) summary(tangram(drug~bili, pbc))
Flattening function to expanded embedded tables inside table cells.
table_flatten(table)
table_flatten(table)
table |
the table object to flatten |
the flattened table object
The tangram method is the principal method to create tables. It uses
R3 method dispatch. If one specifies rows and columns, one gets an empty
table of the given size. A formula or character will invoke the parser
and process the specified data into a table like Hmisc::summaryM
.
Given an rms
object it will summarize that model in a table. A
data.frame
is converted directly into a table as well for later
rendering. Can create tables from summary.rms(), anova.rms(), and other rms object info to create a
single pretty table of model results. The rms and Hmisc packages are required.
## S3 method for class 'clmm2' tangram( x, id = NULL, style = "hmisc", caption = NULL, footnote = NULL, digits = NULL, ... ) ## S3 method for class 'summary.clmm2' tangram( x, id = NULL, style = "hmisc", caption = NULL, footnote = NULL, digits = NULL, pformat = "%1.3f", include_p = FALSE, ... ) tangram(x, ...) ## S3 method for class 'numeric' tangram( x, cols, id = NULL, caption = NULL, style = "hmisc", footnote = NULL, fixed_thead = NULL, ... ) ## S3 method for class 'anova.lme' tangram( x, id = NULL, style = "hmisc", caption = NULL, footnote = NULL, digits = NULL, fixed_thead = NULL, ... ) ## S3 method for class 'data.frame' tangram( x, id = NULL, colheader = NA, caption = NULL, style = "hmisc", footnote = NULL, after = NA, quant = seq(0, 1, 0.25), msd = TRUE, as.character = NULL, fixed_thead = NULL, exclude = NULL, ... ) ## S3 method for class 'formula' tangram( x, data = NULL, id = NULL, transforms = NULL, caption = NULL, style = "hmisc", footnote = NULL, after = NA, digits = NA, fixed_thead = NULL, exclude = NULL, ... ) ## S3 method for class 'character' tangram(x, ...) ## S3 method for class 'table' tangram( x, id = NULL, percents = FALSE, digits = 1, test = FALSE, footnote = NULL, ... ) ## S3 method for class 'ftable' tangram(x, id = NULL, ...) ## S3 method for class 'matrix' tangram(x, digits = NULL, ...) ## S3 method for class 'tbl_df' tangram(x, ...) ## S3 method for class 'lm' tangram(x, ...) ## S3 method for class 'summary.lm' tangram(x, id = NULL, format = NULL, pformat = NULL, tformat = NULL, ...) ## S3 method for class 'rms' tangram( x, data = NULL, short.labels = NULL, footnote = NULL, rnd.digits = 2, rnd.stats = rnd.digits, ... )
## S3 method for class 'clmm2' tangram( x, id = NULL, style = "hmisc", caption = NULL, footnote = NULL, digits = NULL, ... ) ## S3 method for class 'summary.clmm2' tangram( x, id = NULL, style = "hmisc", caption = NULL, footnote = NULL, digits = NULL, pformat = "%1.3f", include_p = FALSE, ... ) tangram(x, ...) ## S3 method for class 'numeric' tangram( x, cols, id = NULL, caption = NULL, style = "hmisc", footnote = NULL, fixed_thead = NULL, ... ) ## S3 method for class 'anova.lme' tangram( x, id = NULL, style = "hmisc", caption = NULL, footnote = NULL, digits = NULL, fixed_thead = NULL, ... ) ## S3 method for class 'data.frame' tangram( x, id = NULL, colheader = NA, caption = NULL, style = "hmisc", footnote = NULL, after = NA, quant = seq(0, 1, 0.25), msd = TRUE, as.character = NULL, fixed_thead = NULL, exclude = NULL, ... ) ## S3 method for class 'formula' tangram( x, data = NULL, id = NULL, transforms = NULL, caption = NULL, style = "hmisc", footnote = NULL, after = NA, digits = NA, fixed_thead = NULL, exclude = NULL, ... ) ## S3 method for class 'character' tangram(x, ...) ## S3 method for class 'table' tangram( x, id = NULL, percents = FALSE, digits = 1, test = FALSE, footnote = NULL, ... ) ## S3 method for class 'ftable' tangram(x, id = NULL, ...) ## S3 method for class 'matrix' tangram(x, digits = NULL, ...) ## S3 method for class 'tbl_df' tangram(x, ...) ## S3 method for class 'lm' tangram(x, ...) ## S3 method for class 'summary.lm' tangram(x, id = NULL, format = NULL, pformat = NULL, tformat = NULL, ...) ## S3 method for class 'rms' tangram( x, data = NULL, short.labels = NULL, footnote = NULL, rnd.digits = 2, rnd.stats = rnd.digits, ... )
x |
object; depends on S3 type, could be rows, formula, string of a formula, data.frame or numerical rows, an rms.model |
id |
character; A unique charcter id used to identify this table over multiple runs. No spaces. |
style |
character; Desired rendering style, currently supports "hmisc", "nejm", and "lancet". Defaults to "hmisc" |
caption |
character; A string with the desired caption |
footnote |
character; A vector of character strings as footnotes |
digits |
numeric; default number of digits to use for display of numerics |
... |
addition models or data supplied to table construction routines |
pformat |
function or character; A function to format p values |
include_p |
logical; Include p-value when printing statistic |
cols |
numeric; An integer of the number of cols to create |
fixed_thead |
logical; On conversion to HTML5 should headers be treated as fixed? |
colheader |
character; Use as column headers in final table |
after |
function or list of functions; one or more functions to further process an abstract table |
quant |
numeric; A vector of quantiles to use for summaries |
msd |
logical; Include mean and standard deviation in numeric summary |
as.character |
logical; if true data.frames all variables are passed through as.character and no numerical summary is provided. |
exclude |
vector or list; When x is a data.frame this exclusion criteria is applied to the data. If this is a list then each list pair is the (column name, criteria). It is preferred to use a list to be specific. |
data |
data.frame; data to use for rendering tangram object |
transforms |
list of lists of functions; that contain the transformation to apply for summarization |
percents |
logical; Display percents when rendering a table object. Defaults to FALSE |
test |
logical or function; Perform default test or a statistical function that will return a test result when passed a row and column |
format |
numeric or character; Format to apply to statistic |
tformat |
numeric or character; format to apply to t-value |
short.labels |
numeric; Named vector of variable labels to replace in interaction rows. Must be in format c("variable name" = "shortened label"). |
rnd.digits |
numeric; Digits to round reference, comparison, result and CI values to. Defaults to 2. |
rnd.stats |
numeric; Digits to round model LR, R2, etc to. Defaults to rnd.digits. |
Note that additional arguments are passed to any subsequent transform. This means that a lot of possible arguments are not documented here but in the transform applied. Examine their documentations for additional possible arguments if needed.
A tangram object (a table).
Possible transforms are (see hmisc
) (*default*),
nejm
and lancet
.
tangram(1, 1) tangram(data.frame(x=1:3, y=c('a','b','c')), id="mytbl1") tangram(drug ~ bili + albumin + protime + sex + age + spiders, pbc, id="mytbl2") tangram("drug~bili+albumin+stage::Categorical+protime+sex+age+spiders", pbc,"mytbl3")
tangram(1, 1) tangram(data.frame(x=1:3, y=c('a','b','c')), id="mytbl1") tangram(drug ~ bili + albumin + protime + sex + age + spiders, pbc, id="mytbl2") tangram("drug~bili+albumin+stage::Categorical+protime+sex+age+spiders", pbc,"mytbl3")
A token in the formula grammar
A token in the formula grammar
R6Class
object.
id
The token identifier, E.g. "LPAREN"
name
Information about the token, useful with IDENTIFIERs.
new()
Construct a lexical token
Token$new(id, name = "")
id
(character) The lexical id of the token
name
(character) Additional token information if needed
clone()
The objects of this class are cloneable with this method.
Token$clone(deep = FALSE)
deep
Whether to make a deep clone.