Skip to content

Commit

Permalink
green ci (#313)
Browse files Browse the repository at this point in the history
close #312

---------

Signed-off-by: Joe Zhu <sha.joe.zhu@gmail.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Pawel Rucki <12943682+pawelru@users.noreply.github.com>
Co-authored-by: Davide Garolini <dgarolini@gmail.com>
  • Loading branch information
5 people committed Aug 28, 2024
1 parent 33e93a9 commit c0bf23f
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 47 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ Imports:
checkmate (>= 2.1.0),
grid,
htmltools (>= 0.5.3),
lifecycle (>= 0.2.0)
lifecycle (>= 0.2.0),
stringi (>= 1.7.12)
Suggests:
dplyr (>= 1.0.9),
gt (>= 0.10.0),
huxtable (>= 2.0.0),
knitr (>= 1.42),
r2rtf (>= 0.3.2),
rmarkdown (>= 2.23),
stringi (>= 1.6),
testthat (>= 3.0.4),
withr (>= 2.0.0)
VignetteBuilder:
knitr
knitr,
rmarkdown
Config/Needs/verdepcheck: mllg/checkmate, rstudio/htmltools,
r-lib/lifecycle, tidyverse/dplyr, rstudio/gt, hughjonesd/huxtable,
yihui/knitr, Merck/r2rtf, rstudio/rmarkdown, gagolews/stringi,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ importFrom(htmltools,tagList)
importFrom(htmltools,tags)
importFrom(lifecycle,deprecated)
importFrom(stats,na.omit)
importFrom(stringi,stri_detect)
importFrom(stringi,stri_replace)
importFrom(stringi,stri_sub)
importFrom(stringi,stri_wrap)
importFrom(tools,file_ext)
importFrom(utils,capture.output)
importFrom(utils,head)
Expand Down
1 change: 1 addition & 0 deletions R/matrix_form.R
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ mf_has_rlabels <- function(mf) ncol(mf$strings) > mf_ncol(mf)
#' mform <- basic_matrix_form(mtcars)
#' cat(toString(mform))
#'
#' @examplesIf require("dplyr")
#' # Advanced test case with label rows
#' library(dplyr)
#' iris_output <- iris %>%
Expand Down
1 change: 1 addition & 0 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
#' @importFrom lifecycle deprecated
#' @importFrom stats na.omit
#' @importFrom utils head tail localeToCharset
#' @importFrom stringi stri_detect stri_replace stri_wrap stri_sub
#' @import checkmate
NULL
3 changes: 2 additions & 1 deletion man/test_matrix_form.Rd

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

1 change: 0 additions & 1 deletion tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
library(dplyr)
make_basemf_fnotes <- function() {
dfmf <- basic_matrix_form(mtcars)
main_title(dfmf) <- "main title"
Expand Down
15 changes: 8 additions & 7 deletions tests/testthat/test-exporters.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ test_that("exporters work", {
)

## export_as_rtf rudimentary coverage
if (requireNamespace("r2rtf")) {
fil4 <- tempfile(fileext = ".rtf")
export_as_rtf(dfmf, file = fil4)
expect_true(file.exists(fil4))
if (file.exists("Rplots.pdf")) {
file.remove("Rplots.pdf") # coming probably from rtf::
}
skip_if_not_installed("r2rtf")

fil4 <- tempfile(fileext = ".rtf")
export_as_rtf(dfmf, file = fil4)
expect_true(file.exists(fil4))
if (file.exists("Rplots.pdf")) {
file.remove("Rplots.pdf") # coming probably from rtf::
}
})

Expand Down Expand Up @@ -214,6 +214,7 @@ test_that("exporting lists of tables and listings works", {
expect_true(file.exists(tmpf))
file.remove(tmpf)

skip_if_not_installed("r2rtf")
# export_as_rtf
tmpf <- tempfile(fileext = ".rtf")
output <- export_as_rtf(bmf, file = tmpf, page_num = "page {i} of {n}", cpp = 70)
Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/test-listings.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("basic_listing_mf respect core modifications from table matrix_form", {
skip_if_not_installed("dplyr")

mtcars_rn <- mtcars %>% dplyr::mutate("rnms" = rownames(mtcars))
expect_silent(lmf <- basic_listing_mf(mtcars_rn, keycols = c("vs", "gear")))

Expand Down Expand Up @@ -99,7 +101,7 @@ test_that("listings are correctly paginated when a wrapping happens on non-domin
)

expect_true(all(
sapply(pgs, function(x) strsplit(toString(x), "\n")[[1]] %>% length() <= 5)
sapply(pgs, function(x) length(strsplit(toString(x), "\n")[[1]]) <= 5)
))
expect_silent(sapply(pgs, function(x) toString(x)))

Expand Down Expand Up @@ -127,7 +129,9 @@ test_that("listings are correctly paginated when a wrapping happens on non-domin
pgs <- paginate_to_mpfs(lst, colwidths = c(30, 15, 12), lpp = 8)

expect_true(all(
sapply(pgs, function(x) strsplit(toString(x), "\n")[[1]] %>% length() <= 8)
sapply(pgs, function(x) {
length(strsplit(toString(x), "\n")[[1]]) <= 8
})
))
expect_silent(null <- sapply(pgs, function(x) toString(x)))
})
11 changes: 7 additions & 4 deletions tests/testthat/test-matrix_form.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
test_that("matrix_form works with and without indentation", {
iris_output <- iris %>%
group_by(Species) %>%
summarize("all obs" = round(mean(Petal.Length), 2)) %>%
mutate("Petal.Length" = "Mean")
skip_if_not_installed("dplyr")

iris_output <- dplyr::summarize(dplyr::group_by(iris, Species),
"all obs" = round(mean(Petal.Length), 2)
)
iris_output <- dplyr::mutate(iris_output, "Petal.Length" = "Mean")

mf <- basic_matrix_form(iris_output,
indent_rownames = TRUE,
split_labels = "Species", data_labels = "Petal.Length"
Expand Down
16 changes: 7 additions & 9 deletions tests/testthat/test-pagination.R
Original file line number Diff line number Diff line change
Expand Up @@ -436,21 +436,19 @@ test_that("rep_cols works as intended for listings and tables", {
expect_equal(num_rep_cols(bmf), 0L) # repeated rowlabels are excluded from num_rep_cols
expect_equal(num_rep_cols(blmf), 2L)

out <- export_as_txt(bmf, rep_cols = 2, cpp = 90) %>%
strsplit("\n") %>%
unlist()
strsplit_unlist <- function(x) {
unlist(strsplit(x, "\n"))
}

out <- strsplit_unlist(export_as_txt(bmf, rep_cols = 2, cpp = 90))
expect_true(grepl(out[35], pattern = "mpg")) # mpg is repeated
expect_true(grepl(out[35], pattern = "cyl")) # cyl is repeated

out <- export_as_txt(blmf, cpp = 70) %>%
strsplit("\n") %>%
unlist()
out <- strsplit_unlist(export_as_txt(blmf, cpp = 70))
expect_true(grepl(out[51], pattern = "vs")) # vs is repeated
expect_true(grepl(out[51], pattern = "gear")) # gear is repeated

out <- export_as_txt(blmf, rep_cols = 1, cpp = 70) %>%
strsplit("\n") %>%
unlist()
out <- strsplit_unlist(export_as_txt(blmf, rep_cols = 1, cpp = 70))
expect_true(grepl(out[51], pattern = "vs")) # vs is repeated
expect_false(grepl(out[51], pattern = "gear")) # gear is NOT repeated
})
47 changes: 27 additions & 20 deletions tests/testthat/test-print.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
test_that("toString works with and without indentation", {
skip_if_not_installed("dplyr")

set.seed(1)
iris_output <- iris %>%
mutate(my_cols = sample(c("A", "B", "C"), nrow(iris), replace = TRUE)) %>%
group_by(Species, my_cols) %>%
summarize("mean_petal_length" = round(mean(Petal.Length), 1), .groups = "drop") %>%
as.data.frame() %>%
reshape(
timevar = "my_cols",
idvar = "Species",
direction = "wide",
v.names = "mean_petal_length"
) %>%
# identical to tidyr::pivot_wider(names_from = my_cols, values_from = mean_petal_length) %>%
rename(
A = `mean_petal_length.A`,
B = `mean_petal_length.B`,
C = `mean_petal_length.C`
) %>%
mutate("Petal.Length" = "Mean")
iris <-
dplyr::mutate(iris, my_cols = sample(c("A", "B", "C"), nrow(iris), replace = TRUE))
iris_output <-
dplyr::summarize(dplyr::group_by(iris, Species, my_cols),
"mean_petal_length" = round(mean(Petal.Length), 1), .groups = "drop"
)
iris_output_df <- as.data.frame(iris_output)
iris_output_df <- reshape(
iris_output_df,
timevar = "my_cols",
idvar = "Species",
direction = "wide",
v.names = "mean_petal_length"
)
# identical to tidyr::pivot_wider(names_from = my_cols, values_from = mean_petal_length) %>%
iris_output_df <- dplyr::rename(
iris_output_df,
A = `mean_petal_length.A`,
B = `mean_petal_length.B`,
C = `mean_petal_length.C`
)

iris_output_df <- dplyr::mutate(iris_output_df, "Petal.Length" = "Mean")

mf <- basic_matrix_form(iris_output,
mf <- basic_matrix_form(iris_output_df,
indent_rownames = TRUE,
split_labels = "Species", data_labels = "Petal.Length"
)
mf_no_indent <- basic_matrix_form(iris_output,
mf_no_indent <- basic_matrix_form(iris_output_df,
indent_rownames = FALSE,
split_labels = "Species", data_labels = "Petal.Length"
)
Expand Down

0 comments on commit c0bf23f

Please sign in to comment.