-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
708f302
commit f008367
Showing
3 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: flextable | ||
Type: Package | ||
Title: Functions for Tabular Reporting | ||
Version: 0.9.6.001 | ||
Version: 0.9.6.002 | ||
Authors@R: c( | ||
person("David", "Gohel", role = c("aut", "cre"), | ||
email = "[email protected]"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
title: "use printers" | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
library(knitr) | ||
opts_chunk$set(echo = FALSE) | ||
library(flextable) | ||
use_model_printer() | ||
use_df_printer() | ||
``` | ||
|
||
# a model | ||
|
||
```{r} | ||
clotting <- data.frame( | ||
u = c(5,10,15,20,30,40,60,80,100), | ||
lot1 = c(118,58,42,35,27,25,21,19,18), | ||
lot2 = c(69,35,26,21,18,16,13,12,12)) | ||
model <- glm(lot1 ~ log(u), data = clotting, family = Gamma) | ||
model | ||
``` | ||
|
||
# no stars | ||
|
||
```{r} | ||
options(show.signif.stars = FALSE) | ||
model | ||
``` | ||
|
||
## example 2 | ||
|
||
```{r} | ||
airquality | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,33 @@ | ||
context("df_printer and utilities") | ||
|
||
test_that("use_model_printer and use_df_printer works", { | ||
expect_silent(use_model_printer()) | ||
expect_silent(use_df_printer()) | ||
rmd_file <- tempfile(fileext = ".Rmd") | ||
file.copy("rmd/use-printer.Rmd", rmd_file) | ||
outfile <- tempfile(fileext = ".html") | ||
rmarkdown::render(rmd_file, | ||
output_file = outfile, output_format = "html_document", | ||
envir = new.env(), quiet = TRUE | ||
) | ||
|
||
doc <- read_html(outfile) | ||
table_nodes <- xml_find_all(doc, "body//*/table") | ||
testthat::expect_length(table_nodes, n = 3) | ||
|
||
# check last table that should be a summary table | ||
table_node_3 <- table_nodes[[3]] | ||
expect_length(xml_children(xml_child(table_node_3, search = "/thead")), 2) | ||
expect_length(xml_children(xml_child(table_node_3, search = "/tbody")), 10) | ||
|
||
tfoot_content <- xml_child(table_node_3, search = "/tfoot") | ||
expect_length(xml_children(tfoot_content), 1) | ||
expect_equal(xml_text(tfoot_content), "n: 153") | ||
|
||
# check first table and last column should have stars | ||
first_tr <- xml_find_first(doc, "//table/tbody/tr") | ||
expect_length(xml_children(first_tr), 6) | ||
expect_equal(xml_text(xml_child(first_tr, 6)), "***") | ||
|
||
# check second table has 5 columns | ||
first_tr <- xml_find_first(doc, "//*[@id='no-stars']//table/tbody/tr") | ||
expect_length(xml_children(first_tr), 5) | ||
}) |