Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions R/figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ sbr_figures <- function(
transfer_files(plots, report = report, ext = "csv")
transfer_files(plots, report = report, ext = "yaml")
transfer_files(plots, report = report, ext = "xlsx")
transfer_files(plots, report = report, ext = "md")
plots <- transfer_files(plots, report = report, ext = "png")
}
colnames(windows)[1] <- "plots"
Expand Down
1 change: 1 addition & 0 deletions R/tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ sbr_tables <- function(
}

transfer_files(data, report = report, ext = "yaml")
transfer_files(data, report = report, ext = "md")
data <- write_files(data, report = report, ext = ".csv", fun = write_csv)

data <- sort_sub(data, sort = sort)
Expand Down
31 changes: 27 additions & 4 deletions tests/testthat/test-figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ test_that("figures", {
)
expect_identical(
sort(list.files(sbr_get_report(), recursive = TRUE)),
sort(c("plots/x.csv", "plots/x.png", "plots/x.xlsx", "plots/x.yaml"))
sort(c(
"plots/x.csv",
"plots/x.md",
"plots/x.png",
"plots/x.xlsx",
"plots/x.yaml"
))
)

skip("opens window")
Expand Down Expand Up @@ -153,7 +159,13 @@ test_that("figures pre_num", {
)
expect_identical(
sort(list.files(sbr_get_report(), recursive = TRUE)),
sort(c("plots/x.csv", "plots/x.png", "plots/x.xlsx", "plots/x.yaml"))
sort(c(
"plots/x.csv",
"plots/x.md",
"plots/x.png",
"plots/x.xlsx",
"plots/x.yaml"
))
)
txt <- sbr_figures()
expect_match(
Expand All @@ -162,7 +174,13 @@ test_that("figures pre_num", {
)
expect_identical(
sort(list.files(sbr_get_report(), recursive = TRUE)),
sort(c("plots/x.csv", "plots/x.png", "plots/x.xlsx", "plots/x.yaml"))
sort(c(
"plots/x.csv",
"plots/x.md",
"plots/x.png",
"plots/x.xlsx",
"plots/x.yaml"
))
)
})

Expand Down Expand Up @@ -221,7 +239,7 @@ test_that("sbr_figures() lists the correct file names in the md string.", {
))
})

