Skip to content

Commit

Permalink
First draft of render_lg_table test; update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sbreitbart-NOAA committed Feb 6, 2025
1 parent e7ee67d commit 625a669
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 6 deletions.
7 changes: 3 additions & 4 deletions R/render_lg_table.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Split an extra-wide table into mulitple tables
#' Split an extra-wide table into multiple tables
#'
#' @param report_flextable The extra-wide flextable.
#' @param essential_columns The columns that will be retained between the split
Expand Down Expand Up @@ -68,14 +68,13 @@ render_lg_table <- function(report_flextable = NULL,
init_col <- 1
end_col <- init_col + goal_cols_per_table

} else if ((i < num_tables) &
((init_col + goal_cols_per_table) <= total_cols)){
} else if ((i < num_tables) & (init_col < total_cols)){

# subtracting essential_cols so the first cols will be the essential ones
# and the total cols will still = goal_cols_per_table
end_col <- init_col + goal_cols_per_table - length(essential_cols)

} else if (i == num_tables){
} else {

end_col <- total_cols

Expand Down
4 changes: 2 additions & 2 deletions man/render_lg_table.Rd

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

Empty file.
105 changes: 105 additions & 0 deletions tests/testthat/test-render_lg_table.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
test_that("accurate number of split tables identified", {

# make very wide table
ft <- as.data.frame(faithful) |>
t() |>
as.data.frame() |>
dplyr::select(1:50) |>
flextable::flextable()

dir.create("rda_files")

# 0 essential columns
tables_test1 <- render_lg_table(ft,
essential_columns = 0,
rda_dir = getwd(),
plot_name = "test_plot1.rda")

expect_equal(tables_test1, 5)

# 2 essential columns
tables_test2 <- render_lg_table(ft,
essential_columns = 1:2,
rda_dir = getwd(),
plot_name = "test_plot2.rda")

expect_equal(tables_test2, 5)



# make very very wide table
ft <- as.data.frame(faithful) |>
t() |>
as.data.frame() |>
dplyr::select(1:70) |>
flextable::flextable()

# 0 essential columns
tables_test3 <- render_lg_table(ft,
essential_columns = 0,
rda_dir = getwd(),
plot_name = "test_plot3.rda")

expect_equal(tables_test3, 7)

# 3 essential columns
tables_test4 <- render_lg_table(ft,
essential_columns = 1:3,
rda_dir = getwd(),
plot_name = "test_plot4.rda")

expect_equal(tables_test4, 7)


# make slightly wide table
ft <- as.data.frame(faithful) |>
t() |>
as.data.frame() |>
dplyr::select(1:20) |>
flextable::flextable()

# 0 essential columns
tables_test5 <- render_lg_table(ft,
essential_columns = 0,
rda_dir = getwd(),
plot_name = "test_plot5.rda")

expect_equal(tables_test5, 2)

# 3 essential columns
tables_test6 <- render_lg_table(ft,
essential_columns = 1:3,
rda_dir = getwd(),
plot_name = "test_plot6.rda")

expect_equal(tables_test6, 2)

# erase temporary testing files
unlink(fs::path(getwd(), "rda_files"), recursive = T)

})

test_that("table_list saved as an rda", {

# make very wide table
ft <- as.data.frame(faithful) |>
t() |>
as.data.frame() |>
dplyr::select(1:50) |>
flextable::flextable()

dir.create("rda_files")

render_lg_table(ft,
essential_columns = 0,
rda_dir = getwd(),
plot_name = "test_plot1.rda")

expect_true(file.exists(fs::path(getwd(),
"rda_files",
"test_plot1_split.rda")))

# erase temporary testing files
unlink(fs::path(getwd(), "rda_files"), recursive = T)

})

0 comments on commit 625a669

Please sign in to comment.