Skip to content

Commit

Permalink
Qualify namespaces explicitly in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nanxstats committed Feb 7, 2024
1 parent dbb3c03 commit 7896111
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 49 deletions.
2 changes: 0 additions & 2 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
library(testthat)
library(dplyr)
library(r2rtf)
library(ggplot2)

test_check("r2rtf")
28 changes: 13 additions & 15 deletions tests/testthat/test-independent-testing-as_rtf_pageby.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library(dplyr)

test_that("Test for case when output has title, footnote and source", {
x <- iris[1:2, ] |>
rtf_title("Title") |>
Expand All @@ -21,13 +19,13 @@ test_that("Test the pageby rows are the last rows of a page", {
rtf_pageby(page_by = "Species", new_page = TRUE, pageby_header = FALSE)

y <- as.data.frame(attributes(as_rtf_pageby(x))) |>
group_by(info.id) |>
summarise_all(last) |>
mutate(row = substr(as.character(info.page), 1, 1))
dplyr::group_by(info.id) |>
dplyr::summarise_all(dplyr::last) |>
dplyr::mutate(row = substr(as.character(info.page), 1, 1))

z <- as.data.frame(table(x$Species)) |>
mutate(cu = cumsum(Freq))
z <- z |> mutate(cum = cu + as.numeric(rownames(z)))
dplyr::mutate(cu = cumsum(Freq))
z <- z |> dplyr::mutate(cum = cu + as.numeric(rownames(z)))

expect_equal(y$row, rownames(y))
expect_equal(y$info.index, z$cum)
Expand Down Expand Up @@ -66,8 +64,8 @@ test_that("Test if page_dict attribute is created for tbl", {

test_that("Test for more than one page_by var", {
x <- iris |>
mutate(cat = rep(1:5, 30)) |>
arrange(Species, cat) |>
dplyr::mutate(cat = rep(1:5, 30)) |>
dplyr::arrange(Species, cat) |>
rtf_page(nrow = 5) |>
rtf_body() |>
rtf_pageby(page_by = c("Species", "cat"), new_page = TRUE, pageby_header = TRUE)
Expand All @@ -92,8 +90,8 @@ test_that("Test if new_page is FALSE and group_by is NOT NULL", {
})

test_that("Test whether lines with '-----' were removed correctly", {
x <- distinct(iris |> subset(Species != "virginica"), Species, .keep_all = T) |>
mutate(Species = ifelse(Species == "setosa", "-----", Species)) |>
x <- dplyr::distinct(iris |> subset(Species != "virginica"), Species, .keep_all = TRUE) |>
dplyr::mutate(Species = ifelse(Species == "setosa", "-----", Species)) |>
rtf_colheader("Sepal.Length | Sepal.Width | Petal.Length | Petal.Width",
col_rel_width = rep(1, 4)
) |>
Expand All @@ -111,8 +109,8 @@ test_that("Test whether lines with '-----' were removed correctly", {

test_that("Test when using subline_by and page_by together in rtf_body", {
tbl1 <- iris[c(1:4, 51:54), 3:5] |>
mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
arrange(Species, s2) |>
dplyr::mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
dplyr::arrange(Species, s2) |>
rtf_body(
subline_by = "s2",
page_by = "Species"
Expand All @@ -125,8 +123,8 @@ test_that("Test when using subline_by and page_by together in rtf_body", {

test_that("Test when using subline_by and page_by with pageby_row = 'first_row' in rtf_body", {
tbl2 <- iris[c(1:4, 51:54), 3:5] |>
mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
arrange(Species, s2) |>
dplyr::mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
dplyr::arrange(Species, s2) |>
rtf_body(
subline_by = "s2",
page_by = "Species",
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-independent-testing-as_rtf_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ test_that("Case for having group_by without page_by", {
# add additional test to increase coverage and for new feature
test_that("Test case when subline is not NULL", {
x <- iris[c(1:4, 51:54), 3:5] |>
mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
arrange(Species, s2) |>
dplyr::mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
dplyr::arrange(Species, s2) |>
rtf_body(
subline_by = "Species",
page_by = "s2",
Expand All @@ -45,18 +45,18 @@ test_that("Test case when subline is not NULL", {

data(r2rtf_adae)
ae <- r2rtf_adae[200:260, ] |>
arrange(SITEID, TRTA, USUBJID, ASTDY)
dplyr::arrange(SITEID, TRTA, USUBJID, ASTDY)

ae <- ae |>
mutate(
dplyr::mutate(
AEDECODNUM = as.character(rownames(ae)),
SUBLINEBY = paste0(
"Trial Number: ", STUDYID,
", Site Number: ", SITEID
),
) |>
select(USUBJID, ASTDY, AEDECODNUM, TRTA, SUBLINEBY) |>
arrange(SUBLINEBY, TRTA, USUBJID, ASTDY) |>
dplyr::select(USUBJID, ASTDY, AEDECODNUM, TRTA, SUBLINEBY) |>
dplyr::arrange(SUBLINEBY, TRTA, USUBJID, ASTDY) |>
rtf_colheader("Subject| Rel Day | Adverse Code|") |>
rtf_body(
subline_by = "SUBLINEBY",
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-independent-testing-rtf_body.R
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ test_that("Case for page_by", {

test_that("Case for using subline_by and page_by together", {
tbl1 <- iris[c(1:4, 51:54), 3:5] |>
mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
arrange(Species, s2) |>
dplyr::mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
dplyr::arrange(Species, s2) |>
rtf_body(
subline_by = "Species",
page_by = "s2"
Expand Down Expand Up @@ -382,8 +382,8 @@ test_that("Case for using subline_by and page_by together", {

test_that("Case for using subline_by and page_by with pageby_row = 'first_row'", {
tbl2 <- iris[c(1:4, 51:54), 3:5] |>
mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
arrange(Species, s2) |>
dplyr::mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
dplyr::arrange(Species, s2) |>
rtf_body(
subline_by = "Species",
page_by = "s2",
Expand Down
26 changes: 13 additions & 13 deletions tests/testthat/test-independent-testing-rtf_encode_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ test_that("Test case when pageby$border_color_last is not NULL", {

test_that("Test case when subline is not NULL", {
ir3 <- iris[c(1:4, 51:54), 3:5] |>
mutate(s2 = paste0(Species, 1:2)) |>
arrange(Species, s2) |>
dplyr::mutate(s2 = paste0(Species, 1:2)) |>
dplyr::arrange(Species, s2) |>
rtf_colheader("patelLength|patelWidth|s2") |>
rtf_body(subline_by = "Species")

Expand All @@ -243,8 +243,8 @@ test_that("Test case when subline is not NULL", {

test_that("Test case when subline is not NULL and verbose equals to TRUE", {
ir3 <- iris[c(1:4, 51:54), 3:5] |>
mutate(s2 = paste0(Species, 1:2)) |>
arrange(Species, s2) |>
dplyr::mutate(s2 = paste0(Species, 1:2)) |>
dplyr::arrange(Species, s2) |>
rtf_colheader("patelLength|patelWidth|s2") |>
rtf_body(subline_by = "Species")

Expand All @@ -256,14 +256,14 @@ test_that("Test case when subline is not NULL and verbose equals to TRUE", {
test_that("Test case when using subline_by, page_by, group_by simultaneously in rtf_body", {
data(r2rtf_adae)
ae_t1 <- r2rtf_adae[200:260, ] |>
mutate(
dplyr::mutate(
SUBLINEBY = paste0(
"Trial Number: ", STUDYID,
", Site Number: ", SITEID
),
) |>
select(USUBJID, ASTDY, AEDECOD, TRTA, SUBLINEBY) |>
arrange(SUBLINEBY, TRTA, USUBJID, ASTDY) |>
dplyr::select(USUBJID, ASTDY, AEDECOD, TRTA, SUBLINEBY) |>
dplyr::arrange(SUBLINEBY, TRTA, USUBJID, ASTDY) |>
rtf_colheader("Subject| Rel Day | Adverse |") |>
rtf_body(
subline_by = "SUBLINEBY",
Expand All @@ -281,14 +281,14 @@ test_that("Test case when using subline_by, page_by, group_by simultaneously wit
data(r2rtf_adae)
ae_t2 <- r2rtf_adae[200:260, ] |>
subset(USUBJID != "01-701-1442") |>
mutate(
dplyr::mutate(
SUBLINEBY = paste0(
"Trial Number: ", STUDYID,
", Site Number: ", SITEID
),
) |>
select(USUBJID, ASTDY, AEDECOD, TRTA, SUBLINEBY) |>
arrange(SUBLINEBY, TRTA, USUBJID, ASTDY) |>
dplyr::select(USUBJID, ASTDY, AEDECOD, TRTA, SUBLINEBY) |>
dplyr::arrange(SUBLINEBY, TRTA, USUBJID, ASTDY) |>
rtf_colheader("Subject| Rel Day | Adverse |",
border_bottom = "single"
) |>
Expand All @@ -309,14 +309,14 @@ test_that("Test case when using subline_by, page_by, group_by simultaneously wit
data(r2rtf_adae)
ae_t3 <- r2rtf_adae[200:260, ] |>
subset(USUBJID != "01-701-1442") |>
mutate(
dplyr::mutate(
SUBLINEBY = paste0(
"Trial Number: ", STUDYID,
", Site Number: ", SITEID
),
) |>
select(USUBJID, ASTDY, AEDECOD, TRTA, SUBLINEBY) |>
arrange(SUBLINEBY, TRTA, USUBJID, ASTDY) |>
dplyr::select(USUBJID, ASTDY, AEDECOD, TRTA, SUBLINEBY) |>
dplyr::arrange(SUBLINEBY, TRTA, USUBJID, ASTDY) |>
rtf_colheader("Subject| Rel Day | Adverse |",
border_bottom = "single"
) |>
Expand Down
14 changes: 6 additions & 8 deletions tests/testthat/test-independent-testing-rtf_pageby.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library(dplyr)

test_that("Test case when page_by is NULL and new_page is TRUE", {
expect_error(iris[1:2, ] |>
rtf_body() |>
Expand All @@ -8,15 +6,15 @@ test_that("Test case when page_by is NULL and new_page is TRUE", {

test_that("Test case when page_by is not NULL and data is sorted by the page_by variable", {
expect_output(str(iris[1:2, ] |>
arrange(Petal.Length) |>
dplyr::arrange(Petal.Length) |>
rtf_body() |>
rtf_pageby(
page_by = c("Petal.Length"), new_page = TRUE,
pageby_header = TRUE
)), "2 obs")

a <- iris[1:2, ] |>
arrange(Sepal.Width) |>
dplyr::arrange(Sepal.Width) |>
rtf_body() |>
rtf_pageby(
page_by = c("Sepal.Width"), new_page = TRUE,
Expand Down Expand Up @@ -60,8 +58,8 @@ test_that("Test if there are more than one page_by variables", {
# add tests for new features
test_that("Test case when pageby_row='first_row'", {
x <- iris[c(1:4, 51:54), 3:5] |>
mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
arrange(Species, s2) |>
dplyr::mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
dplyr::arrange(Species, s2) |>
rtf_colheader("patelLength|patelWidth|s3") |>
rtf_body(subline_by = "Species") |>
rtf_pageby(
Expand All @@ -78,8 +76,8 @@ test_that("Test case when pageby_row='first_row'", {

test_that("Test case when subline is not NULL", {
x <- iris[c(1:4, 51:54), 3:5] |>
mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
arrange(Species, s2) |>
dplyr::mutate(s2 = paste0(Species, 1:2), s3 = s2) |>
dplyr::arrange(Species, s2) |>
rtf_colheader("patelLength|patelWidth|s3") |>
rtf_body(subline_by = "Species") |>
rtf_pageby(
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-independent-testing-rtf_read_figure.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
library(dplyr)
test_that("Test fig_format attribute", {
a <- rtf_read_figure(c("fig/fig3.jpeg", "fig/fig2.png", "fig/fig4.emf"))

Expand Down

0 comments on commit 7896111

Please sign in to comment.