test_that("figures copies yaml and xlsx to report folder", {
test_that("figures copies yaml, xlsx and md to report folder", {
withr::local_options(sbr.pre_num_fig = NULL)
path <- withr::local_tempdir()
subfoldr2::sbf_set_main(path, "output", rm = TRUE, ask = FALSE)
Expand All @@ -236,10 +254,15 @@ test_that("figures copies yaml and xlsx to report folder", {
main <- subfoldr2::sbf_get_main()
expect_true(file.exists(file.path(main, "plots/x.yaml")))
expect_true(file.exists(file.path(main, "plots/x.xlsx")))
expect_true(file.exists(file.path(main, "plots/x.md")))

sbr_figures()
report <- sbr_get_report()
expect_true(file.exists(file.path(report, "plots/x.png")))
expect_true(file.exists(file.path(report, "plots/x.yaml")))
expect_true(file.exists(file.path(report, "plots/x.xlsx")))
expect_identical(
readLines(file.path(report, "plots/x.md")),
readLines(file.path(main, "plots/x.md"))
)
})
58 changes: 48 additions & 10 deletions tests/testthat/test-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ test_that("tables", {
)
expect_identical(
list.files(sbr_get_report(), recursive = TRUE),
c("tables/x.csv", "tables/x.yaml")
c("tables/x.csv", "tables/x.md", "tables/x.yaml")
)

subfoldr2::sbf_save_table(x, x_name = "y", report = FALSE)
expect_identical(sbr_tables(pre_num = 0L), txt)
expect_identical(
list.files(sbr_get_report(), recursive = TRUE),
c("tables/x.csv", "tables/x.yaml")
c("tables/x.csv", "tables/x.md", "tables/x.yaml")
)

x_csv <- utils::read.csv(file.path(sbr_get_report(), "tables/x.csv"))
Expand Down Expand Up @@ -122,7 +122,7 @@ test_that("tables sub", {
)
expect_identical(
list.files(sbr_get_report(), recursive = TRUE),
c("tables/A sub/x.csv", "tables/A sub/x.yaml")
c("tables/A sub/x.csv", "tables/A sub/x.md", "tables/A sub/x.yaml")
)
})

Expand All @@ -143,7 +143,7 @@ test_that("tables missing caption", {
)
expect_identical(
list.files(sbr_get_report(), recursive = TRUE),
c("tables/x.csv", "tables/x.yaml")
c("tables/x.csv", "tables/x.md", "tables/x.yaml")
)
})

Expand All @@ -166,7 +166,14 @@ test_that("tables sort sub and name", {
)
expect_identical(
list.files(sbr_get_report(), recursive = TRUE),
c("tables/a.csv", "tables/a.yaml", "tables/b/a.csv", "tables/b/a.yaml")
c(
"tables/a.csv",
"tables/a.md",
"tables/a.yaml",
"tables/b/a.csv",
"tables/b/a.md",
"tables/b/a.yaml"
)
)

txt <- sbr_tables(sort = c("b", "a"), pre_num = 0L)
Expand All @@ -193,7 +200,7 @@ test_that("tables with []", {
)
expect_identical(
list.files(sbr_get_report(), recursive = TRUE),
c("tables/x.csv", "tables/x.yaml")
c("tables/x.csv", "tables/x.md", "tables/x.yaml")
)
})

Expand All @@ -218,8 +225,10 @@ test_that("tables copies yaml metadata to report folder", {
sort(list.files(sbr_get_report(), recursive = TRUE)),
sort(c(
"tables/x.csv",
"tables/x.md",
"tables/x.yaml",
"tables/A sub/y.csv",
"tables/A sub/y.md",
"tables/A sub/y.yaml"
))
)
Expand All @@ -242,7 +251,7 @@ test_that("tables pre_num", {
)
expect_identical(
sort(list.files(sbr_get_report(), recursive = TRUE)),
sort(c("tables/x.csv", "tables/x.yaml"))
sort(c("tables/x.csv", "tables/x.md", "tables/x.yaml"))
)
txt <- sbr_tables()
expect_identical(
Expand All @@ -251,7 +260,7 @@ test_that("tables pre_num", {
)
expect_identical(
sort(list.files(sbr_get_report(), recursive = TRUE)),
sort(c("tables/x.csv", "tables/x.yaml"))
sort(c("tables/x.csv", "tables/x.md", "tables/x.yaml"))
)
})

Expand All @@ -262,7 +271,12 @@ test_that("tables drop", {
sbr_set_report(path, "report", rm = TRUE, ask = FALSE)
sbf_reset_sub()

subfoldr2::sbf_save_table(data.frame(x = 1L), "x", sub = "a", caption = "Kept")
subfoldr2::sbf_save_table(
data.frame(x = 1L),
"x",
sub = "a",
caption = "Kept"
)
subfoldr2::sbf_save_table(
data.frame(x = 2L),
"x",
Expand All @@ -276,7 +290,31 @@ test_that("tables drop", {
)
expect_identical(
sort(list.files(sbr_get_report(), recursive = TRUE)),
sort(c("tables/a/x.csv", "tables/a/x.yaml"))
sort(c("tables/a/x.csv", "tables/a/x.md", "tables/a/x.yaml"))
)
expect_identical(sbr_tables(drop = c("a", "b")), character(0))
})

test_that("tables copies md files to report folder when they exist", {
withr::local_options(sbr.pre_num_tab = NULL)
path <- withr::local_tempdir()
subfoldr2::sbf_set_main(path, "output", rm = TRUE, ask = FALSE)
sbr_set_report(path, "report", rm = TRUE, ask = FALSE)
sbf_reset_sub()

x <- data.frame(estimate = 1.2345, lower = 0.9, upper = 1.6)
subfoldr2::sbf_save_table(x, caption = "Estimates")
withr::with_options(
list(sbf.save_md = FALSE),
subfoldr2::sbf_save_table(x, x_name = "y", caption = "No md")
)

sbr_tables()
report <- sbr_get_report()
expect_identical(
readLines(file.path(report, "tables/x.md")),
readLines(file.path(subfoldr2::sbf_get_main(), "tables/x.md"))
)
expect_false(file.exists(file.path(report, "tables/y.md")))
expect_true(file.exists(file.path(report, "tables/y.csv")))
})
Loading