Learn R Programming

pixiedust (version 0.5.0)

sprinkle: Define Customizations to a Table

Description

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.

Usage

sprinkle(x, rows = NULL, cols = NULL, ..., part = c("body", "head",
  "foot", "interfoot", "table"))

sprinkle_print_method(x, print_method = c("console", "markdown", "html",
  "latex"))

sprinkle_table(x, cols = NULL, ..., part = "table")

Arguments

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.
print_method
A character string giving the print method for the table.

Sprinkles

The following list 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. For a complete list of which sprinkles are recognized by each output type, see vignette("sprinkles", package = "pixiedust").
  • bg
{A character string denoting the color for the background. See "Colors".} bg_pattern{This is one of the few exceptions to the length 1 rule. This accepts a vector of any length. Background colors are recycled in a pattern. See "Colors". If left unspecified but bg_pattern_by is specified, this will default to c("White", "Gray").} bg_pattern_by{A character string denoting if the background pattern is recycled over rows or columns. Accepts either "rows", or "columns" with partial matching and defaults to "rows". If bg_pattern is provided, bg_pattern_by is assumed, meaning it is not necessary to explicitly define bg_pattern_by unless changing an existing or default setting.} bold{Logical value. If TRUE, text is rendered in bold.} border_collapse{Logical. Defaults to TRUE. This element is only applicable to part = "table" and will be applied to the table regardless the value of part in the call.} border{This is one of the few exceptions to the length 1 rule. Accepts values "left", "right", "top", "bottom", and "all" with partial matching. The border will be added to the sides indicated.} border_thickness{A numeric value denoting the thickness of the border. Defaults to 1.} border_units{A character string taking any one of the values "px" or "pt" with partial matching. Defaults to "px".} border_style{A character string taking any one of the values "solid", "dashed", "dotted", "double", "groove", "ridge", "inset", "outset", "hidden", or "none". Defaults to "solid".} border_color{A character string denoting the color for the border. See "Colors".} fn{A function to apply to values in cells. The function should be an expression that acts on the variable value. For example, quote(round(value, 3)).} font_color{A character string denoting the color of the font. See "Colors".} font_size{A numeric value denoting the size of the font.} font_size_units{A character string giving the units of the font size. Accepts values "px", "pt", "%", and "em". Defaults to "pt". LaTeX formats only recognize "pt" and "em", and other units specifications will be coerced to "pt", which may result in an unexpected appearance.} halign{A character string denoting the horizontal alignment. Accepts any one of the values "left", "center", or "right", with partial matching.} height{A numerical value giving the height of the cells.} height_units{A character string giving the units for the height argument. Accepts "px", "pt", "cm", "in" and "%". Defaults to "pt". LaTeX formats do not recognize "px" and this will be coerced to "pt" when submitted for LaTeX output.} italic{Logical value. If TRUE, text is rendered in italics.} 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 FALSE, indicating that only one table is printed (default); TRUE that the table should be split into multiple tables with the default number of rows per table (see "Longtable"); or a positive integer indicating how many rows per table to include. All other values are interpreted as FALSE.} merge{Logical. If TRUE, the cells indicated in rows and cols are merged into a single cell. An error is cast if the cells do not form an adjacent block. Specifying merge_rowval or merge_colval without merge results in an error; pixiedust is conservative and will not assume you mean to merge cells--it must be explicitly declared.} merge_rowval{A numeric value of length 1 indicating the row position of the merged cells with the desired display text. The value given must be an element of rows. If no value is provided, the smallest value of rows is used.} merge_colval{A numeric value of length 1 indicating the column position of the merged cells with the desired display text. The value given must be an element of cols. If no value is provided, the smallest value of cols is used.} na_string{A character value of length 1. Specifies how missing values (NA) are to be represented in the table. Defaults to an empty character string ("").} pad{A numerical value giving the cell padding in pixels.} replace{A character vector (or vector to be coerced to character) that will replace the cells identified by rows and cols. Replacement is always performed moving down columns first, then across rows from left to right. The operating assumption is that the most frequent use of this argument will be to replace entire columns.} rotate_degree{A numerical value that determines the angle of rotation in the clockwise direction. Use negative values to rotate counter clockwise.} round{A numerical value for the number of decimal places to which numerical values are rounded. This can also be accomplished through the fn argument, but this argument makes it a bit easier to do. In cases where character values are indicated for rounding (such a a term name), no action is taken. This means that `sprinkle(x, round=3)` would round all numerical values in a table to three decimal places without affecting any true character values; there is no need to limit the `round` sprinkle to known numerical values.} valign{A character string giving the vertical alignment for the cells. Accepts the values "top", "middle", or "bottom" with partial matching.} width{A numerical value giving the width of the cells.} width_units{A character string giving the units for the width argument. Accepts "px", "pt", "cm", "in" and "%". Defaults to "px". LaTeX formats do not recognize "px" and this will be coerced to "pt" when submitted for LaTeX output.}

Longtable

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.

HTML Colors

Color specifications accept X11 color names ("orchid"), hexidecimal names ("#DA70D6"), rgb names ("rgb(218 112 214)"), and rgba (rgb+alpha transparency; "rgba(218, 112, 214, .75)"). Refer to https://en.wikipedia.org/wiki/Web_colors#X11_color_names. HTML color names are not case sensitive, but the color names in LaTeX output are. If you desire to be able to toggle your output between HTML and LaTeX, it is recommended that you use the color names under the dvips section of page 38 of the LaTeX package xcolor manual (http://ctan.mirrorcatalogs.com/macros/latex/contrib/xcolor/xcolor.pdf.

LaTeX Colors

Use of color in LaTeX requirements requires that you have the LaTeX color package included in your document preamble (\usepackage{color}). Rmarkdown documents include the color package automatically. The standard colors available in LaTeX are "white", "black", "red", "green", "blue", "cyan", "magenta", and "yellow". Additional colors may be made available using the LaTeX package xcolor. To be consistent with color names used in the HTML tables, it is recommended that you use the option \usepackage[dvipsnames]{xcolor} in your preamble. Please note that color names in LaTeX are case-sensitive, but the HTML names are not. If the ability to switch between output methods is something you desire, you should adopt the capitalization used in the dvips names (See page 38 of the xcolor manual; http://ctan.mirrorcatalogs.com/macros/latex/contrib/xcolor/xcolor.pdf). If desired, you may also use the [x11names] option to have the X11 color names available to you. The LaTeX output will accept hexidecimal names ("#DA70D6") and rgb names ("rgb(218 112 214)"), similar to the HTML colors described above. However, transparency is not supported. If the transparency value is provided, it is silently ignored. Custom color definitions may also be defined by defining the color in the preamble. The process for color definitions is described in the xcolor documentation. Keep in mind that custom color designations in LaTeX output will not transfer the other output formats.

Required LaTeX Packages

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: ll{ Sprinkle LaTeX Package(s) font_color \usepackage[dvipsnames]{xcolor} bg, bg_pattern \usepackage[dvipsnames,table]{xcolor} }

Details

Sprinkling is done over the intersection of rows and columns. 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. Whenever part = "table", rows and columns are ignored and the attributes are applied to the entire table. This feature is not yet implemented (2015-08-05) and may be removed, depending on how useful it turns out to be. 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") In sprinkle, when part = "table", the attributes are assigned to the entire table. This is not yet active and may be removed entirely. The 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.

See Also

sprinkle_colnames for changing column names in a table.

Examples

Run this code
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)

Run the code above in your browser using DataLab