Title: | Tables so Beautifully Fine-Tuned You Will Believe It's Magic |
---|---|
Description: | The introduction of the 'broom' package has made converting model objects into data frames as simple as a single function. While the 'broom' package focuses on providing tidy data frames that can be used in advanced analysis, it deliberately stops short of providing functionality for reporting models in publication-ready tables. 'pixiedust' provides this functionality with a programming interface intended to be similar to 'ggplot2's system of layers with fine tuned control over each cell of the table. Options for output include printing to the console and to the common markdown formats (markdown, HTML, and LaTeX). With a little 'pixiedust' (and happy thoughts) tables can really fly. |
Authors: | Benjamin Nutter [aut, cre], David Kretch [ctb] |
Maintainer: | Benjamin Nutter <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.9.4 |
Built: | 2025-02-02 04:41:19 UTC |
Source: | https://github.com/nutterb/pixiedust |
Chain together multiple operations and save to the object at the start of the chain. See 'magrittr' documentation for details.
lhs %<>% rhs
lhs %<>% rhs
lhs , rhs
|
A data set and function to apply it to |
Pipe an object forward into a function or call expression
lhs %>% rhs
lhs %>% rhs
lhs , rhs
|
A dataset and function to apply to it |
dust
Object to Data FrameSprinkles are applied to the dust
object
as if it were being prepared for printing to the console.
However, instead of printing, the object is returned
as a single data frame.
## S3 method for class 'dust' as.data.frame(x, ..., sprinkled = TRUE) ## S3 method for class 'dust_list' as.data.frame(x, ...)
## S3 method for class 'dust' as.data.frame(x, ..., sprinkled = TRUE) ## S3 method for class 'dust_list' as.data.frame(x, ...)
x |
A |
... |
Arguments to be passed to other methods. Currently unused. |
sprinkled |
Logical. If |
In its current state, this can be a fairly inefficient function
as the table, if the longtable option is in use, will be built in
a for
loop and bound together using rbind
. This isn't
really intended for large tables, but may be of assistance when
there isn't a sprinkle that does what you want to do. (You can
at least pull out the object as a data frame and do your own
post processing).
Accepts an object of class dust
or dust_list
Accepts a logical(1)
indicating if the sprinkles should
be applied to the data.
For a dust
object, returns an object of class
data.frame
For a dust_list
object, returns a list of objects of class
data.frame
Benjamin Nutter
fit <- lm(mpg ~ qsec + factor(am) + wt * factor(gear), data = mtcars) Dust <- dust(fit) %>% sprinkle(cols = 2:4, round = 2) %>% sprinkle(cols = 5, fn = quote(pvalString(value))) %>% sprinkle(cols = 3, font_color = "#DA70D6") %>% sprinkle_print_method("html") as.data.frame(Dust)
fit <- lm(mpg ~ qsec + factor(am) + wt * factor(gear), data = mtcars) Dust <- dust(fit) %>% sprinkle(cols = 2:4, round = 2) %>% sprinkle(cols = 5, fn = quote(pvalString(value))) %>% sprinkle(cols = 3, font_color = "#DA70D6") %>% sprinkle_print_method("html") as.data.frame(Dust)
Dust tables consist of four primary components that are
built together to create a full table. Namely, the head
, the
body
, the interfoot
, and the foot
. Dust tables
also contain a table-wide attributes border_collapse
and
longtable
as well as a print_method
element.
dust(object, ...) ## Default S3 method: dust( object, ..., tidy_df = FALSE, keep_rownames = FALSE, glance_foot = FALSE, glance_stats = NULL, col_pairs = 2, byrow = FALSE, descriptors = "term", numeric_level = c("term", "term_plain", "label"), label = NULL, caption = NULL, caption_number = getOption("pixied_caption_number", TRUE), justify = getOption("pixie_justify", "center"), float = getOption("pixie_float", TRUE), longtable = getOption("pixie_longtable", FALSE), hhline = getOption("pixie_hhline", FALSE), bookdown = getOption("pixie_bookdown", FALSE), border_collapse = getOption("pixie_border_collapse", "collapse"), tabcolsep = getOption("pixie_tabcolsep", 6), fixed_header = getOption("pixie_fixed_header", FALSE), html_preserve = getOption("pixie_html_preserve", TRUE) ) ## S3 method for class 'grouped_df' dust(object, ungroup = TRUE, ...) ## S3 method for class 'list' dust(object, ...) redust(x, table, part = c("head", "foot", "interfoot", "body")) ## Default S3 method: redust(x, table, part = c("head", "foot", "interfoot", "body")) ## S3 method for class 'dust_list' redust(x, table, part = c("head", "foot", "interfoot", "body"))
dust(object, ...) ## Default S3 method: dust( object, ..., tidy_df = FALSE, keep_rownames = FALSE, glance_foot = FALSE, glance_stats = NULL, col_pairs = 2, byrow = FALSE, descriptors = "term", numeric_level = c("term", "term_plain", "label"), label = NULL, caption = NULL, caption_number = getOption("pixied_caption_number", TRUE), justify = getOption("pixie_justify", "center"), float = getOption("pixie_float", TRUE), longtable = getOption("pixie_longtable", FALSE), hhline = getOption("pixie_hhline", FALSE), bookdown = getOption("pixie_bookdown", FALSE), border_collapse = getOption("pixie_border_collapse", "collapse"), tabcolsep = getOption("pixie_tabcolsep", 6), fixed_header = getOption("pixie_fixed_header", FALSE), html_preserve = getOption("pixie_html_preserve", TRUE) ) ## S3 method for class 'grouped_df' dust(object, ungroup = TRUE, ...) ## S3 method for class 'list' dust(object, ...) redust(x, table, part = c("head", "foot", "interfoot", "body")) ## Default S3 method: redust(x, table, part = c("head", "foot", "interfoot", "body")) ## S3 method for class 'dust_list' redust(x, table, part = c("head", "foot", "interfoot", "body"))
object |
An object that has a |
... |
Additional arguments to pass to |
tidy_df |
When |
keep_rownames |
When |
glance_foot |
Arrange the glance statistics for the |
glance_stats |
A character vector giving the names of the glance statistics
to put in the output. When |
col_pairs |
An integer indicating the number of column-pairings for the
glance output. This must be less than half the total number of columns,
as each column-pairing includes a statistic name and value. See the full
documentation for the unexported function |
byrow |
A logical, defaulting to |
descriptors |
A character vector indicating the descriptors to
be used in the table. Acceptable inputs are |
numeric_level |
A character string that determines which descriptor
is used for numeric variables in the |
label |
|
caption |
A character string giving the caption for the table. |
caption_number |
|
justify |
|
float |
A logical used only in LaTeX output. When |
longtable |
Allows the user to print a table in multiple sections.
This is useful when
a table has more rows than will fit on a printed page. Acceptable inputs are |
hhline |
Logical. When |
bookdown |
Logical. When |
border_collapse |
|
tabcolsep |
|
fixed_header |
|
html_preserve |
|
ungroup |
Used when a |
x |
A dust object |
table |
A data frame of similar dimensions of the part being replaced. |
part |
The part of the table to replace with |
The head
object describes what each column of the table
represents. By default, the head is a single row, but multi row headers
may be provided. Note that multirow headers may not render in markdown
or console output as intended, though rendering in HTML and LaTeX is
fairly reliable. In longtables (tables broken over multiple pages),
the head
appears at the top of each table portion.
The body
object gives the main body of information. In long tables,
this section is broken into portions, ideally with one portion per page.
The interfoot
object is an optional table to be placed at the
bottom of longtable portions with the exception of the last portion. A
well designed interfoot
can convey to the user that the table
continues on the next page.
The foot
object is the table that appears at the end of the
completed table. For model objects, it is recommended that the
glance
statistics be used to display model fit
statistics.
The border_collapse
object applies to an entire HTML table. It
indicates if the borders should form a single line or distinct lines.
The longtable
object determines how many rows per page are printed.
By default, all content is printed as a single table. Using the
longtable
argument in the sprinkle
function can change this
setting.
The table_width
element is specific to LaTeX tables. This is a reference
value for when column widths are specified in terms of the %
units. For
example, a column width of 20%
will be defined as table_width * .20
.
The value in table_width
is assumed to be in inches and defaults to 6.
The tabcolsep
object determines the spacing between columns in a
LaTeX table in pt. By default, it is set at 6.
The print_method
object determines how the table is rendered when
the print
method is invoked. The default is to print to the
console.
Many of these options may be set globally. See
pixiedust
for a complete list of package options.
Returns an object of class dust
When using markdown, math symbols and greek letters may be employed as
they would within a markdown document. For example, "$\alpha$"
will render as the lower case Greek alpha. Math symbols may be rendered
in the same manner.
Benjamin Nutter
tidy
glance_foot
tidy_levels_labels
pixiedust
get_dust_part
for extracting parts of the dust
object
in order to build custom headers and/or footers.
x <- dust(lm(mpg ~ qsec + factor(am), data = mtcars)) x
x <- dust(lm(mpg ~ qsec + factor(am), data = mtcars)) x
Tables with a fixed header may be generated to permit the headings to remain visible with the data. The CSS is not difficult, but it not-trivial and requires some coordination across a few parts. This functions standardizes the generation of the CSS code using as few elements as possible. Note that there is potential for conflicts with existing CSS in this method.
fixed_header_css( fixed_header_class_name = "pixie-fixed", scroll_body_height = 300, scroll_body_height_units = "px", scroll_body_background_color = "white", fixed_header_height = 20, fixed_header_height_units = "px", fixed_header_text_height = fixed_header_height/2, fixed_header_text_height_units = "px", fixed_header_background_color = "white", pretty = TRUE )
fixed_header_css( fixed_header_class_name = "pixie-fixed", scroll_body_height = 300, scroll_body_height_units = "px", scroll_body_background_color = "white", fixed_header_height = 20, fixed_header_height_units = "px", fixed_header_text_height = fixed_header_height/2, fixed_header_text_height_units = "px", fixed_header_background_color = "white", pretty = TRUE )
fixed_header_class_name |
|
scroll_body_height |
|
scroll_body_height_units |
|
scroll_body_background_color |
|
fixed_header_height |
|
fixed_header_height_units |
|
fixed_header_text_height |
|
fixed_header_text_height_units |
|
fixed_header_background_color |
|
pretty |
|
CSS doesn't make this kind of table natural. The solution to
generate the fixed headers used by pixiedust
is probably not the
best solution in terms of CSS design. It is, however, the most conducive
to generating dynamically on the fly.
The fixed header table requires nesting several HTML elements.
a div
tag is used to control the alignment of the table
a section
tag is used to set up the header row that remains fixed.
a div
that sets the height of the scrollable body
the table
tag establishes the actual table.
The th
tags inside the table are set to full transparency and
the content of the headers is duplicated in a div
within the
th
tag to display the content.
To accomplish these tasks, some CSS is exported with the table and placed in the document immediately before the table. Read further to understand the conflicts that may arise if you are using custom CSS specifications in your documents.
Because of all of the shenanigans involved, exporting the CSS with the tables
may result in conflicts with your custom CSS. Most importantly, any CSS
you have applied to the th
or td
tags may be overwritten.
If you are using custom CSS, you may want to consider using
include_fixed_header_css = FALSE
and then utilizing
fixed_header_css
to generate CSS you can include in your
CSS file to provide the fixed headers. The code generated by
fixed_header_css
ought to be placed before your definitions for
td
and th
.
To get the same header design in the fixed table, you will want to modify
the .th-pixie-fixed div
definition in the CSS to match your desired
th
definition.
The code produced by fixed_header_css
will include comments where
there is potential for a CSS conflict.
If pretty = TRUE
print results to the console.
If pretty = FALSE
Return a character string of length 1.
Cast an error if scroll_body_height
is not integerish(1)
Cast an error if scroll_body_height_units
is not character(1)
Cast an error if scroll_body_background_color
is not character(1)
Cast an error if scroll_body_background_color
is not a valid color.
Cast an error if fixed_header_height
is not integerish(1)
Cast an error if fixed_header_height_units
is not character(1)
Cast an error if fixed_header_text_height
is not numeric(1)
Cast an error if fixed_header_text_height_units
is not character(1)
Cast an error if fixed_header_background_color
is not character(1)
Cast an error if fixed_header_background_color
is not a valid color.
Cast an error if pretty
is not logical(1)
Jonas Schubert Erlandsson. https://jsfiddle.net/dPixie/byB9d/3/
Tidy multiple models and display coefficients and test statistics in a side-by-side format.
gaze( ..., include_glance = TRUE, glance_vars = c("adj.r.squared", "sigma", "AIC"), digits = 3 )
gaze( ..., include_glance = TRUE, glance_vars = c("adj.r.squared", "sigma", "AIC"), digits = 3 )
... |
models to be tidied. Arguments may be named or unnamed. For named arguments, the model will be identfied by the argument name; for unnamed arguments, the object name will be the identifier. |
include_glance |
|
glance_vars |
|
digits |
|
This function is still in development. Significant stars will be added in a future version. Note that function defaults may be subject to change.
Return a data frame object
Cast an error if include_glance
is not logical(1)
Cast an error if glance_vars
is not a character
vector.
Cast an error if digits
is not "integerish(1)"
.
fit1 <- lm(mpg ~ qsec + am + wt + gear + factor(vs), data = mtcars) fit2 <- lm(mpg ~ am + wt + gear + factor(vs), data = mtcars) gaze(fit1, fit2) gaze(with_qsec = fit1, without_qsec = fit2) gaze(fit1, fit2, include_glance = FALSE) gaze(fit1, fit2, glance_vars = c("AIC", "BIC"))
fit1 <- lm(mpg ~ qsec + am + wt + gear + factor(vs), data = mtcars) fit2 <- lm(mpg ~ am + wt + gear + factor(vs), data = mtcars) gaze(fit1, fit2) gaze(with_qsec = fit1, without_qsec = fit2) gaze(fit1, fit2, include_glance = FALSE) gaze(fit1, fit2, glance_vars = c("AIC", "BIC"))
dust
ObjectMaking customized table headers and footers requires a
data frame be added to the dust
object that has the same
column dimension as the rest of the table. In order to reduce the
inconvenience of counting columns, get_dust_part
extracts the
data frame portion currently in use. This ensures the column dimension
is correct with the current values, and provides an object suitable
for editing.
get_dust_part(x, part = c("head", "foot", "interfoot", "body"))
get_dust_part(x, part = c("head", "foot", "interfoot", "body"))
x |
An object of class |
part |
|
an object of class data.frame
Return, as a data frame, the part of the table requested in part
Cast an error if x
is not a dust
object.
Cast an error if part
is not one of c("head", "foot",
"interfoot", "body")
pixiedust
Table FooterRetrieves the broom::glance
output for a model object and
structures it into a table suitable to be placed in the footer. By default,
the statistics are displayed in two column-pairings (see Details). This
function is not exported but is documented to maintain clarity of its
behavior. It is intended for use within dust
, but may be useful
elsewhere if used with caution.
glance_foot(fit, col_pairs, total_cols, glance_stats = NULL, byrow = FALSE)
glance_foot(fit, col_pairs, total_cols, glance_stats = NULL, byrow = FALSE)
fit |
A model object with a |
col_pairs |
An integer indicating the number of column-pairings for the glance output. This must be less than half the total number of columns, as each column-pairing includes a statistic name and value. |
total_cols |
The total number of columns in the body of the pixiedust table |
glance_stats |
A character vector giving the names of the glance statistics
to put in the output. When |
byrow |
A logical, defaulting to |
Statistics are placed in column-pairings. Each column pair consists of
two columns named stat_name_x
and stat_value_x
, where x
is
the integer index of the column pair. The column-pairings are used to allow
the user to further customize the output, more-so than pasting the name and
value together would allow. With this design, statistics can be rounded
differently by applying sprinkles to the resulting table.
The total number of column-pairings must be less than or equal to half the number of total columns. This constraint prevents making glance tables that have more columns than the model table it accompanies.
When the total number of column-parings is strictly less than half the total number of columns, "filler" columns are placed between the column pairings. As much as possible, the filler columns are placed evenly between the column pairings, but when the number of filler columns is unequal between column-pairings, there will be more space placed on the left side. For example, if a table has 7 columns and 3 column-pairings, the order of placement would be column-pair-1, filler, column-pair-2, column-pair-3. Since there was only room for one column of filler, it was placed in the left most fill position.
The byrow
arguments acts similarly to the byrow
argument in the
matrix
function, but defaults to FALSE
. If four statistics are
requested and byrow = FALSE
, the left column-pair will have statistics
one and two, while the right column-pair will have statistics three and four.
If byrow = TRUE
, however, the left column-pair will have statistics
one and three, while the right column-pair will have statistics two and four.
Benjamin Nutter
The sprinkle methods accept the rows and columns that are
to be modified as matrix coordinates. The dust
object stores
the table data in a long form. The tabular coordinates are translated
into row indices using this function.
index_to_sprinkle( x, rows = NULL, cols = NULL, fixed = FALSE, part = c("body", "head", "foot", "interfoot"), recycle = c("none", "rows", "cols", "columns"), coll = NULL )
index_to_sprinkle( x, rows = NULL, cols = NULL, fixed = FALSE, part = c("body", "head", "foot", "interfoot"), recycle = c("none", "rows", "cols", "columns"), coll = NULL )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
fixed |
|
part |
|
recycle |
|
coll |
An optional |
When fixed = FALSE
, sprinkles are applied at the
intersection of rows
and cols
, meaning that the arguments
do not have to share the same length. When fixed = TRUE
, they must
share the same length.
The value of recycle
determines how sprinkles are
managed when the sprinkle input doesn't match the length of the region
to be sprinkled. By default, recycling is turned off. Recycling
may be performed across rows first (left to right, top to bottom),
or down columns first (top to bottom, left to right). "cols"
and "columns"
have the same effect. The two choices to specify
are motivated by the fact that I sometimes get confused about which
it should be. :)
Return the indices of the intersection of rows
and cols
If rows = NULL
, assume all rows.
If rows
is an expression where no values resolve to
TRUE
, return x
unchanged.
If any value in rows
is not a valid row in the table,
cast an error.
If cols = NULL
, assume all columns.
If any value in cols
does not identify a column in the table,
cast an error.
If fixed = TRUE
, length(rows)
(or sum(rows),
if an expression
) and cols
must have the same length.
Cast an error if fixed
is not a logical(1)
Cast an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
.
Benjamin Nutter
sprinkle
pixiedust
recognizes colors as dvips names,
rgb(R,G,B)
, rgba(R,G,B,A)
, #RRGGBB
, or
#RRGGBBAA
. This code returns a logical indicating if
the given character strings are valid.
is_valid_color(color) is_valid_color_single(color)
is_valid_color(color) is_valid_color_single(color)
color |
A character vector of color names. |
Returns a logical vector correctly identifying valid color formats.
Casts an error if color
is not a character object.
knitr
Printing FunctionCustom printing functions for displaying dust
and
dust_list
objects in R Markdown documents.
## S3 method for class 'dust' knit_print(x, options, ...) ## S3 method for class 'dust_list' knit_print(x, options, ...)
## S3 method for class 'dust' knit_print(x, options, ...) ## S3 method for class 'dust_list' knit_print(x, options, ...)
x |
A dust object |
options |
A list of options received from the chunk options. |
... |
Additional arguments to pass to other methods. |
pixiedust
can get to be pretty verbose if you are doing
a great deal of customization. Sprinkle medleys can take out some of that
code by bundling much of the formatting sprinkling into a single function.
pixiedust
comes with a couple very basic medleys that are mostly
for illustration of how to write medleys. Once you get the hang of
sprinkling, you need only bundle your most common sprinkles into a
medley function of your own and cut down on some of the time
coding your most basic formatting.
medley_bw(x) medley_model(x, round = 2)
medley_bw(x) medley_model(x, round = 2)
x |
a |
round |
A numerical value passed to the |
Benjamin Nutter
## Not run: fit <- lm(mpg ~ qsec + factor(am) + wt * factor(gear), data = mtcars) dust(fit) %>% medley_bw() %>% sprinkle_print_method("html") dust(fit, glance_foot = TRUE) %>% medley_model() %>% sprinkle_print_method("html") # Medleys are not generics and do not have methods. # Using a medley on a dust_list object requires pixieply library(dplyr) mtcars %>% group_by(gear) %>% dust(ungroup = FALSE) %>% pixieply(medley_bw) %>% sprinkle_print_method("html") ## End(Not run)
## Not run: fit <- lm(mpg ~ qsec + factor(am) + wt * factor(gear), data = mtcars) dust(fit) %>% medley_bw() %>% sprinkle_print_method("html") dust(fit, glance_foot = TRUE) %>% medley_model() %>% sprinkle_print_method("html") # Medleys are not generics and do not have methods. # Using a medley on a dust_list object requires pixieply library(dplyr) mtcars %>% group_by(gear) %>% dust(ungroup = FALSE) %>% pixieply(medley_bw) %>% sprinkle_print_method("html") ## End(Not run)
For most output, specifying a region of cells with borders
on all sides is as simple as giving the sprinkle border = "all"
.
In LaTeX output, however, this can result in thicker than expected
vertical borders. This medley provides a LaTeX save approach to
drawing borders on all sides without getting the double vertical
border effect.
medley_all_borders( x, rows = NULL, cols = NULL, horizontal = TRUE, vertical = TRUE, part = "body" )
medley_all_borders( x, rows = NULL, cols = NULL, horizontal = TRUE, vertical = TRUE, part = "body" )
x |
An object of class dust |
rows |
The rows over which the borders are to be drawn. |
cols |
The cols over which the borders are to be drawn. |
horizontal |
Logical. Toggles horizontal borders. |
vertical |
Logical. Toggles vertical borders |
part |
A character vector. May contain any of |
Benjamin Nutter
While LaTeX provides the ability to automatically number tables, this
functionality is not readily available with console, HTML, or Word output. By
keep track of the number of (captioned) tables, we can mimic the behavior of
LaTeX tables to provide (mostly) consistent table numbering between formats. The
table numbering is stored in the pixie_count
option.
get_pixie_count() set_pixie_count(value) increment_pixie_count(increment = 1)
get_pixie_count() set_pixie_count(value) increment_pixie_count(increment = 1)
value |
The value at which to set the pixie counter. |
increment |
The value to add to the current pixie count. Defaults to 1. |
The pixie count is stored in the options and may also be accessed using
getOption("pixie_count")
.
get_pixie_count
returns the current value of the counter.
set_pixie_count
sets the value to the user-specification.
increment_pixie_count
increments the pixie count, usually by 1. This is called
within print.dust
any time a dust
object has a caption.
Benjamin Nutter
The concept for these functions is loosely based on a hook meant to work with
knitr
to automatically number tables.
http://stackoverflow.com/a/18672268/1017276
The user has the option of designating the print method to use, or
allowing package to select one from the knitr
settings. This
function manages the logic of assigning the correct print method within the
dust
call.
pixiedust_print_method()
pixiedust_print_method()
The function pixiedust_print_method
first uses
getOption("pixiedust_print_method")
to determine if the user has set
a print method. If the user has not, it then looks to
knitr::opts_knit$get("rmarkdown.pandoc.to")
. Finally, if this is also
NULL
, then the option is set to "console"
.
The sprinkle
methods work with dust_list
objects very naturally, but medleys pose a slightly more difficult problem.
Medleys are intended to be predefined collections of sprinkles that reduce
the time required to format a table with a particular look and style.
It seems counter-productive to expect a user to define each of her or his
medleys as a method that can work with both dust
and dust_list
objects. pixieply
is a wrapper to lapply
that preserves the
dust_list
class of the object.
pixiemap
provides functionality to apply differing sprinkles over
each element of a dust_list
. The most common example is probably
adding a unique caption to each table.
pixieply(X, FUN, ...) pixiemap(X, FUN, ..., MoreArgs = NULL, SIMPLIFY = FALSE, USE.NAMES = TRUE)
pixieply(X, FUN, ...) pixiemap(X, FUN, ..., MoreArgs = NULL, SIMPLIFY = FALSE, USE.NAMES = TRUE)
X |
An object of class |
FUN |
A function to apply to each element of |
... |
Additional arguments to pass to |
MoreArgs |
a list of other arguments to FUN |
SIMPLIFY |
logical or character string; attempt to reduce the result
to a vector, matrix or higher dimensional array; see the |
USE.NAMES |
logical; use names if the first ... argument has names, or if it is a character vector, use that character vector as the names. |
## Not run: #* This example will only display the last table #* in the viewer pane. To see the full output, #* run this example in an Rmarkdown document. x <- split(mtcars, list(mtcars$am, mtcars$vs)) dust(x) %>% sprinkle_print_method("html") %>% pixieply(medley_bw) ## End(Not run) ## Not run: #* This is the full text of an RMarkdown script #* for the previous example. --- title: "Pixieply" output: html_document --- ```{r} library(pixiedust) x <- dplyr::group_by(mtcars, am, vs) dust(x, ungroup = FALSE) %>% sprinkle_print_method("html") %>% pixieply(medley_bw) ``` ## End(Not run)
## Not run: #* This example will only display the last table #* in the viewer pane. To see the full output, #* run this example in an Rmarkdown document. x <- split(mtcars, list(mtcars$am, mtcars$vs)) dust(x) %>% sprinkle_print_method("html") %>% pixieply(medley_bw) ## End(Not run) ## Not run: #* This is the full text of an RMarkdown script #* for the previous example. --- title: "Pixieply" output: html_document --- ```{r} library(pixiedust) x <- dplyr::group_by(mtcars, am, vs) dust(x, ungroup = FALSE) %>% sprinkle_print_method("html") %>% pixieply(medley_bw) ``` ## End(Not run)
dust
TableApply the formatting to a dust
object and print the table.
## S3 method for class 'dust' print(x, ..., asis = TRUE, linebreak_at_end = 2) ## S3 method for class 'dust_list' print(x, ..., asis = TRUE)
## S3 method for class 'dust' print(x, ..., asis = TRUE, linebreak_at_end = 2) ## S3 method for class 'dust_list' print(x, ..., asis = TRUE)
x |
An object of class |
... |
Additional arguments to pass to the print method. Currently ignored. |
asis |
A logical value that controls if the output is printed using
|
linebreak_at_end |
Used only in HTML tables; defines the number of
line break tags |
The printing format is drawn from options()$dustpan_output
and may take any of
the values "console"
, "markdown"
, "html"
, or "latex"
The markdown, html, and latex output is returned via asis_output
,
which forces the output into the 'asis' environment. It is intended to work
with Rmarkdown, and the tables will be rendered regardless of the
chunk's results
argument. Currently, there is no way to to capture
the code for additional post processing.
When asis = TRUE
(the default), the output is returned via knitr::asis_output
,
which renders the output as if the chunk options included results = 'asis'
. Under
this setting, the table will be rendered regardless of the value of the results
option. Using asis = FALSE
returns a character string with the code for the table.
This may be rendered in a markdown document via cat(print(x, asis = FALSE))
with the
chunk option results = 'asis'
. (If working with an Rnw file, the chunk option is
results = tex
). The only way to use the asis
argument is with an explicit
call to print.dust
.
Benjamin Nutter
dust(lm(mpg ~ qsec + factor(am), data = mtcars))
dust(lm(mpg ~ qsec + factor(am), data = mtcars))
Convert numeric p-values to character strings according to pre-defined formatting parameters. Additional formats may be added for required or desired reporting standards.
pval_string(p, format = c("default", "exact", "scientific"), digits = 3, ...) pvalString(p, format = c("default", "exact", "scientific"), digits = 3, ...)
pval_string(p, format = c("default", "exact", "scientific"), digits = 3, ...) pvalString(p, format = c("default", "exact", "scientific"), digits = 3, ...)
p |
a numeric vector of p-values. |
format |
A character string indicating the desired format for the p-values. See Details for full descriptions. |
digits |
For |
... |
Additional arguments to be passed to |
When format = "default"
, p-values are formatted:
p > 0.99: "> 0.99"
0.99 > p > 0.10: Rounded to two digits
0.10 > p > 0.001: Rounded to three digits
0.001 > p: "< 0.001"
When format = "exact"
, the exact p-value is printed with the
number of places after the deimal equal to digits
. P-values smaller
that 1*(10^-digits
) are printed in scientific notation.
When format = "scientific"
, all values are printed in scientific
notation with digits
digits printed before the e
.
When format = "default"
, print p-values greater than
0.99 as "> 0.99"; greater than 0.10 with two digits;
greater than 0.001 with three digits; and less than 0.001 as
"< 0.001".
when format = "exact"
, print the exact p-value out to at most
digits
places past the decimal place.
When format = "scientific"
, print the p-value in
scientific notation with up to digits
values ahead of the
e
.
Cast an error if p
is not numeric on the interval [0, 1]
Cast an error if format is not one of c("default", "exact",
"scientific")
.
Cast an error if digits
is not integerish(1)
.
Benjamin Nutter
p <- c(1, .999, .905, .505, .205, .125, .09531, .05493, .04532, .011234, .0003431, .000000342) pvalString(p, format="default") pvalString(p, format="exact", digits=3) pvalString(p, format="exact", digits=2) pvalString(p, format="scientific", digits=3) pvalString(p, format="scientific", digits=4)
p <- c(1, .999, .905, .505, .205, .125, .09531, .05493, .04532, .011234, .0003431, .000000342) pvalString(p, format="default") pvalString(p, format="exact", digits=3) pvalString(p, format="exact", digits=2) pvalString(p, format="scientific", digits=3) pvalString(p, format="scientific", digits=4)
Stack data frames on top of each other. Data frames do not have to have all of the same columns.
.rbind_internal(..., deparse.level = 1)
.rbind_internal(..., deparse.level = 1)
... |
data frames |
deparse.level |
See |
Benjamin Nutter
Pixiedust reshapes data to have one row per cell in the table. This permits adjustments to be made to individual cells. These internal functions are provided to simplify the reshaping process. It is slower than using the tidyr functions 'gather' and 'spread' (or whatever their newer counterparts are), but keeps me off of other people's development schedules.
.make_dataframe_long(data)
.make_dataframe_long(data)
data |
A |
No validations are performed in these functions, and it is assumed that the input data set has the components it needs.
Benjamin Nutter
sanitize_latex
translates particular items in
character strings to LaTeX format, e.g., makes a^2 = a\$^2\$
for superscript within variable labels. LaTeX names of greek letters
(e.g., "alpha") will have backslashes added if greek==TRUE
.
Math mode is inserted as needed. sanitize_latex
assumes that
input text always has matches, e.g. [) [] (] ()
, and that
surrounding by \$\$
is OK.
sanitize_latex( object, inn = NULL, out = NULL, pb = FALSE, greek = FALSE, na = "", ... )
sanitize_latex( object, inn = NULL, out = NULL, pb = FALSE, greek = FALSE, na = "", ... )
object |
|
inn |
|
out |
|
pb |
|
greek |
|
na |
|
... |
Additional arguments for other methods. Currently ignored. |
Vector of chracter strings.
This code is lifted from the Hmisc
package in order to
avoid depending on that package.
Frank E. Harrell Jr.
Department of Biostatistics,
Vanderbilt University,
[email protected]
Richard M. Heiberger,
Department of Statistics,
Temple University, Philadelphia, PA.
[email protected]
David R. Whiting,
School of Clinical Medical Sciences (Diabetes),
University of Newcastle upon Tyne, UK.
[email protected]
Hmisc::latexTranslate
, Hmisc::sedit
sanitize_latex("75% of the cars were | more than $20,000 Delta = 1.30", greek = TRUE)
sanitize_latex("75% of the cars were | more than $20,000 Delta = 1.30", greek = TRUE)
Customizations to a dust
table are added by "sprinkling"
with a little extra pixie dust. Sprinkles are a collection of attributes
to be applied over a subset of table cells. They may be added to any
part of the table, or to the table as a whole.
sprinkle( x, rows = NULL, cols = NULL, ..., part = c("body", "head", "foot", "interfoot", "table") ) ## Default S3 method: sprinkle( x, rows = NULL, cols = NULL, ..., part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns") ) ## S3 method for class 'dust_list' sprinkle( x, rows = NULL, cols = NULL, ..., part = c("body", "head", "foot", "interfoot", "table") ) sprinkle_print_method( x, print_method = c("console", "markdown", "html", "latex") ) ## Default S3 method: sprinkle_print_method( x, print_method = c("console", "markdown", "html", "latex", "docx") ) ## S3 method for class 'dust_list' sprinkle_print_method( x, print_method = c("console", "markdown", "html", "latex") ) sprinkle_table(x, cols = NULL, ..., part = "table") ## Default S3 method: sprinkle_table(x, cols = NULL, ..., part = "table") ## S3 method for class 'dust_list' sprinkle_table(x, cols = NULL, ..., part = "table")
sprinkle( x, rows = NULL, cols = NULL, ..., part = c("body", "head", "foot", "interfoot", "table") ) ## Default S3 method: sprinkle( x, rows = NULL, cols = NULL, ..., part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns") ) ## S3 method for class 'dust_list' sprinkle( x, rows = NULL, cols = NULL, ..., part = c("body", "head", "foot", "interfoot", "table") ) sprinkle_print_method( x, print_method = c("console", "markdown", "html", "latex") ) ## Default S3 method: sprinkle_print_method( x, print_method = c("console", "markdown", "html", "latex", "docx") ) ## S3 method for class 'dust_list' sprinkle_print_method( x, print_method = c("console", "markdown", "html", "latex") ) sprinkle_table(x, cols = NULL, ..., part = "table") ## Default S3 method: sprinkle_table(x, cols = NULL, ..., part = "table") ## S3 method for class 'dust_list' sprinkle_table(x, cols = NULL, ..., part = "table")
x |
A dust object |
rows |
A numeric vector specifying the rows of the table to sprinkle. See details for more about sprinkling. |
cols |
A numeric (or character) vector specifying the columns (or column names) to sprinkle. See details for more about sprinkling. |
... |
named arguments, each of length 1, defining the customizations for the given cells. See "Sprinkles" for a listing of these arguments. |
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
print_method |
A character string giving the print method for the table.
Note: |
Sprinkling is done over the intersection of rows and columns
(unless fixed = TRUE
. If
rows but no columns are specified, sprinkling is performed over all columns
of the given given rows. The reverse is true for when columns but no rows
are specified. If neither columns nor rows are specified, the attribute
is applied over all of the cells in the table part denoted in part
.
If at least one of border
, border_thickness
, border_units
,
border_style
or border_color
is specified, the remaining
unspecified attributes assume their default values.
Other sprinkle pairings are height
and height_units
;
width
and width_units
; font_size
and font_size_units
;
bg_pattern
and bg_pattern_by
The sprinkles bg
and bg_pattern
may not be used together.
A more detailed demonstration of the use of sprinkles is available in
vignette("pixiedust", package = "pixiedust")
Using sprinkle_table
, sprinkles may be applied to the columns of multiple tables. Table
parts are required to have the same number of columns, but not necessarily the same number
of rows, which is why the rows
argument is not available for the sprinkle_table
.
In contrast to sprinkle
, the part
argument in sprinkle_table
will
accept multiple parts. If any of the named parts is "table"
, the sprinkle will be
applied to the columns of all of the parts.
The following table describes the valid sprinkles that may be defined in the
...
dots argument. All sprinkles may be defined for any output type, but
only sprinkles recognized by that output type will be applied when printed.
A more readable format of this information is available in
vignette("sprinkles", package = "pixiedust")
.
bg | ||
action | Modifies the background color of a cell. | |
default | ||
accepts | dvips color names; rgb(R,G,B); rgba(R,G,B,A); | |
#RRGGBB; #RRGGBBAA. See the "Colors" section | ||
for further details. | ||
console | Not recognized | |
markdown | Not recognized | |
html | Accepts any of the listed formats; | |
recognizes transparency | ||
latex | Accepts any of the listed formats, | |
but ignores transparency | ||
bg_pattern | ||
action | Generates a pattern of background colors. | |
Can be used to make striping | ||
by rows or by columns. | ||
default | c("#FFFFFF", "#DDDDDD") | |
accepts | A vector of color names: | |
dvips color names; rgb(R,G,B); rgba(R,G,B,A); | ||
#RRGGBB; #RRGGBBAA | ||
console | Not recognized | |
markdown | Not recognized | |
html | Accepts any of the listed formats; | |
recognizes transparency | ||
latex | Accepts any of the listed formats, | |
but ignores transparency | ||
bg_pattern_by | ||
action | Determines if a `bg_pattern` is patterned | |
by row or by columns. | ||
default | "rows" | |
accepts | "rows", "columns", "cols" | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
bold | ||
action | Renders text within a cell in bold. | |
default | FALSE | |
accepts | logical(1) | |
console | Recognized; rendered as double asterisks on either | |
side of the text | ||
markdown | Recognized | |
html | Recognized | |
latex | Recognized | |
border_collapse | ||
action | Sets the `border-collapse` property in an | |
HTML table. The property sets whether the | ||
table borders are collapsed into a | ||
single border or detached as in standard HTML. | ||
default | TRUE | |
accepts | logical(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Not recognized | |
border | ||
action | Sets a border on the specified side of a cell. | |
default | ||
accepts | Any combination of "all", "bottom", "left", "top", | |
"right". Using "all" results in all borders | ||
being drawn, regardless of what other values are | ||
passed with it. | ||
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
border_color | ||
action | Sets the color of the borders specified for a cell. | |
default | "Black" | |
accepts | character(1) | |
dvips color names; rgb(R,G,B); rgba(R,G,B,A); | ||
#RRGGBB; #RRGGBBAA. See the "Colors" section | ||
for further details. | ||
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
border_style | ||
action | Sets the border style for a specified cell | |
default | "solid" | |
accepts | character(1) | |
"solid", "dashed", "dotted", "double", "groove", | ||
"ridge", "inset", "outset", "hidden", "none" | ||
console | Not recognized | |
markdown | Not recognized | |
html | Accepts any of the values listed. | |
latex; hhline = FALSE | accepts "solid", "dashed", "dotted", | |
"hidden", "none" | ||
"dotted" is silently changed to "dashed" | ||
"hidden" and "none" are equivalent. | ||
latex; hhline = TRUE | accepts "solid", "double", "hidden", "none" | |
"hidden" and "none" are equivalent. | ||
border_thickness | ||
action | Sets the thickness of the specified border | |
default | 1 | |
accepts | numeric(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
border_units | ||
action | Sets the unit of measure for the specified border | |
thickness | ||
default | "pt" | |
accepts | "pt", "px" | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Silently changes "px" to "pt" | |
caption | ||
action | Adds or alters the `caption` property | |
default | ||
accepts | character(1) | |
console | Recognized | |
markdown | Recognized | |
html | Recognized | |
latex | Recognized | |
discrete | ||
action | Adds distinct background colors based on | |
discrete values in the selected region. | ||
May not be used concurrently with bg . |
||
"font" is an alias for "font_color" |
||
and "border" is an alias for |
||
all borders. | ||
default | "bg" | |
accepts | "bg", "font", "font_color", "border", | |
"left_border", "top_border", "right_border", | ||
"bottom_border" | ||
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
discrete_color | ||
action | Sets the color palette from which discrete |
|
selects background colors. If NULL |
||
colors are automatically selected using | ||
the scales package. |
||
default | getOption("pixie_discrete_pal", NULL) |
|
accepts | character | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
float | ||
action | Sets the `float` property | |
default | TRUE | |
accepts | logical(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Not recognized | |
latex | Recognized | |
fn | ||
action | Applies a function to the value of a cell. | |
The function should be an | ||
expression that acts on the variable `value`. | ||
For example, quote(format(value, nsmall = 3)) |
||
default | ||
accepts | call | |
console | Recognized | |
markdown | Recognized | |
html | Recognized | |
latex | Recognized | |
font_color | ||
action | Sets the color of the cell text | |
default | Black | |
accepts | dvips color names; rgb(R,G,B); rgba(R,G,B,A); | |
#RRGGBB; #RRGGBBAA. See the "Colors" section | ||
for further details. | ||
console | Not recognized | |
markdown | Not recognized | |
html | Recognized; transparency recognized | |
latex | Recognized; transparency ignored | |
font_family | ||
action | Sets the font for the text | |
default | Times New Roman | |
accepts | character(1) | |
http://www.w3schools.com/cssref/css_websafe_fonts.asp | ||
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Not recognized | |
font_size | ||
action | Sets the size of the font in the cell | |
default | ||
accepts | numeric(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
font_size_units | ||
action | Determines the units in which `font_size` | |
is measured | ||
default | "px" | |
accepts | "px", "pt", "%", "em" | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Only recognizes "pt" and "em". | |
All others are coerced to "pt" | ||
gradient | ||
action | Adds distinct background colors based on | |
progressively increasing values in the | ||
selected region. May not be used concurrently | ||
with bg . |
||
"font" is an alias for "font_color" |
||
and "border" is an alias for |
||
all borders. | ||
default | "bg" | |
accepts | "bg", "font", "font_color", "border", | |
"left_border", "top_border", "right_border", | ||
"bottom_border" | ||
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
gradient_colors | ||
action | Provides the colors between which to | |
shade gradients. | ||
default | getOptions("pixie_gradient_pal", NULL) |
|
accepts | character | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
gradient_cut | ||
action | Determines the breaks points for the | |
gradient shading. When NULL |
||
equally spaced quantiles are used, the | ||
number of which are determined by | ||
gradient_n . |
||
default | NULL | |
accepts | numeric | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
gradient_n | ||
action | Determines the number of shades to use | |
between the colors in gradient_colors . |
||
default | 10 | |
accepts | numeric | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
gradient_na | ||
action | Sets the color of NA values when gradients | |
are shaded. | ||
default | grey | |
accepts | character(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
halign | ||
action | Sets the horizontal alignment of the text in | |
the cell | ||
default | ||
accepts | "left", "center", "right" | |
console | Not recognized | |
markdown | Recognized; numeric values will auto align to the | |
right if no value given. | ||
html | Recognized. Does not currently employ auto | |
alignment of numeric values, but this may change. | ||
latex | Recognized; numeric values will auto align to | |
the right if no value given. | ||
height | ||
action | Sets the height of the cell | |
default | ||
accepts | numeric(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
height_units | ||
action | Determines the units in which `height` is measured | |
default | "pt" | |
accepts | "px", "pt", "cm", "in", "%" | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized; "px" is coerced to "pt" | |
hhline | ||
action | Toggles the option for cell border drawing with | |
the `hhline` LaTeX package | ||
default | FALSE | |
accepts | logical(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Not recognized | |
latex | Recognized. When `FALSE` double borders are | |
not available. | ||
When `TRUE`, colored and dashed borders are not | ||
available. This is usually the better option | ||
when using colored backgrounds in table cells. | ||
italic | ||
action | Renders the text in the cell in italic | |
default | FALSE | |
accepts | logical(1) | |
console | Recognized; rendered as an underscore on either | |
side of the text. | ||
markdown | Recognized | |
html | Recognized | |
latex | Recognized | |
justify | ||
action | Justifies the entire table on the page. | |
default | "center" | |
accepts | character(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognizes "center", but both "left" and "right" | |
are rendered as left justified. This may change | ||
if a satisfactory solution is found. | ||
Usually, tables are best left centered. | ||
longtable | ||
action | Toggles the use of the LaTeX `longtable` style | |
tables, namely allowing long tables to be broken | ||
into multiple sections. The table header appears | ||
at the top of each section. The table interfoot | ||
appears at the bottom of each section, except | ||
for the last. | ||
The table foot appears at the bottom of the | ||
last section. | ||
May accept either a logical or a numerical value. | ||
If numerical, each section will have the specified | ||
number of rows. | ||
default | FALSE | |
accepts | logical(1); numeric(1) | |
console | Recognized; when `TRUE`, defaults to 25 rows | |
per section. | ||
markdown | Recognized; when `TRUE`, defaults to 25 rows | |
per section. | ||
html | Recognized; when `TRUE`, defaults to 25 rows | |
per section. | ||
latex | Recognized; when `TRUE`, `longtable`'s own algorithm | |
will determine the number of rows per section. | ||
When numeric, breaks are forced at the specified | ||
number of rows. | ||
merge | ||
action | Merges cells in the specified range into a | |
single cell. In cases where | ||
either `merge_rowval` or `merge_colval` is | ||
specified, they will only be | ||
honored if `merge = TRUE`. You must opt in to | ||
this action. | ||
default | FALSE | |
accepts | logical(1) | |
console | Recognized | |
markdown | Recognized | |
html | Recognized | |
latex | Recognized | |
merge_rowval | ||
action | Specifies the row value of the merged range to | |
print in the table | ||
default | minimum row value of the merged range | |
accepts | numeric(1) | |
console | Recognized | |
markdown | Recognized | |
html | Recognized | |
latex | Recognized | |
merge_colval | ||
action | Specifies the column value of the merged range | |
to print in the table | ||
default | minimum col value of the merged range | |
accepts | numeric(1) | |
console | Recognized | |
markdown | Recognized | |
html | Recognized | |
latex | Recognized | |
na_string | ||
action | Designates the character string to use in place | |
of missing values | ||
default | NA | |
accepts | character(1) | |
console | Recognized | |
markdown | Recognized | |
html | Recognized | |
latex | Recognized | |
pad | ||
action | Designates the padding to place between cell | |
text and boundaries | ||
Measured in pixels. | ||
default | 0 | |
accepts | numeric(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Not recognized | |
replace | ||
action | Replaces existing cell values with user-specified | |
content. Replacement occurs moving down columns | ||
from left to right. | ||
default | ||
accepts | character vector of the same length as the number | |
of cells being replaced. | ||
console | Recognized | |
markdown | Recognized | |
html | Recognized | |
latex | Recognized | |
rotate_degree | ||
action | Rotates text in cells by the designated angle | |
in degrees | ||
default | ||
accepts | numeric(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
round | ||
action | Applies the `round` function to values in the | |
cell. Skips any character values it encounters. | ||
default | getOption("digits") |
|
accepts | numeric(1) | |
console | Recognized | |
markdown | Recognized | |
html | Recognized | |
latex | Recognized | |
sanitize | ||
action | Sanitizes character values that may cause | |
difficulties for the rendered format. | ||
default | FALSE | |
accepts | logical(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Not recognized | |
latex | Recognized. Sanitization is performed using | |
latexTranslate |
||
sanitize_args | ||
action | Passes additional arguments to latexTranslate |
|
default | list() |
|
accepts | list. See documentation for latexTranslate |
|
for details | ||
console | Not recognized | |
markdown | Not recognized | |
html | Not recognized | |
latex | Recognized | |
tabcolsep | ||
action | Modifies the LaTeX `tabcolsep` parameter of tables | |
This is similar to `pad` for HTML tables, but only | ||
affects the space between columns. Measured in "pt" | ||
default | 6 | |
accepts | numeric(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Not recognized | |
latex | Recognized | |
valign | ||
action | Designates the vertical alignment of a cell. | |
default | ||
accepts | "top", "middle", "bottom" | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
width | ||
action | Sets the width of the cell | |
default | ||
accepts | numeric(1) | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized | |
width_units | ||
action | Determines the units in which `width` is measured | |
default | "pt" | |
accepts | "px", "pt", "cm", "in", "%" | |
console | Not recognized | |
markdown | Not recognized | |
html | Recognized | |
latex | Recognized; "px" is coerced to "pt" | |
The longtable
feature is named for the LaTeX package used to break very large
tables into multiple pages.
When using the longtable=TRUE
option, the default number of rows per table is 25 for
console, HTML, and markdown output. For LaTeX output, the number of rows is determined by
the LaTeX longtable
package's algorithm. The number of rows per table only considers
the content in the body of the table. Consideration for the number of rows in the head and
foot are the responsibility of the user.
Whenever a table is broken into multiple parts, each part retains the table head. If any
interfoot
is provided, it is appended to the bottom of each section, with the
exception of the last section. The last section has the foot
appended.
Colors may be declared as any of the color names in colors()
,
as rgb character strings such as "rgb(rrr,ggg,bbb)"
or as
hexadecimal character strings such as "#rrggbb"
.
Transparency is also recognized by HTML output, and may be indicated
in the rgba format "rgba(rrr,ggg,bbb,aa)"
, where aa
is a
number between 0 and 1, inclusive. Alternative, transparency may be
given as "#rrggbbAA"
, where AA
is a hexadecimal
representation of transparency with "00" being completely transparent
and "FF" being completely opaque.
LaTeX output does not recognize transparency and will quietly drop the transparency parameter.
All colors are internally translated into rgb format and are case insensitive.
If you will be using the LaTeX output, some sprinkles will require you
to include additional LaTeX packages in your document preamble. In
.Rnw
files, additional packages can be included with the
\usepackage{[package]}
syntax. In markdown, additional packages
are included using header-includes:
in the YAML front matter with
a line of the format \usepackage{[package]}
for each package to
be used. Sprinkles that require additional packages, and the LaTeX packages
required, are listed below:
Sprinkle | LaTeX Package(s) |
font_color |
\usepackage[dvipsnames]{xcolor} |
bg, bg_pattern |
\usepackage[dvipsnames,table]{xcolor} |
border_style |
\usepackage{arydshln} |
\usepackage{amssymb} |
|
\usepackage{hhline} |
|
(with vertical dashed lines) | \usepackage{graphicx} |
\makeatletter |
|
\newcommand*\vdashline{\rotatebox[origin=c]{90}{\$\dabar@\dabar@\dabar@\$}} |
|
\makeatother |
|
longtable |
\usepackage{longtable} |
(Must be loaded before arydshln ) |
|
merge |
\usepackage{multirow} |
captions for non floats |
\usepackage{caption}
|
Note that hhline
is used to make horizontal lines when
options(pixiedust_latex_hhline = TRUE)
(the package default is FALSE
),
otherwise the cline
command is used.
Use of cline
permits colored borders and dashed borders, but
borders around cells with background colors are sometimes (often) lost.
Use of hhline
preserves borders around cells with background colors
and permits double borders, but colored and dashed borders are not available.
In order to ensure all features are available, the recommended code block (accounting for the proper order to load packages) is:
header-includes:
- \usepackage{amssymb}
- \usepackage{arydshln}
- \usepackage{caption}
- \usepackage{graphicx}
- \usepackage{hhline}
- \usepackage{longtable}
- \usepackage{multirow}
- \usepackage[dvipsnames,table]{xcolor}
- \makeatletter
- \newcommand*\vdashline{\rotatebox[origin=c]{90}{\$\dabar@\dabar@\dabar@\$}}
- \makeatother
Benjamin Nutter
Altering the number of rows in a LaTeX longtable
http://tex.stackexchange.com/questions/19710/how-can-i-set-the-maximum-number-of-rows-in-a-page-for-longtable
Vertical dashed cell borders in LaTeX table
http://www.latex-community.org/forum/viewtopic.php?f=45&t=3149
Colored Cell border
http://tex.stackexchange.com/questions/40666/how-to-change-line-color-in-tabular
sprinkle_colnames
for changing column names in a table.
x <- dust(lm(mpg ~ qsec + factor(am), data = mtcars)) x %>% sprinkle(cols = 2:4, round = 3) %>% sprinkle(cols = 5, fn = quote(pvalString(value))) %>% sprinkle(rows = 2, bold = TRUE)
x <- dust(lm(mpg ~ qsec + factor(am), data = mtcars)) x %>% sprinkle(cols = 2:4, round = 3) %>% sprinkle(cols = 5, fn = quote(pvalString(value))) %>% sprinkle(rows = 2, bold = TRUE)
The alignment refers to the positioning of the text within a cell. Alignment may be given relative to the left, center, or right of a cell, and the top, middle, or bottom of the cell.
sprinkle_align( x, rows = NULL, cols = NULL, halign = NULL, valign = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_align( x, rows = NULL, cols = NULL, halign = NULL, valign = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_align( x, rows = NULL, cols = NULL, halign = NULL, valign = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_align( x, rows = NULL, cols = NULL, halign = NULL, valign = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_align( x, rows = NULL, cols = NULL, halign = NULL, valign = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_align( x, rows = NULL, cols = NULL, halign = NULL, valign = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
halign |
|
valign |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
Correctly reassigns the appropriate elements of halign
and valign
columns in the table part.
Casts an error if x
is not a dust
object.
Casts an error if halign
is not a character
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
Casts an error if valign
is not a character
Cast an error if recycle = "none"
and halign
does
not have length 1.
Cast an error if recycle = "none"
and valign
does
not have length 1.
Cast an error if halign
is not one of c("left", "center", "right")
Cast an error if valign
is not one of c("top", "middle", "bottom")
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
Background colors may be used to highlight the contents
of cells, rows, or columns. Most commonly, backgrounds are used to
provide row discrimination; the sprinkle_bg_pattern
function
is better suited to that purpose.
sprinkle_bg( x, rows = NULL, cols = NULL, bg = "", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_bg( x, rows = NULL, cols = NULL, bg = "", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_bg( x, rows = NULL, cols = NULL, bg = "", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) sprinkle_background( x, rows = NULL, cols = NULL, bg = "", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_bg( x, rows = NULL, cols = NULL, bg = "", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_bg( x, rows = NULL, cols = NULL, bg = "", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_bg( x, rows = NULL, cols = NULL, bg = "", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) sprinkle_background( x, rows = NULL, cols = NULL, bg = "", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
bg |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
Colors may be a dvips color name, or in the rgb(R, G, B), rgba(R, G, B, A), #RRGGBB, or #RRGGBBAA formats.
This sprinkle is ignored in console and markdown outputs. HTML output will accept any of the color formats and recognize transparency. LaTeX output will accept any of the color formats but ignore transparency.
As long as bg
is required to be a character(1)
, the
recycle
argument is kind of useless. It is included to maintain
consistency with the index_to_sprinkle
function. Future development
may permit a character vector of colors.
Correctly reassigns the appropriate elements bg
column
in the table part.
Casts an error if x
is not a dust
object.
Casts an error if bg
is not a character(1)
Casts an error if bg
is not a valid color format.
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
Casts an error if recycle = "none"
and bg
does not
have length 1.
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
Benjamin Nutter
sprinkle
, sprinkle_bg_pattern
,
index_to_sprinkle
Provides background color striping based on row or column. Striping may be done with any number of colors. The most common use of striping is to provide row discrimination in tables.
sprinkle_bg_pattern( x, rows = NULL, cols = NULL, bg_pattern = c("transparent", "#DCDCDC"), bg_pattern_by = c("rows", "cols"), ..., part = c("body", "head", "foot", "interoot", "table") ) ## Default S3 method: sprinkle_bg_pattern( x, rows = NULL, cols = NULL, bg_pattern = c("transparent", "#DCDCDC"), bg_pattern_by = c("rows", "cols"), ..., part = c("body", "head", "foot", "interfoot", "table") ) ## S3 method for class 'dust_list' sprinkle_bg_pattern( x, rows = NULL, cols = NULL, bg_pattern = c("transparent", "#DCDCDC"), bg_pattern_by = c("rows", "cols"), ..., part = c("body", "head", "foot", "interfoot", "table") )
sprinkle_bg_pattern( x, rows = NULL, cols = NULL, bg_pattern = c("transparent", "#DCDCDC"), bg_pattern_by = c("rows", "cols"), ..., part = c("body", "head", "foot", "interoot", "table") ) ## Default S3 method: sprinkle_bg_pattern( x, rows = NULL, cols = NULL, bg_pattern = c("transparent", "#DCDCDC"), bg_pattern_by = c("rows", "cols"), ..., part = c("body", "head", "foot", "interfoot", "table") ) ## S3 method for class 'dust_list' sprinkle_bg_pattern( x, rows = NULL, cols = NULL, bg_pattern = c("transparent", "#DCDCDC"), bg_pattern_by = c("rows", "cols"), ..., part = c("body", "head", "foot", "interfoot", "table") )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
bg_pattern |
A character vector giving the colors to be iterated in the pattern. |
bg_pattern_by |
A subset of |
... |
Additional arguments to pass to other methods. Currently ignored. |
part |
A character string denoting which part of the table to modify. |
Correctly reassigns the appropriate elements bg
column
in the table part.
Casts an error if x
is not a dust
object.
Casts an error if bg_pattern
is not a character vector.
Casts an error if any element in bg_pattern
is not a valid
color name.
Casts an error if bg_pattern_by
is not a subset of
c("rows", "columns")
(with partial matching).
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
This is a rare sprinkle that doesn't use the fixed
and recycle
arguments. They are assumed to be FALSE
and "none"
,
respectively, in order to pass through index_to_sprinkle
.
sprinkle_bg
, sprinkle
,
index_to_sprinkle
Tables built for the bookdown
package can be referenced
in a manner that is consistent between HTML and LaTeX documents.
sprinkle_bookdown(x, bookdown = getOption("pixie_bookdown", FALSE), ...) ## Default S3 method: sprinkle_bookdown(x, bookdown = getOption("pixie_bookdown", FALSE), ...) ## S3 method for class 'dust_list' sprinkle_bookdown(x, bookdown = getOption("pixie_bookdown", FALSE), ...)
sprinkle_bookdown(x, bookdown = getOption("pixie_bookdown", FALSE), ...) ## Default S3 method: sprinkle_bookdown(x, bookdown = getOption("pixie_bookdown", FALSE), ...) ## S3 method for class 'dust_list' sprinkle_bookdown(x, bookdown = getOption("pixie_bookdown", FALSE), ...)
x |
An object of class |
bookdown |
|
... |
Additional arguments to pass to other methods. Currently ignored. |
bookdown
is a package that facilitates the writing of books.
One of the advantages of bookdown
is the ability to reference
tables in a manner similar to LaTeX. The key difference in how
pixiedust
handles output is the reference specification. See
https://bookdown.org/yihui/bookdown/tables.html for details on how
bookdown
uses labels and references.
Change the bookdown
attribute of the dust
object.
Cast an error if x
is not a dust
object.
Cast an error if bookdown
is not a logical object.
Cast an error if bookdown
has length greater than 1.
Benjamin Nutter
https://bookdown.org/yihui/bookdown/tables.html
Cell borders may be used to give visual structure to a table. Borders may generate distinction between sets of results, groups, or types of output.
sprinkle_border( x, rows, cols, border = c("all", "bottom", "left", "top", "right"), border_color = "black", border_style = "solid", border_thickness = 1, border_units = c("pt", "px"), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_border( x, rows = NULL, cols = NULL, border = c("all", "bottom", "left", "top", "right"), border_color = "black", border_style = "solid", border_thickness = 1, border_units = c("pt", "px"), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_border( x, rows = NULL, cols = NULL, border = c("all", "bottom", "left", "top", "right"), border_color = "black", border_style = "solid", border_thickness = 1, border_units = c("pt", "px"), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_border( x, rows, cols, border = c("all", "bottom", "left", "top", "right"), border_color = "black", border_style = "solid", border_thickness = 1, border_units = c("pt", "px"), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_border( x, rows = NULL, cols = NULL, border = c("all", "bottom", "left", "top", "right"), border_color = "black", border_style = "solid", border_thickness = 1, border_units = c("pt", "px"), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_border( x, rows = NULL, cols = NULL, border = c("all", "bottom", "left", "top", "right"), border_color = "black", border_style = "solid", border_thickness = 1, border_units = c("pt", "px"), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
border |
One or more of |
border_color |
|
border_style |
|
border_thickness |
|
border_units |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
This sprinkle has no effect on console and markdown output.
HTML output accepts all of the possible values of border_style
.
For LaTeX output, when hhline = FALSE
, "solid"
, "dashed"
,
"dotted"
, "hidden"
, and "none"
are accepted.
"dotted"
will silently be treated as "dashed"
, and
"hidden"
is the equivalent of "none"
.
For LaTeX output when hhline = TRUE
, "solid"
, "double"
,
"hidden"
, and "none"
are accepted. "hidden"
is the
equivalent of "none"
.
When a value of border_style
is not recognized by an output format,
it is silently ignored.
Correctly reassigns the left_border
, right_border
,
top_border
and bottom_border
columns in the table part.
Casts an error if x
is not a dust
object.
Casts an error if any element of border
is not one of
"all"
, "bottom"
, "left"
, "top"
, or
"right"
.
Casts an error if border_color
is not a character(1)
Casts an error if border_color
is not a valid color format.
Casts an error if border_style
is not one of "solid"
,
"dashed"
, "dotted"
, "double"
, "groove"
,
"ridge"
, "inset"
, "outset"
, "hidden"
,
"none"
Casts an error if border_thickness
is not a numeric(1)
.
Casts an error if border_units
is not one of "pt"
or
"px"
.
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
Cast an error if recycle = "none"
and border_color
does not have length 1.
Cast an error if recycle = "none"
and border_style
does not have length 1.
Cast an error if recycle = "none"
and border_thickness
does not have length 1.
Quietly restrict border_units
to just the first element if
is has length > 1 and recycle = "none"
.
Benjamin Nutter
The border_collapse
property controls the appearance of
cell borders in HTML tables. Be default, pixiedust
collapses
the borders so that the adjoining border of two cells appear as a
single border.
sprinkle_border_collapse( x, border_collapse = getOption("pixie_border_collapse", "collapse"), ... ) ## Default S3 method: sprinkle_border_collapse( x, border_collapse = getOption("pixie_border_collapse", "collapse"), ... ) ## S3 method for class 'dust_list' sprinkle_border_collapse( x, border_collapse = getOption("pixie_border_collapse", "collapse"), ... )
sprinkle_border_collapse( x, border_collapse = getOption("pixie_border_collapse", "collapse"), ... ) ## Default S3 method: sprinkle_border_collapse( x, border_collapse = getOption("pixie_border_collapse", "collapse"), ... ) ## S3 method for class 'dust_list' sprinkle_border_collapse( x, border_collapse = getOption("pixie_border_collapse", "collapse"), ... )
x |
An object of class |
border_collapse |
|
... |
Additional arguments to pass to other methods. Currently ignored. |
See https://www.w3schools.com/cssref/pr_border-collapse.asp for details on how each option affects the appearance of a table.
This property has no effect on non-HTML output.
Change the border_collapse
attribute of the dust
object.
Cast an error if x
is not a dust
object.
Cast an error if border_collapse
is not one of
"collapse"
, "separate"
, "initial"
, "inherit"
.
Benjamin Nutter
https://www.w3schools.com/cssref/pr_border-collapse.asp
The table caption is often used as a brief title, but may also be used to provide a longer statement explaining how to interpret the table results.
sprinkle_caption(x, caption, ...) ## Default S3 method: sprinkle_caption(x, caption, ...) ## S3 method for class 'dust_list' sprinkle_caption(x, caption, ...)
sprinkle_caption(x, caption, ...) ## Default S3 method: sprinkle_caption(x, caption, ...) ## S3 method for class 'dust_list' sprinkle_caption(x, caption, ...)
x |
An object of class |
caption |
|
... |
Additional arguments to pass to other methods. Currently ignored. |
The caption may be set during the initial dust
call. This
method allows for modification afterward, such as in the case of when a
dust
object is loaded from memory and the initial call cannot be
accessed.
Change the caption
attribute of the dust
object.
Cast an error if x
is not a dust
object.
Cast an error if caption
is not a character object.
Cast an error if caption
has length greater than 1.
Benjamin Nutter
The table caption is often used as a brief title, but may also be used to provide a longer statement explaining how to interpret the table results.
sprinkle_caption_number(x, caption_number, ...) ## Default S3 method: sprinkle_caption_number( x, caption_number = getOption("pixie_caption_number", TRUE), ... ) ## S3 method for class 'dust_list' sprinkle_caption_number( x, caption_number = getOption("pixie_caption_number", TRUE), ... )
sprinkle_caption_number(x, caption_number, ...) ## Default S3 method: sprinkle_caption_number( x, caption_number = getOption("pixie_caption_number", TRUE), ... ) ## S3 method for class 'dust_list' sprinkle_caption_number( x, caption_number = getOption("pixie_caption_number", TRUE), ... )
x |
An object of class |
caption_number |
|
... |
Additional arguments to pass to other methods. Currently ignored. |
Table numbering makes it possible to reference tables within a document. In some cases, the numbering is not desired. Suppressing numbering may restrict the ability to make reference to the table.
Change the caption_number
attribute of the dust
object.
Cast an error if x
is not a dust
object.
Cast an error if caption_number
is not a logical object.
Cast an error if caption_number
has length greater than 1.
Benjamin Nutter
dust
TablesAssigns new column names to a table
sprinkle_colnames(x, ...) ## Default S3 method: sprinkle_colnames(x, ...) ## S3 method for class 'dust_list' sprinkle_colnames(x, ...)
sprinkle_colnames(x, ...) ## Default S3 method: sprinkle_colnames(x, ...) ## S3 method for class 'dust_list' sprinkle_colnames(x, ...)
x |
A dust object. |
... |
Column names for the table. See 'Input Formats' |
named arguments Using dust_colnames(term = "Term", estimate = "Estimate")
,
column names may be passed for all or a subset of the columns. The existing column
name will be matched against the argument name.
unnamed arguments Using dust_colnames("Term", "Estimate", "SE", ...)
,
column names may be passed for all of the columns. If the arguments are unnamed, the
number of arguments passed must match the number of columns in the table.
When using named arguments (or a named vector), you may not mix named and unnamed elements. In other words, if one element is named, they must all be named. Unnamed elements are assigned to columns in sequential order.
Benjamin Nutter
x <- dust(lm(mpg ~ qsec + factor(am), data = mtcars)) x x %>% sprinkle_colnames(term = "Term", statistic = "T") x %>% sprinkle_colnames("Term", "Estimate", "SE", "T-statistic", "p-value") ## Not run: # Causes an error due to too few unnamed arguments x %>% sprinkle_colnames("Term", "Estimate") ## End(Not run)
x <- dust(lm(mpg ~ qsec + factor(am), data = mtcars)) x x %>% sprinkle_colnames(term = "Term", statistic = "T") x %>% sprinkle_colnames("Term", "Estimate", "SE", "T-statistic", "p-value") ## Not run: # Causes an error due to too few unnamed arguments x %>% sprinkle_colnames("Term", "Estimate") ## End(Not run)
Distinct values within a range will be assigned a color and the designated attribute of the table will be modified accordingly.
sprinkle_discrete( x, rows = NULL, cols = NULL, discrete = "bg", discrete_colors = getOption("pixie_discrete_pal", NULL), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_discrete( x, rows = NULL, cols = NULL, discrete = "bg", discrete_colors = getOption("pixie_discrete_pal", NULL), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_discrete( x, rows = NULL, cols = NULL, discrete = "bg", discrete_colors = getOption("pixie_discrete_pal", NULL), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_discrete( x, rows = NULL, cols = NULL, discrete = "bg", discrete_colors = getOption("pixie_discrete_pal", NULL), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_discrete( x, rows = NULL, cols = NULL, discrete = "bg", discrete_colors = getOption("pixie_discrete_pal", NULL), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_discrete( x, rows = NULL, cols = NULL, discrete = "bg", discrete_colors = getOption("pixie_discrete_pal", NULL), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
discrete |
|
discrete_colors |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
This sprinkle is only recognized by HTML and LaTeX. All of the
height_units
values are recognized by HTML. For LaTeX, "px"
is converted to "pt"
.
"font"
and "font_color"
both change the font color.
"border"
is a shortcut to specify all borders.
Correctly reassigns the appropriate elements of the bg
,
font_color
, left_border
, top_border
,
right_border
, or bottom_border
column in the table part.
Casts an error if x
is not a dust
object.
Casts an error if discrete
is not a subset of
c("bg", "font", "font_color", "border", "left_border",
"right_border", "top_border", "bottom_border")
Casts an error if discrete_colors
is not a character
value.
Casts an error if any value of discrete_colors
is not a
recognized color value.
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
Long tables to be displayed on-screen may benefit by keeping the header fixed in position while scrolling through the body of the table. This allows the user to maintain visual contact between the column name and the data.
sprinkle_fixed_header( x, fixed_header = TRUE, include_fixed_header_css = TRUE, fixed_header_class_name = "pixie-fixed", scroll_body_height = 300, scroll_body_height_units = "px", scroll_body_background_color = "white", fixed_header_height = 20, fixed_header_height_units = "px", fixed_header_text_height = fixed_header_height/2, fixed_header_text_height_units = "px", fixed_header_background_color = "white", ... ) ## Default S3 method: sprinkle_fixed_header( x, fixed_header = TRUE, include_fixed_header_css = TRUE, fixed_header_class_name = "pixie-fixed", scroll_body_height = 300, scroll_body_height_units = "px", scroll_body_background_color = "white", fixed_header_height = 20, fixed_header_height_units = "px", fixed_header_text_height = fixed_header_height/2, fixed_header_text_height_units = "px", fixed_header_background_color = "white", ... ) ## S3 method for class 'dust_list' sprinkle_fixed_header( x, fixed_header = TRUE, include_fixed_header_css = TRUE, fixed_header_class_name = "pixie-fixed", scroll_body_height = 300, scroll_body_height_units = "px", scroll_body_background_color = "white", fixed_header_height = 20, fixed_header_height_units = "px", fixed_header_text_height = fixed_header_height/2, fixed_header_text_height_units = "px", fixed_header_background_color = "white", ... )
sprinkle_fixed_header( x, fixed_header = TRUE, include_fixed_header_css = TRUE, fixed_header_class_name = "pixie-fixed", scroll_body_height = 300, scroll_body_height_units = "px", scroll_body_background_color = "white", fixed_header_height = 20, fixed_header_height_units = "px", fixed_header_text_height = fixed_header_height/2, fixed_header_text_height_units = "px", fixed_header_background_color = "white", ... ) ## Default S3 method: sprinkle_fixed_header( x, fixed_header = TRUE, include_fixed_header_css = TRUE, fixed_header_class_name = "pixie-fixed", scroll_body_height = 300, scroll_body_height_units = "px", scroll_body_background_color = "white", fixed_header_height = 20, fixed_header_height_units = "px", fixed_header_text_height = fixed_header_height/2, fixed_header_text_height_units = "px", fixed_header_background_color = "white", ... ) ## S3 method for class 'dust_list' sprinkle_fixed_header( x, fixed_header = TRUE, include_fixed_header_css = TRUE, fixed_header_class_name = "pixie-fixed", scroll_body_height = 300, scroll_body_height_units = "px", scroll_body_background_color = "white", fixed_header_height = 20, fixed_header_height_units = "px", fixed_header_text_height = fixed_header_height/2, fixed_header_text_height_units = "px", fixed_header_background_color = "white", ... )
x |
An object of class |
fixed_header |
|
include_fixed_header_css |
|
fixed_header_class_name |
|
scroll_body_height |
|
scroll_body_height_units |
|
scroll_body_background_color |
|
fixed_header_height |
|
fixed_header_height_units |
|
fixed_header_text_height |
|
fixed_header_text_height_units |
|
fixed_header_background_color |
|
... |
Arguments to pass to other methods. |
CSS doesn't make this kind of table natural. The solution to
generate the fixed headers used by pixiedust
is probably not the
best solution in terms of CSS design. It is, however, the most conducive
to generating dynamically on the fly.
The fixed header table requires nesting several HTML elements.
a div
tag is used to control the alignment of the table
a section
tag is used to set up the header row that remains fixed.
a div
that sets the height of the scrollable body
the table
tag establishes the actual table.
The th
tags inside the table are set to full transparency and
the content of the headers is duplicated in a div
within the
th
tag to display the content.
To accomplish these tasks, some CSS is exported with the table and placed in the document immediately before the table. Read further to understand the conflicts that may arise if you are using custom CSS specifications in your documents.
Because of all of the shenanigans involved, exporting the CSS with the tables
may result in conflicts with your custom CSS. Most importantly, any CSS
you have applied to the th
or td
tags may be overwritten.
If you are using custom CSS, you may want to consider using
include_fixed_header_css = FALSE
and then utilizing
fixed_header_css
to generate CSS you can include in your
CSS file to provide the fixed headers. The code generated by
fixed_header_css
ought to be placed before your definitions for
td
and th
.
To get the same header design in the fixed table, you will want to modify
the .th-pixie-fixed div
definition in the CSS to match your desired
th
definition.
The code produced by fixed_header_css
will include comments where
there is potential for a CSS conflict.
Set the fixed_header
element of the dust
object correctly.
Set the include_fixed_header_css
element of the dust
object correctly.
Set the fixed_header_param
element of the dust
object
correctly.
Cast an error if x
does not inherit class dust
Cast an error if scroll_body_height
is not integerish(1)
Cast an error if scroll_body_height_units
is not character(1)
Cast an error if scroll_body_background_color
is not character(1)
Cast an error if scroll_body_background_color
is not a valid color.
Cast an error if fixed_header_height
is not integerish(1)
Cast an error if fixed_header_height_units
is not character(1)
Cast an error if fixed_header_text_height
is not numeric(1)
Cast an error if fixed_header_text_height_units
is not character(1)
Cast an error if fixed_header_background_color
is not character(1)
Cast an error if fixed_header_background_color
is not a valid color.
Cast an error if include_fixed_header_css
is not logical(1)
Cast an error if fixed_header_class_name
is not character(1)
Alter the floating behavior of tables rendered in
LaTeX documents. Floating tables are moved to a position deemed ideal
by the typesetter. Setting float = FALSE
causes the table to
be rendered in the position in which it is generated in the code.
sprinkle_float(x, float = getOption("pixie_float", FALSE), ...) ## Default S3 method: sprinkle_float(x, float = getOption("pixie_float", FALSE), ...) ## S3 method for class 'dust_list' sprinkle_float(x, float = getOption("pixie_float", FALSE), ...)
sprinkle_float(x, float = getOption("pixie_float", FALSE), ...) ## Default S3 method: sprinkle_float(x, float = getOption("pixie_float", FALSE), ...) ## S3 method for class 'dust_list' sprinkle_float(x, float = getOption("pixie_float", FALSE), ...)
x |
An object of class |
float |
|
... |
Additional arguments to pass to other methods. Currently ignored. |
See https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions for more about floating environments in LaTeX.
This property has no effect on non-LaTeX output.
Change the float
attribute of the dust
object.
Cast an error if x
is not a dust
object.
Cast an error if float
is not logical or length 1.
Benjamin Nutter
https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions
The pre-defined sprinkles do not always provide the desired impact on the tables. Applying a function allows for highly customized output without having to pre-process that data frame.
sprinkle_fn( x, rows = NULL, cols = NULL, fn = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols"), ... ) ## Default S3 method: sprinkle_fn( x, rows = NULL, cols = NULL, fn = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_fn( x, rows = NULL, cols = NULL, fn = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_fn( x, rows = NULL, cols = NULL, fn = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols"), ... ) ## Default S3 method: sprinkle_fn( x, rows = NULL, cols = NULL, fn = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_fn( x, rows = NULL, cols = NULL, fn = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
fn |
An object of class |
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
dust
objects transform tabular objects so that each cell
in the table comprises one row in the data frame of cell attributes.
The function to be applied needs to act on the value
column of
that data frame.
Correctly reassigns the appropriate elements fn
column
in the table part.
Casts an error if x
is not a dust
object.
Casts an error if fn
is not a call
object.
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
Benjamin Nutter
Text can be made to stand out (or fade away) by using font features such as bold and italic text, color, size, or different fonts.
sprinkle_font( x, rows = NULL, cols = NULL, bold = NULL, italic = NULL, font_size = NULL, font_size_units = NULL, font_color = NULL, font_family = NULL, ..., part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = "none" ) ## Default S3 method: sprinkle_font( x, rows = NULL, cols = NULL, bold = NULL, italic = NULL, font_size = NULL, font_size_units = NULL, font_color = NULL, font_family = NULL, ..., part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = "none" ) ## S3 method for class 'dust_list' sprinkle_font( x, rows = NULL, cols = NULL, bold = NULL, italic = NULL, font_size = NULL, font_size_units = NULL, font_color = NULL, font_family = NULL, ..., part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = "none" )
sprinkle_font( x, rows = NULL, cols = NULL, bold = NULL, italic = NULL, font_size = NULL, font_size_units = NULL, font_color = NULL, font_family = NULL, ..., part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = "none" ) ## Default S3 method: sprinkle_font( x, rows = NULL, cols = NULL, bold = NULL, italic = NULL, font_size = NULL, font_size_units = NULL, font_color = NULL, font_family = NULL, ..., part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = "none" ) ## S3 method for class 'dust_list' sprinkle_font( x, rows = NULL, cols = NULL, bold = NULL, italic = NULL, font_size = NULL, font_size_units = NULL, font_color = NULL, font_family = NULL, ..., part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = "none" )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
bold |
|
italic |
|
font_size |
|
font_size_units |
|
font_color |
|
font_family |
|
... |
Additional arguments to pass to other methods. Currently ignored. |
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
The bold
and italic
features are recognized by all
formats.
Font size features are recognized by HTML and LaTeX. LaTeX only recognizes
the font size unit options of "pt"
and "em"
, but will quietly
change "px"
to "pt"
when printing.
Font color features are recognized by HTML and LaTeX.
Font family is only recognized by HTML.
Correctly change the bold
column of the table part for
the selected cells.
Correctly change the italic
column of the table part for
the selected cells.
Correctly change the font_size
column of the table part for
the selected cells.
Correctly change the font_size_units
column of the table part for
the selected cells.
Correctly chagne the font_color
column of the table part
for the selected cells.
Correctly change the font_family
column of the table part for
the selected cells.
Cast an error if x
is not a dust object.
Cast an error if bold
is not logical(1)
Cast an error if italic
is not logical(1)
Cast an error if font_size
is not numeric(1)
Cast an error if font_size_units
is not character(1)
Cast an error if font_size_units
is not one of
px, pt, em, or
Cast an error if font_color
is not character(1)
Cast an error if font_family
is not character(1)
Cast an error if part
is not a subset of c("body",
"head", "foot", "interfoot")
Cast an error if recycle = "none"
and bold
does not have length 1.
Cast an error if recycle = "none"
and italic
does not have length 1.
Cast an error if recycle = "none"
and font_size
does not have length 1.
Cast an error if recycle = "none"
and font_size_units
does not have length 1.
Cast an error if recycle = "none"
and font_color
does not have length 1.
Cast an error if recycle = "none"
and font_family
does not have length 1.
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
Benjamin Nutter
Numeric values within a range of cells are binned and colors assigned to show gradual increases in the numeric value.
sprinkle_gradient( x, rows = NULL, cols = NULL, gradient = "bg", gradient_colors = getOption("pixie_gradient_pal", NULL), gradient_cut = NULL, gradient_n = 10, gradient_na = "grey", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_gradient( x, rows = NULL, cols = NULL, gradient = "bg", gradient_colors = getOption("pixie_gradient_pal", c("#132B43", "#56B1F7")), gradient_cut = NULL, gradient_n = 10, gradient_na = "grey", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_gradient( x, rows = NULL, cols = NULL, gradient = "bg", gradient_colors = getOption("pixie_gradient_pal", c("#132B43", "#56B1F7")), gradient_cut = NULL, gradient_n = 10, gradient_na = "grey", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_gradient( x, rows = NULL, cols = NULL, gradient = "bg", gradient_colors = getOption("pixie_gradient_pal", NULL), gradient_cut = NULL, gradient_n = 10, gradient_na = "grey", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_gradient( x, rows = NULL, cols = NULL, gradient = "bg", gradient_colors = getOption("pixie_gradient_pal", c("#132B43", "#56B1F7")), gradient_cut = NULL, gradient_n = 10, gradient_na = "grey", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_gradient( x, rows = NULL, cols = NULL, gradient = "bg", gradient_colors = getOption("pixie_gradient_pal", c("#132B43", "#56B1F7")), gradient_cut = NULL, gradient_n = 10, gradient_na = "grey", part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
gradient |
|
gradient_colors |
|
gradient_cut |
|
gradient_n |
|
gradient_na |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
This sprinkle is only recognized by HTML and LaTeX. All of the
height_units
values are recognized by HTML. For LaTeX, "px"
is converted to "pt"
.
"font"
and "font_color"
both change the font color.
"border"
is a shortcut to specify all borders.
Correctly reassigns the appropriate elements of the bg
,
font_color
, left_border
, top_border
,
right_border
, or bottom_border
column in the table part.
Casts an error if x
is not a dust
object.
Casts an error if gradient
is not a subset of
c("bg", "font", "font_color", "border", "left_border",
"right_border", "top_border", "bottom_border")
Casts an error if gradient_colors
is not a character(2)
value.
Casts an error if any value of gradient_colors
is not a
recognized color value.
Casts an error if gradient_cut
is not numeric
.
Casts an error if gradient_n
is not numeric(1)
.
Casts an error if gradient_na
is not character(1)
.
Casts an error if gradient_na
is not a valid color.
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
Customize the height of a cell in a table. This may be done to improve the appearance of cells with long text.
sprinkle_height( x, rows = NULL, cols = NULL, height = NULL, height_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_height( x, rows = NULL, cols = NULL, height = NULL, height_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_height( x, rows = NULL, cols = NULL, height = NULL, height_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_height( x, rows = NULL, cols = NULL, height = NULL, height_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_height( x, rows = NULL, cols = NULL, height = NULL, height_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_height( x, rows = NULL, cols = NULL, height = NULL, height_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
height |
|
height_units |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
This sprinkle is only recognized by HTML and LaTeX. All of the
height_units
values are recognized by HTML. For LaTeX, "px"
is converted to "pt"
.
Correctly reassigns the appropriate elements of height
and height_units
columns in the table part.
Casts an error if x
is not a dust
object.
Casts an error if height
is not a numeric(1)
Casts an error if height_units
is not a character(1)
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
Cast an error if recycle = "none"
and height
does not have length 1.
When recycle = "none"
, quietly coerce height_units
to just the first element given.
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
The hhline
property controls the appearance of
cell borders in LaTeX tables. There is a known limitation in the
LaTeX colortbl
package where cell borders can be hidden if
the cell has a background color. If using both cell borders and
background colors, it is recommended that you use the hhline
property to make cell borders appear as desired.
sprinkle_hhline(x, hhline = getOption("pixie_hhline", FALSE), ...) ## Default S3 method: sprinkle_hhline(x, hhline = getOption("pixie_hhline", FALSE), ...) ## S3 method for class 'dust_list' sprinkle_hhline(x, hhline = getOption("pixie_hhline", FALSE), ...)
sprinkle_hhline(x, hhline = getOption("pixie_hhline", FALSE), ...) ## Default S3 method: sprinkle_hhline(x, hhline = getOption("pixie_hhline", FALSE), ...) ## S3 method for class 'dust_list' sprinkle_hhline(x, hhline = getOption("pixie_hhline", FALSE), ...)
x |
An object of class |
hhline |
|
... |
Additional arguments to pass to other methods. Currently ignored. |
When hhline = TRUE
, borders will be solid; dashed and dotted
borders are unsupported by hhline.
This property has no effect on non-LaTeX output.
Change the hhline
attribute of the dust
object.
Cast an error if x
is not a dust
object.
Cast an error if hhline
is not logical and length 1.
Benjamin Nutter
https://www.ctan.org/pkg/hhline?lang=en
By default pixiedust
makes use of htmltools::htmlPreserve
to prevent certain symbols from rendering in unintended ways based on some
not-very-well-understood-by-the-author issues. This property controls whether
the preservation is used or not.
sprinkle_html_preserve( x, html_preserve = getOption("pixie_html_preserve", TRUE), ... ) ## Default S3 method: sprinkle_html_preserve( x, html_preserve = getOption("pixie_html_preserve", TRUE), ... ) ## S3 method for class 'dust_list' sprinkle_html_preserve( x, html_preserve = getOption("pixie_html_preserve", TRUE), ... )
sprinkle_html_preserve( x, html_preserve = getOption("pixie_html_preserve", TRUE), ... ) ## Default S3 method: sprinkle_html_preserve( x, html_preserve = getOption("pixie_html_preserve", TRUE), ... ) ## S3 method for class 'dust_list' sprinkle_html_preserve( x, html_preserve = getOption("pixie_html_preserve", TRUE), ... )
x |
An object of class |
html_preserve |
|
... |
Additional arguments to pass to other methods. Currently ignored. |
Change the html_preserve
attribute of the dust
object.
Cast an error if x
is not a dust
object.
Cast an error if html_preserve
is not logical(1).
Benjamin Nutter
The justification of the table determines the horizontal placing of the table on the page.
sprinkle_justify(x, justify = getOption("pixie_justify", "center"), ...) ## Default S3 method: sprinkle_justify(x, justify = getOption("pixie_justify", "center"), ...) ## S3 method for class 'dust_list' sprinkle_justify(x, justify = getOption("pixie_justify", "center"), ...)
sprinkle_justify(x, justify = getOption("pixie_justify", "center"), ...) ## Default S3 method: sprinkle_justify(x, justify = getOption("pixie_justify", "center"), ...) ## S3 method for class 'dust_list' sprinkle_justify(x, justify = getOption("pixie_justify", "center"), ...)
x |
An object of class |
justify |
|
... |
Additional arguments to pass to other methods. Currently ignored. |
For HTML tables, the values "center"
,
"left"
, and "right"
all justify the table as expected.
It is important to note, however, that "left"
and "right"
will cause subsequent elements to be rendered next to the table, not
below it. To render the table with left alignment without this side
effect, use "none"
.
In LaTeX output, both "right"
and "left"
justify
to the left. This may change in the future if I find a resolution. Using
"none"
also results in left justification.
Change the justify
attribute of the dust
object.
Cast an error if x
is not a dust
object.
Cast an error if justify
is not one of "center"
,
"none"
, "left"
, or "right"
.
Ignore capitalization of the justify
argument.
Benjamin Nutter
The label
property is used to make references to a
table. Labels may be used in LaTeX documents, or in both LaTeX and
HTML documents when using bookdown
.
sprinkle_label(x, label = NULL, ...) ## Default S3 method: sprinkle_label(x, label = NULL, ...) ## S3 method for class 'dust_list' sprinkle_label(x, label = NULL, ...)
sprinkle_label(x, label = NULL, ...) ## Default S3 method: sprinkle_label(x, label = NULL, ...) ## S3 method for class 'dust_list' sprinkle_label(x, label = NULL, ...)
x |
An object of class |
label |
|
... |
Additional arguments to pass to other methods. Currently ignored. |
For details about using labels in LaTeX documents, see https://en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing.
For details about using labels in bookdown
documents, see
https://bookdown.org/yihui/bookdown/tables.html
Change the label
attribute of the dust
object.
Cast an error if x
is not a dust
object.
Cast an error if label
is not a character(1)
.
Benjamin Nutter
https://en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing
https://bookdown.org/yihui/bookdown/tables.html
The LaTeX longtable
package allows for long tables
to be broken into multiple parts to be displayed on separate pages.
pixiedust
will mimic this behavior for other output types.
sprinkle_longtable(x, longtable = getOption("pixie_longtable", FALSE), ...) ## Default S3 method: sprinkle_longtable(x, longtable = getOption("pixie_longtable", FALSE), ...) ## S3 method for class 'dust_list' sprinkle_longtable(x, longtable = getOption("pixie_longtable", FALSE), ...)
sprinkle_longtable(x, longtable = getOption("pixie_longtable", FALSE), ...) ## Default S3 method: sprinkle_longtable(x, longtable = getOption("pixie_longtable", FALSE), ...) ## S3 method for class 'dust_list' sprinkle_longtable(x, longtable = getOption("pixie_longtable", FALSE), ...)
x |
An object of class |
longtable |
Either a |
... |
Additional arguments to pass to other methods. Currently ignored. |
When longtable = TRUE
, LaTeX tables will be divided
according to the LaTeX document settings. In other table outputs, the
default is to use 25 rows per table.
When longtable
is an integer (or integer-like) value, the table
is divided into that many rows per section. This applies to all output.
Change the longtable
attribute of the dust
object.
Cast an error if x
is not a dust
object.
Cast an error if longtable
is logical and has length not equal
to 1.
when longtable
is not logical, cast an error if
it is not-integerish and has length not equal to 1.
Benjamin Nutter
Merging cells creates more space for values to be displayed without disrupting the appearance of other cells in the same row or column. The downside is that the content from only one of the cells in the merge range will be displayed.
sprinkle_merge( x, rows = NULL, cols = NULL, merge = FALSE, merge_rowval = NULL, merge_colval = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_merge( x, rows = NULL, cols = NULL, merge = FALSE, merge_rowval = NULL, merge_colval = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_merge( x, rows = NULL, cols = NULL, merge = FALSE, merge_rowval = NULL, merge_colval = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_merge( x, rows = NULL, cols = NULL, merge = FALSE, merge_rowval = NULL, merge_colval = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_merge( x, rows = NULL, cols = NULL, merge = FALSE, merge_rowval = NULL, merge_colval = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_merge( x, rows = NULL, cols = NULL, merge = FALSE, merge_rowval = NULL, merge_colval = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
merge |
|
merge_rowval |
The row position of the cell whose content will be
displayed. Defaults to the minimum of |
merge_colval |
The column position of the cell whose content will
be displayed. Deafults to the minimum of |
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
Correctly reassigns the appropriate elements of merge
,
merge_rowval
and merge_colval
columns in the table part.
Casts an error if x
is not a dust
object.
Casts an error if merge
is not a logical(1)
Casts an error if merge_rowval
is not a numeric(1)
Casts an error if merge_colval
is not a numeric(1)
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
The appearance of NA
values in a table may be dependent
on the context. pixiedust
uses the na_string
sprinkle
to guide the appearance of missing values in the table.
sprinkle_na_string( x, rows = NULL, cols = NULL, na_string = getOption("pixie_na_string", NA), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_na_string( x, rows = NULL, cols = NULL, na_string = getOption("pixie_na_string", NA), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_na_string( x, rows = NULL, cols = NULL, na_string = getOption("pixie_na_string", NA), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_na_string( x, rows = NULL, cols = NULL, na_string = getOption("pixie_na_string", NA), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_na_string( x, rows = NULL, cols = NULL, na_string = getOption("pixie_na_string", NA), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_na_string( x, rows = NULL, cols = NULL, na_string = getOption("pixie_na_string", NA), part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
na_string |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
Correctly reassigns the appropriate elements na_string
column
in the table part.
Casts an error if x
is not a dust
object.
Casts an error if bg
is not a character(1)
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
Cast an error if recycle = "none"
and na_string
does not have length 1.
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
Padding for HTML tables indicates how many pixels should be placed between the cell's content and the outside border.
sprinkle_pad( x, rows = NULL, cols = NULL, pad = 0, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_pad( x, rows = NULL, cols = NULL, pad = 0, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_pad( x, rows = NULL, cols = NULL, pad = 0, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_pad( x, rows = NULL, cols = NULL, pad = 0, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_pad( x, rows = NULL, cols = NULL, pad = 0, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_pad( x, rows = NULL, cols = NULL, pad = 0, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
pad |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
Colors may be a dvips color name, or in the rgb(R, G, B), rgba(R, G, B, A), #RRGGBB, or #RRGGBBAA formats.
This sprinkle is ignored in console and markdown outputs. HTML output will accept any of the color formats and recognize transparency. LaTeX output will accept any of the color formats but ignore transparency.
As long as pad
is required to be a numeric(1)
, the
recycle
argument is kind of useless. It is included to maintain
consistency with the index_to_sprinkle
function. Future development
may permit a character vector of colors.
Correctly reassigns the appropriate elements pad
column
in the table part.
Casts an error if x
is not a dust
object.
Casts an error if pad
is not a numeric(1)
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
Cast an error if recycle = "none"
and pad
does not have length 1.
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
Benjamin Nutter
At times it may be necessary to replace the contents of a cell with user-supplied values.
sprinkle_replace( x, rows = NULL, cols = NULL, replace, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_replace( x, rows = NULL, cols = NULL, replace, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_replace( x, rows = NULL, cols = NULL, replace, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_replace( x, rows = NULL, cols = NULL, replace, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_replace( x, rows = NULL, cols = NULL, replace, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_replace( x, rows = NULL, cols = NULL, replace, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
replace |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
Correctly reassigns the appropriate elements replace
column
in the table part.
Casts an error if x
is not a dust
object.
Casts an error if replace
is not a vector
Casts an warning if the number of indices to replace is not a
multiple of replace
Casts an error if length(replace)
is greater than the
number of cells to replace.
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
The content of cells may be rotated when it is desired to save space (such as long table column names), or to draw attention to the cells.
sprinkle_rotate_degree( x, rows = NULL, cols = NULL, rotate_degree = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_rotate_degree( x, rows = NULL, cols = NULL, rotate_degree = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_rotate_degree( x, rows = NULL, cols = NULL, rotate_degree = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_rotate_degree( x, rows = NULL, cols = NULL, rotate_degree = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_rotate_degree( x, rows = NULL, cols = NULL, rotate_degree = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_rotate_degree( x, rows = NULL, cols = NULL, rotate_degree = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
rotate_degree |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
Correctly reassigns the appropriate elements rotate_degree
column
in the table part.
Casts an error if x
is not a dust
object.
Casts an error if rotate_degree
is not a numeric(1)
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
Cast an error if recycle = "none"
and rotate_degree
does not have length 1.
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
The appearance of NA
values in a table may be dependent
on the context. pixiedust
uses the round
sprinkle
to guide the appearance of missing values in the table.
sprinkle_round( x, rows = NULL, cols = NULL, round = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_round( x, rows = NULL, cols = NULL, round = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_round( x, rows = NULL, cols = NULL, round = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_round( x, rows = NULL, cols = NULL, round = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_round( x, rows = NULL, cols = NULL, round = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_round( x, rows = NULL, cols = NULL, round = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
round |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
Correctly reassigns the appropriate elements round
column
in the table part.
Casts an error if x
is not a dust
object.
Casts an error if round
is not a numeric(1)
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
Cast an error if recycle = "none"
and round
does not have length 1.
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
Certain characters in LaTeX code need to be escaped to
prevent errors during processing. For example, %
is the
comment character in LaTeX, and needs to be escaped in
order to render correctly.
sprinkle_sanitize( x, rows = NULL, cols = NULL, sanitize = NULL, sanitize_args = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_sanitize( x, rows = NULL, cols = NULL, sanitize = NULL, sanitize_args = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_sanitize( x, rows = NULL, cols = NULL, sanitize = NULL, sanitize_args = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_sanitize( x, rows = NULL, cols = NULL, sanitize = NULL, sanitize_args = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_sanitize( x, rows = NULL, cols = NULL, sanitize = NULL, sanitize_args = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_sanitize( x, rows = NULL, cols = NULL, sanitize = NULL, sanitize_args = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
sanitize |
|
sanitize_args |
A list of arguments to pass to
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
This sprinkle is only recognized by LaTeX output. See
latexTranslate
for more details.
Correctly reassigns the appropriate elements of sanitize
and sanitize_args
columns in the table part.
Casts an error if x
is not a dust
object.
Casts an error if sanitize
is not a logical(1)
Casts an error if sanitize_args
is not a list
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
The tabcolsep
property controls the space between
columns in LaTeX output. By default, it is set to 6 pt.
sprinkle_tabcolsep(x, tabcolsep = getOption("pixie_tabcolsep", 6), ...) ## Default S3 method: sprinkle_tabcolsep(x, tabcolsep = getOption("pixie_tabcolsep", 6), ...) ## S3 method for class 'dust_list' sprinkle_tabcolsep(x, tabcolsep = getOption("pixie_tabcolsep", 6), ...)
sprinkle_tabcolsep(x, tabcolsep = getOption("pixie_tabcolsep", 6), ...) ## Default S3 method: sprinkle_tabcolsep(x, tabcolsep = getOption("pixie_tabcolsep", 6), ...) ## S3 method for class 'dust_list' sprinkle_tabcolsep(x, tabcolsep = getOption("pixie_tabcolsep", 6), ...)
x |
An object of class |
tabcolsep |
|
... |
Additional arguments to pass to other methods. Currently ignored. |
Reading on the details of tabcolsep
may be done by
searching "latex tabcolsep" on the internet.
This property has no effect on non-LaTeX output.
Change the tabcolsep
attribute of the dust
object.
Cast an error if x
is not a dust
object.
Cast an error if tabcolsep
is not integerish and length 1.
Benjamin Nutter
Customize the width of a cell in a table. This may be done to improve the appearance of cells with long text.
sprinkle_width( x, rows = NULL, cols = NULL, width = NULL, width_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_width( x, rows = NULL, cols = NULL, width = NULL, width_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_width( x, rows = NULL, cols = NULL, width = NULL, width_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
sprinkle_width( x, rows = NULL, cols = NULL, width = NULL, width_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## Default S3 method: sprinkle_width( x, rows = NULL, cols = NULL, width = NULL, width_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... ) ## S3 method for class 'dust_list' sprinkle_width( x, rows = NULL, cols = NULL, width = NULL, width_units = NULL, part = c("body", "head", "foot", "interfoot", "table"), fixed = FALSE, recycle = c("none", "rows", "cols", "columns"), ... )
x |
An object of class |
rows |
Either a numeric vector of rows in the tabular object to be
modified or an object of class |
cols |
Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible. |
width |
|
width_units |
|
part |
A character string denoting which part of the table to modify. |
fixed |
|
recycle |
A |
... |
Additional arguments to pass to other methods. Currently ignored. |
This sprinkle is only recognized by HTML and LaTeX. All of the
width_units
values are recognized by HTML. For LaTeX, "px"
is converted to "pt"
.
Correctly reassigns the appropriate elements of width
and width_units
columns in the table part.
Casts an error if x
is not a dust
object.
Casts an error if width
is not numeric
Casts an error if width_units
is not one of
c("px", "pt", "in", "cm", "%")
.
Casts an error if part
is not one of "body"
,
"head"
, "foot"
, or "interfoot"
Casts an error if fixed
is not a logical(1)
Casts an error if recycle
is not one of "none"
,
"rows"
, or "cols"
Casts an error if recycle = "none"
and width
does
not have length 1.
Correctly assigns values when recycle
is not "none"
and multiple values are given.
Quietly accepts only the first value in width_units
when
recycle = "none"
.
The functional behavior of the fixed
and recycle
arguments
is not tested for this function. It is tested and validated in the
tests for index_to_sprinkle
.
This is a utility function that follow the pattern of
stringr::str_extract_all
. It is provided to avoid the
dependency on the stringr
package.
str_extract_base(x, pattern) str_split_fixed_base(x, pattern, n)
str_extract_base(x, pattern) str_split_fixed_base(x, pattern, n)
x |
|
pattern |
|
n |
The number of splits. |
https://stackoverflow.com/a/27274231/1017276
stringr::str_extract_all
pixiedust
TablesDefault model objects identify rows of results with
appropriate term name. More often than not, the term name is
not suitable for formally reported output. tidy_levels_labels
performs some basic work to quickly provide more readable
descriptors for cases where they can easily be obtained. These
descriptors are retrieved from the data, however, so the
utility is determined by the user's habits in providing
term labels and meaningful factor levels.
Due to the complexity of the terms that could be used for a model,
it isn't practical to attempt to recover human-ready descriptors
for every conceivable term. This would require recovering variable
names for any number of functions. pixiedust
only
goes after the easiest to obtain. Replacements no managed by
tidy_levels_labels
may still be made with the replace
sprinkle.
tidy_levels_labels( object, descriptors = "term", numeric_level = c("term", "term_plain", "label"), argcheck = NULL )
tidy_levels_labels( object, descriptors = "term", numeric_level = c("term", "term_plain", "label"), argcheck = NULL )
object |
A model object, ideally with a |
descriptors |
A character vector indicating the descriptors to
be used in the table. Acceptable inputs are |
numeric_level |
A character string that determines which descriptor
is used for numeric variables in the |
argcheck |
An assert collection created by |
The user may select up to five columns of descriptors, although doing so would certainly create some ambiguity. See the Examples for sample output.
"term"
The term name used in the R model summary
"term_plain"
The term name used in the formula.
For variables that produce multiple term names (such as factors),
the plain term name may be duplicated. For example, a factor that
has term names FctrB
and FctrC
, indicating rows for
levels B
and C
of the variable Fctr
, will
have two rows of "term_plain"
of just Fctr
.
"label"
Provides the label attached to the data using
labelVector::get_label
. When a term is not associated with a label,
the value of term_plain
is returned instead. Note that, variable names
will disassociate with a label if they are used in a function (such
as factor(x)
or x^2
.
"level"
Indicates the level being compared within a factor
(or an interaction involving a factor), otherwise it returns NA
.
It may also be said that this value is the appendix to a factor name.
For the term FctrB
, this would just be B
.
"level_detail"
Gives additional information to level
by including the reference level of the factor. For the term FctrB
,
this would return "B vs A"
. When an interaction with a numeric
variable is present, the level
for the numeric may be either
term_plain
or label
, the choice being controlled by the
level_detail
argument.
The descriptors, other than "term"
, generally don't make sense for data
frame objects. The use of tidy_levels_labels
is not permitted within
the dust
function, but is allowed if you really want it by
pixiedust:::tidy_levels_labels
.
Other special cases noted in future uses will be documented here, but in general, if it isn't a model object, you probably don't really want to use this.
Benjamin Nutter
#* Descriptors for lm output with no interactions mtcars2 <- mtcars mtcars2$mpg <- labelVector::set_label(mtcars2$mpg, "Gas Mileage") mtcars2$qsec <- labelVector::set_label(mtcars2$qsec, "Quarter Mile Time") mtcars2$am <- labelVector::set_label(mtcars2$am, "Transmission") mtcars2$wt <- labelVector::set_label(mtcars2$wt, "Weight") mtcars2$gear <- labelVector::set_label(mtcars2$gear, "Gears") #* Basic Output for a model with no interactions #* Note: numeric_level has no impact as there are no #* interactions involving numeric variables. fit <- lm(mpg ~ qsec + factor(am) + wt + factor(gear), data = mtcars2) pixiedust:::tidy_levels_labels(fit, descriptors = c("term", "term_plain", "label", "level", "level_detail"), numeric_level = "term") #* Assign factors ahead of the model. This allows #* the user to determine the levels that display. #* Compare the output for 'am' with the output for 'gear' mtcars2$am <- factor(mtcars2$am, 0:1, c("Automatic", "Manual")) mtcars2$am <- labelVector::set_label(mtcars2$am, "Transmission") # Label was lost in variable conversion fit <- lm(mpg ~ qsec + am + wt + factor(gear), data = mtcars2) pixiedust:::tidy_levels_labels(fit, descriptors = c("term", "term_plain", "label", "level", "level_detail"), numeric_level = "term") #* Include an interaction between a factor and numeric. fit <- lm(mpg ~ qsec + am * wt + factor(gear), data = mtcars2) pixiedust:::tidy_levels_labels(fit, descriptors = c("term", "term_plain", "label", "level", "level_detail"), numeric_level = "term") #* Now observe how 'level' and 'level_detail' change #* in the interaction terms as we choose different #* values for 'numeric_level' pixiedust:::tidy_levels_labels(fit, descriptors = c("term", "term_plain", "label", "level", "level_detail"), numeric_level = "term_plain") pixiedust:::tidy_levels_labels(fit, descriptors = c("term", "term_plain", "label", "level", "level_detail"), numeric_level = "label")
#* Descriptors for lm output with no interactions mtcars2 <- mtcars mtcars2$mpg <- labelVector::set_label(mtcars2$mpg, "Gas Mileage") mtcars2$qsec <- labelVector::set_label(mtcars2$qsec, "Quarter Mile Time") mtcars2$am <- labelVector::set_label(mtcars2$am, "Transmission") mtcars2$wt <- labelVector::set_label(mtcars2$wt, "Weight") mtcars2$gear <- labelVector::set_label(mtcars2$gear, "Gears") #* Basic Output for a model with no interactions #* Note: numeric_level has no impact as there are no #* interactions involving numeric variables. fit <- lm(mpg ~ qsec + factor(am) + wt + factor(gear), data = mtcars2) pixiedust:::tidy_levels_labels(fit, descriptors = c("term", "term_plain", "label", "level", "level_detail"), numeric_level = "term") #* Assign factors ahead of the model. This allows #* the user to determine the levels that display. #* Compare the output for 'am' with the output for 'gear' mtcars2$am <- factor(mtcars2$am, 0:1, c("Automatic", "Manual")) mtcars2$am <- labelVector::set_label(mtcars2$am, "Transmission") # Label was lost in variable conversion fit <- lm(mpg ~ qsec + am + wt + factor(gear), data = mtcars2) pixiedust:::tidy_levels_labels(fit, descriptors = c("term", "term_plain", "label", "level", "level_detail"), numeric_level = "term") #* Include an interaction between a factor and numeric. fit <- lm(mpg ~ qsec + am * wt + factor(gear), data = mtcars2) pixiedust:::tidy_levels_labels(fit, descriptors = c("term", "term_plain", "label", "level", "level_detail"), numeric_level = "term") #* Now observe how 'level' and 'level_detail' change #* in the interaction terms as we choose different #* values for 'numeric_level' pixiedust:::tidy_levels_labels(fit, descriptors = c("term", "term_plain", "label", "level", "level_detail"), numeric_level = "term_plain") pixiedust:::tidy_levels_labels(fit, descriptors = c("term", "term_plain", "label", "level", "level_detail"), numeric_level = "label")