Skip to content

Commit

Permalink
Show cols issue #318
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosak01 committed Mar 19, 2024
1 parent 59d550c commit d54038c
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 14 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Fixed bug on continuous table outside borders.
* Fixed bug with early page break when appending content dynamically.
* Fixed bug on page numbers in title for RTF.
* Fixed bug where show_cols was overriding `define()` visible = FALSE.

# reporter 1.4.3

Expand Down
8 changes: 6 additions & 2 deletions R/sizing_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,12 @@ get_table_cols <- function(x, control_cols) {

if (show_all == FALSE & def$visible)
ret[length(ret) + 1] <- def$var_c
else if (show_all == TRUE & def$visible == FALSE)
ret <- ret[!ret %in% def$var_c]
#else if (show_all == TRUE & def$visible == FALSE)
else if (def$visible == FALSE) {
if (def$var_c %in% ret) {
ret <- ret[!ret %in% def$var_c]
}
}
}

ret <- unique(ret)
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/reporter-wrap.html

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

Binary file modified docs/man/images/e6a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/man/images/e6b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ articles:
reporter-title_header: reporter-title_header.html
reporter-wrap: reporter-wrap.html
reporter: reporter.html
last_built: 2024-03-17T02:50Z
last_built: 2024-03-19T16:59Z
urls:
reference: https://reporter.r-sassy.org/reference
article: https://reporter.r-sassy.org/articles
Expand Down
Binary file modified man/images/e6a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/images/e6b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions tests/testthat/test-pdf2.R
Original file line number Diff line number Diff line change
Expand Up @@ -2964,6 +2964,103 @@ test_that("pdf2-78: Page by with wrap works as expected.", {

})

# Failing right now. Reminder to fix wrap.rmd
test_that("pdf2-79: show_cols does not override define", {

if (dev) {

# Create temp file name
fp <- file.path(base_path, "pdf2/test79.pdf")

# Prepare data
dat <- mtcars[1:10, ]
dat <- data.frame(vehicle = rownames(dat), dat)

# Define table
tbl <- create_table(dat, show_cols = 1:8) |>
define(vehicle, label = "Vehicle", width = 3, id_var = TRUE, align = "left") |>
define(mpg, label = "Miles per Gallon", width = 1) |>
define(cyl, label = "Cylinders", format = "%.1f") |>
define(disp, label = "Displacement") |>
define(hp, label = "Horsepower", page_wrap = TRUE) |>
define(drat, visible = FALSE) |>
define(wt, label = "Weight") |>
define(qsec, label = "Quarter Mile Time", width = 1.5)


# Create the report
rpt <- create_report(fp, output_type = "PDF",
font = "Courier", font_size = 12) |>
titles("Listing 2.0", "MTCARS Data Listing with Page Wrap") |>
set_margins(top = 1, bottom = 1) |>
add_content(tbl) |>
page_footer(right = "Page [pg] of [tpg]")

# Write the report
res <- write_report(rpt)


expect_equal(file.exists(fp), TRUE)
expect_equal(res$pages, 2)
expect_equal(length(res$column_widths[[1]]), 7)
expect_equal("drat" %in% names(res$column_widths[[1]]), FALSE)

} else {

expect_equal(TRUE, TRUE)
}

})

test_that("pdf2-80: spanning header works on show_cols none and defined cols", {

if (dev) {

# Create temp file name
fp <- file.path(base_path, "pdf2/test80.pdf")

# Prepare data
dat <- mtcars[1:10, ]
dat <- data.frame(vehicle = rownames(dat), dat)

# Define table
tbl <- create_table(dat, show_cols = "none") |>
spanning_header(mpg, qsec, label = "fork") |>
column_defaults(from = mpg, to = qsec, width = 1) |>
define(vehicle, label = "Vehicle", width = 3, id_var = TRUE, align = "left") |>
define(mpg, label = "Miles per Gallon", width = 1) |>
define(cyl, label = "Cylinders", format = "%.1f") |>
define(disp, label = "Displacement", width = 1.25) |>
define(hp, label = "Horsepower", page_wrap = TRUE) |>
define(drat, visible = FALSE) |>
define(wt, label = "Weight") |>
define(qsec, label = "Quarter Mile Time", width = 1.5)


# Create the report
rpt <- create_report(fp, output_type = "PDF",
font = "Courier", font_size = 12) |>
titles("Listing 2.0", "MTCARS Data Listing with Page Wrap") |>
set_margins(top = 1, bottom = 1) |>
add_content(tbl) |>
page_footer(right = "Page [pg] of [tpg]")

# Write the report
res <- write_report(rpt)


expect_equal(file.exists(fp), TRUE)
expect_equal(res$pages, 2)
expect_equal(length(res$column_widths[[1]]), 7)
expect_equal("drat" %in% names(res$column_widths[[1]]), FALSE)

} else {

expect_equal(TRUE, TRUE)
}

})




Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-rtf2.R
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,7 @@ test_that("rtf2-80: Two tables one continuous works as expected.", {
# file.show(res$modified_path)

expect_equal(file.exists(fp), TRUE)
expect_equal(res$pages, 7)
expect_equal(res$pages, 6)


} else {
Expand Down Expand Up @@ -3476,7 +3476,7 @@ test_that("rtf2-97: Page X of Y works as expected.", {
res <- write_report(rpt)

expect_equal(file.exists(fp), TRUE)
expect_equal(res$pages, 8)
expect_equal(res$pages, 11)

} else
expect_equal(TRUE, TRUE)
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-system.R
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ test_that("test19: show_cols 'none' parameter on table works as expected.", {
tbl <- create_table(mtcars[1:10, ], show_cols = "none") %>%
define(mpg) %>%
define(cyl) %>%
define(vs)
define(vs) %>%
define(drat, visible = FALSE)

rpt <- create_report(fp) %>%
titles("MTCARS Data Frame", align = "left") %>%
Expand All @@ -750,9 +751,10 @@ test_that("test20: show_cols 'some' parameter on table works as expected.", {
fp <- file.path(base_path, "output/test20.out")

tbl <- create_table(mtcars[1:10, ],
show_cols = c("vs", "mpg", "cyl", "disp")) %>%
show_cols = c("vs", "mpg", "cyl", "disp", "drat")) %>%
define(mpg, label = "Miles Per Gallon") %>%
define(vs, label = "")
define(vs, label = "") %>%
define(drat, visible = FALSE)


rpt <- create_report(fp) %>%
Expand Down
2 changes: 1 addition & 1 deletion vignettes/reporter-wrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ knitr::opts_chunk$set(
# define(cyl, label = "Cylinders", format = "%.1f") %>%
# define(disp, label = "Displacement") %>%
# define(hp, label = "Horsepower", page_wrap = TRUE) %>%
# define(drat) %>%
# define(drat, visible = FALSE) %>%
# define(wt, label = "Weight") %>%
# define(qsec, label = "Quarter Mile Time", width = 1.5)
#
Expand Down
2 changes: 1 addition & 1 deletion vignettes/reporter-wrap.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tbl <- create_table(dat, show_cols = 1:8) %>%
define(cyl, label = "Cylinders", format = "%.1f") %>%
define(disp, label = "Displacement") %>%
define(hp, label = "Horsepower", page_wrap = TRUE) %>%
define(drat) %>%
define(drat, visible = FALSE) %>%
define(wt, label = "Weight") %>%
define(qsec, label = "Quarter Mile Time", width = 1.5)
Expand Down
6 changes: 3 additions & 3 deletions vignettes/reporter-wrap.html

Large diffs are not rendered by default.

0 comments on commit d54038c

Please sign in to comment.