Skip to content

Commit

Permalink
Examples and tests don't open browser windows anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
zeehio committed May 14, 2020
1 parent 8d4ba0a commit 6cb3380
Show file tree
Hide file tree
Showing 37 changed files with 240 additions and 59 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Replace xlsx with openxlsx. This avoids pulling RJava as a suggested dependency
* Warn if unsupported rule is used with Excel output
* Fix warning due to rlang update
* Change examples and tests so they don't open browser windows

# condformat 0.8.0

Expand Down
15 changes: 12 additions & 3 deletions R/condformat.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@
#' viewed using RStudio Viewer or an HTML browser, as available.
#' @examples
#' data(iris)
#' condformat(iris[1:5,])
#' cf <- condformat(iris[1:5,])
#' \dontrun{
#' print(cf)
#' }
#'
#' condformat(iris[1:5,]) %>% rule_fill_gradient(Sepal.Length)
#' cf <- condformat(iris[1:5,]) %>% rule_fill_gradient(Sepal.Length)
#' \dontrun{
#' print(cf)
#' }
#'
#' condformat(iris[1:5,]) %>%
#' cf <- condformat(iris[1:5,]) %>%
#' rule_fill_discrete(Sepal.Length, expression=Sepal.Width > 2)
#' \dontrun{
#' print(cf)
#' }
#' @export
condformat <- function(x) {
x <- tibble::as_tibble(x)
Expand Down
2 changes: 2 additions & 0 deletions R/condformat_render.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#' @return the value returned by htmlTable
#' @examples
#' data(iris)
#' \dontrun{
#' print(condformat(iris[1:5,]))
#' }
#' @export
print.condformat_tbl <- function(x, ..., paginate = TRUE) {
if (!is.null(getOption("knitr.in.progress"))) {
Expand Down
10 changes: 8 additions & 2 deletions R/render_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#' @return the htmlTable object
#' @examples
#' data(iris)
#' condformat2html(condformat(iris[1:5,]))
#' cf <- condformat2html(condformat(iris[1:5,]))
#' \dontrun{
#' print(cf)
#' }
#' @export
condformat2html <- function(x) {
htmltable_ready <- condformat2htmlcommon(x)
Expand All @@ -23,7 +26,10 @@ condformat2html <- function(x) {
#' @examples
#' \dontrun{
#' data(iris)
#' condformat2widget(condformat(iris[1:5,]))
#' cf <- condformat2widget(condformat(iris[1:5,]))
#' \dontrun{
#' print(cf)
#' }
#' }
#' @export
condformat2widget <- function(x, ...) {
Expand Down
5 changes: 4 additions & 1 deletion R/rule_css.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
#' @param na.value CSS property value to be used in missing values (e.g. `"grey"`)
#' @examples
#' data(iris)
#' condformat(iris[c(1:5, 51:55, 101:105),]) %>%
#' cf <- condformat(iris[c(1:5, 51:55, 101:105),]) %>%
#' rule_css(Species, expression = ifelse(Species == "setosa", "red", "darkgreen"),
#' css_field = "color")
#' \dontrun{
#' print(cf)
#' }
#' @export
rule_css <- function(x, columns, expression,
css_field,
Expand Down
5 changes: 4 additions & 1 deletion R/rule_fill_bar.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
#' @return The condformat_tbl object, with the added formatting information
#' @examples
#' data(iris)
#' condformat(iris[c(1:5, 70:75, 120:125), ]) %>% rule_fill_bar("Sepal.Length")
#' cf <- condformat(iris[c(1:5, 70:75, 120:125), ]) %>% rule_fill_bar("Sepal.Length")
#' \dontrun{
#' print(cf)
#' }
#' @export
rule_fill_bar <- function(x, columns, expression,
low = "darkgreen",
Expand Down
10 changes: 8 additions & 2 deletions R/rule_fill_discrete.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@
#' @return The condformat_tbl object, with the added formatting information
#' @examples
#' data(iris)
#' condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' cf <- condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' rule_fill_discrete("Species", colours = c("setosa" = "red",
#' "versicolor" = "blue",
#' "virginica" = "green")) %>%
#' rule_fill_discrete("Sepal.Length", expression = Sepal.Length > 4.6,
#' colours=c("TRUE"="red"))
#' \dontrun{
#' print(cf)
#' }
#'
#' condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' cf <- condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' rule_fill_discrete(c(starts_with("Sepal"), starts_with("Petal")),
#' expression = Sepal.Length > 4.6,
#' colours=c("TRUE"="red"))
#' \dontrun{
#' print(cf)
#' }
#' @export
rule_fill_discrete <- function(x, columns, expression, colours = NA,
na.value = "#FFFFFF",
Expand Down
10 changes: 8 additions & 2 deletions R/rule_fill_gradient.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@
#' @return The condformat_tbl object, with the added formatting information
#' @examples
#' data(iris)
#' condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' cf <- condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' rule_fill_gradient(Sepal.Length) %>%
#' rule_fill_gradient(Species, expression=Sepal.Length - Sepal.Width)
#' \dontrun{
#' print(cf)
#' }
#'
#' condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' cf <- condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' rule_fill_gradient("Petal.Length") %>%
#' rule_fill_gradient(starts_with("Sepal"), expression=Sepal.Length - Sepal.Width)
#' \dontrun{
#' print(cf)
#' }
#'
#' @export
rule_fill_gradient <- function(x, columns, expression,
Expand Down
10 changes: 8 additions & 2 deletions R/rule_fill_gradient2.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@
#' @return The condformat_tbl object, with the added formatting information
#' @examples
#' data(iris)
#' condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' cf <- condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' rule_fill_gradient2(Sepal.Length) %>%
#' rule_fill_gradient2(Species, expression=Sepal.Length - Sepal.Width)
#' \dontrun{
#' print(cf)
#' }
#'
#' condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' cf <- condformat(iris[c(1:5, 70:75, 120:125), ]) %>%
#' rule_fill_gradient2("Petal.Length") %>%
#' rule_fill_gradient2(starts_with("Sepal"), expression=Sepal.Length - Sepal.Width)
#' \dontrun{
#' print(cf)
#' }
#'
#' @importFrom scales rescale_mid
#' @export
Expand Down
5 changes: 4 additions & 1 deletion R/rule_text_bold.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
#' @param na.bold If `TRUE`, make missing values bold.
#' @examples
#' data(iris)
#' condformat(iris[c(1:5, 51:55, 101:105),]) %>%
#' cf <- condformat(iris[c(1:5, 51:55, 101:105),]) %>%
#' rule_text_bold(Species, expression = Species == "setosa")
#' \dontrun{
#' print(cf)
#' }
#' @export
rule_text_bold <- function(x, columns, expression,
na.bold = FALSE,
Expand Down
5 changes: 4 additions & 1 deletion R/rule_text_color.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
#' @param na.color Color for missing values
#' @examples
#' data(iris)
#' condformat(iris[c(1:5, 51:55, 101:105),]) %>%
#' cf <- condformat(iris[c(1:5, 51:55, 101:105),]) %>%
#' rule_text_color(Species, expression = ifelse(Species == "setosa", "blue", ""))
#' \dontrun{
#' print(cf)
#' }
#' @export
rule_text_color <- function(x, columns, expression,
na.color = "",
Expand Down
30 changes: 24 additions & 6 deletions R/show_columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,39 @@
#' x <- head(iris)
#'
#' # Include some columns:
#' condformat(x) %>% show_columns(c(Sepal.Length, Sepal.Width, Species))
#' condformat(x) %>% show_columns(c("Sepal.Length", "Sepal.Width", "Species"))
#' cf <- condformat(x) %>% show_columns(c(Sepal.Length, Sepal.Width, Species))
#' \dontrun{
#' print(cf)
#' }
#' cf <- condformat(x) %>% show_columns(c("Sepal.Length", "Sepal.Width", "Species"))
#' \dontrun{
#' print(cf)
#' }
#'
#' # Rename columns:
#' condformat(x) %>%
#' cf <- condformat(x) %>%
#' show_columns(c(Sepal.Length, Species),
#' col_names = c("Length", "Spec."))
#' \dontrun{
#' print(cf)
#' }
#'
#' # Exclude some columns:
#' condformat(x) %>% show_columns(c(-Petal.Length, -Petal.Width))
#' cf <- condformat(x) %>% show_columns(c(-Petal.Length, -Petal.Width))
#' \dontrun{
#' print(cf)
#' }
#'
#' condformat(x) %>% show_columns(c(starts_with("Petal"), Species))
#' cf <- condformat(x) %>% show_columns(c(starts_with("Petal"), Species))
#' \dontrun{
#' print(cf)
#' }
#'
#' petal_width <- "Petal.Width"
#' condformat(x) %>% show_columns(!! petal_width)
#' cf <- condformat(x) %>% show_columns(!! petal_width)
#' \dontrun{
#' print(cf)
#' }
#'
#' @export
#' @seealso \code{\link[dplyr]{select}}
Expand Down
15 changes: 12 additions & 3 deletions R/show_rows.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@
#' library(condformat)
#' data(iris)
#' x <- head(iris)
#' condformat(x) %>% show_rows(Sepal.Length > 4.5, Species == "setosa")
#' cf <- condformat(x) %>% show_rows(Sepal.Length > 4.5, Species == "setosa")
#' \dontrun{
#' print(cf)
#' }
#' # Use it programatically
#' expr_as_text <- 'Sepal.Length > 4.5'
#' expr <- rlang::parse_expr(expr_as_text)
#' condformat(x) %>% show_rows(!! expr)
#' cf <- condformat(x) %>% show_rows(!! expr)
#' \dontrun{
#' print(cf)
#' }
#' # With multiple arguments:
#' expr_as_text <- c('Sepal.Length > 4.5', 'Species == "setosa"')
#' exprs <- lapply(expr_as_text, rlang::parse_expr)
#' condformat(x) %>% show_rows(!!! exprs)
#' cf <- condformat(x) %>% show_rows(!!! exprs)
#' \dontrun{
#' print(cf)
#' }
#' @export
#' @seealso \code{\link[dplyr]{filter}}
show_rows <- function(x, ...) {
Expand Down
5 changes: 4 additions & 1 deletion R/theme_caption.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#' @param caption The caption to show
#' @examples
#' data(iris)
#' condformat(head(iris)) %>%
#' cf <- condformat(head(iris)) %>%
#' theme_caption(caption = "My Caption")
#' \dontrun{
#' print(cf)
#' }
#' @export
theme_caption <- function(x, caption = "") {
if (!inherits(x, "condformat_tbl")) {
Expand Down
5 changes: 4 additions & 1 deletion R/theme_grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#' @seealso \code{\link[gridExtra]{tableGrob}}
#' @examples
#' data(iris)
#' condformat(head(iris)) %>%
#' cf <- condformat(head(iris)) %>%
#' theme_grob(base_size = 10, base_colour = "red")
#' \dontrun{
#' print(cf)
#' }
#' @export
theme_grob <- function(x, ...) {
if (!inherits(x, "condformat_tbl")) {
Expand Down
6 changes: 5 additions & 1 deletion R/theme_htmlTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#' @seealso \code{\link[htmlTable]{htmlTable}}
#' @examples
#' data(iris)
#' condformat(head(iris)) %>% theme_htmlTable(caption="Table 1: My iris table", rnames=FALSE)
#' cf <- condformat(head(iris)) %>%
#' theme_htmlTable(caption="Table 1: My iris table", rnames=FALSE)
#' \dontrun{
#' print(cf)
#' }
#' @export
theme_htmlTable <- function(x, ...) {
if (!inherits(x, "condformat_tbl")) {
Expand Down
5 changes: 4 additions & 1 deletion R/theme_htmlWidget.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#' @seealso \code{\link[htmlTable]{htmlTable}}
#' @examples
#' data(iris)
#' condformat(head(iris)) %>%
#' cf <- condformat(head(iris)) %>%
#' theme_htmlWidget(number_of_entries = c(10, 25, 100),
#' width = NULL, height = NULL, elementId = NULL)
#' \dontrun{
#' print(cf)
#' }
#' @export
theme_htmlWidget <- function(x, ...) {
if (!inherits(x, "condformat_tbl")) {
Expand Down
5 changes: 4 additions & 1 deletion R/theme_kable.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#' @seealso \code{\link[knitr]{kable}}
#' @examples
#' data(iris)
#' condformat(head(iris)) %>%
#' cf <- condformat(head(iris)) %>%
#' theme_kable(booktabs = TRUE, caption = "My Caption")
#' \dontrun{
#' print(cf)
#' }
#' @export
theme_kable <- function(x, ...) {
if (!inherits(x, "condformat_tbl")) {
Expand Down
15 changes: 12 additions & 3 deletions man/condformat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/condformat2html.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/condformat2widget.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/print.condformat_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/rule_css.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6cb3380

Please sign in to comment.