Conditional Formatting in Data Frames

Apply and visualize conditional formatting to data frames in R. It renders a data frame with cells formatted according to criteria defined by rules, using a tidy evaluation syntax. The table is printed either opening a web browser or within the 'RStudio' viewer if available. The conditional formatting rules allow to highlight cells matching a condition or add a gradient background to a given column. This package supports both 'HTML' and 'LaTeX' outputs in 'knitr' reports, and exporting to an 'xlsx' file.


Sergio Oller 2018-10-27 condformat renders a data frame in which cells in columns are formatted according to several rules or criteria.

Downloads Build Status codecov.io

Browse source code

Checkout the code and browse it at http://github.com/zeehio/condformat.

How to install condformat:

If you want to use the PDF output you will need the xcolor LaTeX package. Either use the full texlive distribution, or install latex-xcolor on Debian and derivatives.

Package installation

  • From CRAN:

    install.packages("condformat")
    
  • To install the latest development version:

    devtools::install_github("zeehio/condformat")
    

Example

data(iris)
library(condformat)
condformat(iris[c(1:5,70:75, 120:125),]) %>%
  rule_fill_discrete(Species) %>%
  rule_fill_discrete(c(Sepal.Width, Sepal.Length),
                     expression = Sepal.Width > Sepal.Length - 2.25,
                     colours = c("TRUE" = "#7D00FF")) %>%
  rule_fill_gradient2(Petal.Length) %>%
  rule_text_bold(c(Sepal.Length, Species), Species == "versicolor") %>%
  rule_text_color(Sepal.Length,
                  expression = ifelse(Species == "setosa", "yellow", "")) %>%
  rule_fill_bar(Petal.Width, limits = c(0, NA)) %>%
  theme_grob(rows = NULL) %>%
  condformat2grob()

This example covers most of the condformat rules.

Rules and engine support

Rule HTML LaTeX gtable
rule_fill_discrete X X X
rule_fill_gradient X X X
rule_fill_gradient2 X X X
rule_text_color X X X
rule_text_bold X X X
rule_fill_bar X X
rule_css X

News

condformat 0.8.0

New features:

  • rule_fill_bar (HTML, for now)
  • rule_text_bold (HTML, PDF)
  • rule_text_color (HTML, PDF)
  • theme_htmlWidget (HTML) Customize the number of entries and the widget size.
  • theme_kable (PDF) pass options to kable
  • theme_caption (HTML, PDF) Set a caption.
  • condformat2grob: Engine to render tables as graphics
  • Shiny: renderCondformat works with async promises (if htmlwidgets 1.3 is available)

Deprecations:

  • Deprecate: theme_htmlTable now only accepts arguments to be passed to htmlTable::htmlTable. Before, it could also be used to accept number_of_entries, width, height... to customize the widget appearence. For that use case, please use theme_htmlWidget instead.
  • Deprecate: condformat2widget will not accept arguments to customize the appearance of the widget. Use theme_htmlWidget instead.

Other

  • Replace dependency: Use grDevices instead of gplots
  • Depend on knitr 1.18: slidy and other rmarkdown formats are properly detected (#13)
  • Drop rJava from suggests (xlsx fix released)
  • Bump rlang dependency (parse_quosure -> parse_expr) (#18, Thanks to @lionel- for the advice and code review!)
  • Internal: More modular code. CSS tags to LaTeX conversion is based on S3 methods so new rules don't need to touch the code for LaTeX export.

condformat 0.7.0

  • Add a new condformat API, that is based on tidy evaluation principles and leverages on rlang and tidyselect. The old API is still fully functional but deprecated.
  • Add a rule_css to let the user specify arbitrary CSS fields. For this rule there is no support for PDF or Excel output.
  • Improve condformat2excel to export to a specific Excel sheet (#11)
  • Fix condformat2latex and add regression test (#9)
  • Fix rescale and rescale_mid calls (recent scales use a S3 generic, so we need to import it)

condformat 0.6.0

  • Fix tibble formatting issues, causing package malfunction.
  • Bugfix: theme_htmlTable() now accepts the css.cell argument (thanks to 鱼飞灰 for reporting it)
  • Require latest htmlTable. Improve/fix printing of condformat

condformat 0.5.0

  • Shiny support: Add condformatOutput and renderCondformat. Closes #3.
    • Use pagination in shiny if recent enough htmlTable package is installed.
  • PDF support: Fix extra NULL when printing. Closes #4.
  • Demote xlsx (and rJava) to Suggests.
  • Fix standard evaluation functions, they now use formulas. See the examples (Reported in #5).
  • Fix Excel export (fixed in 80440ecfd16fb74e3e0aa4c6ebc623ad2ae74b15, reported in #7)

condformat 0.4.0

  • Excel export support with condformat2excel

condformat 0.3.0

  • PDF support: Export table to LaTeX using knitr.
  • Fix examples for full compatibility with dplyr 0.5.0

condformat 0.2.0

  • First CRAN submission
  • Add theme_htmlTable to pass custom formatting options to htmlTable.
  • Improve knitr compatibility

condformat 0.1.1

  • Change to a ggplot-like syntax

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("condformat")

0.8.0 by Sergio Oller Moreno, 6 months ago


http://github.com/zeehio/condformat


Report a bug at http://github.com/zeehio/condformat/issues


Browse source code at https://github.com/cran/condformat


Authors: Sergio Oller Moreno [aut, cph, cre]


Documentation:   PDF Manual  


BSD_3_clause + file LICENSE license


Imports grDevices, graphics, gridExtra, gtable, htmlTable, htmltools, tibble, scales, dplyr, lazyeval, knitr, rmarkdown, magrittr, rlang, tidyselect

Suggests promises, shiny, testthat, xlsx


See at CRAN