Skip to content

Commit

Permalink
Merge pull request #212 from Merck/gha
Browse files Browse the repository at this point in the history
Update GitHub Actions workflows to upstream latest versions
  • Loading branch information
nanxstats committed Feb 8, 2024
2 parents b3378df + f808ad1 commit c55513d
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -41,7 +41,7 @@ jobs:

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
shell: Rscript {0}

- name: Cache styler
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.styler-location.outputs.location }}
key: ${{ runner.os }}-styler-${{ github.sha }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
Expand All @@ -31,7 +31,7 @@ jobs:
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
shell: Rscript {0}

Expand All @@ -44,7 +44,7 @@ jobs:

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
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")
30 changes: 13 additions & 17 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)
svg(tempfile("tmp.svg"))
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 All @@ -136,5 +134,3 @@ test_that("Test when using subline_by and page_by with pageby_row = 'first_row'

expect_snapshot_output(tbl2$body)
})

dev.off()
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
42 changes: 21 additions & 21 deletions tests/testthat/test-independent-testing-assemble.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ test_that("rtf_assemble: output without using officer", {
})

# test functionality with officer
if (requireNamespace("officer")) {
test_that("rtf_assemble: output with using officer", {
file_tmp <- tempfile(fileext = ".docx")
rtf_path <- assemble_docx(
input = file,
output = file_tmp,
landscape = c(FALSE, TRUE)
)
test_that("rtf_assemble: output with using officer", {
skip_if_not_installed("officer")

expect_equal(rtf_path, file_tmp)
file_tmp <- tempfile(fileext = ".docx")
rtf_path <- assemble_docx(
input = file,
output = file_tmp,
landscape = c(FALSE, TRUE)
)

expect_equal(rtf_path, file_tmp)

# Need to read in and expose document text for our test
docx <- officer::read_docx(rtf_path)
tmp_docx <- officer::docx_summary(docx)
body_docx <- officer::docx_body_xml(docx)
# Need to read in and expose document text for our test
docx <- officer::read_docx(rtf_path)
tmp_docx <- officer::docx_summary(docx)
body_docx <- officer::docx_body_xml(docx)

# Need to check if both "table seq table" texts are in the docx file.
expect_true(grepl("Table SEQ Table", tmp_docx$text[1]))
# Need to check if both "table seq table" texts are in the docx file.
expect_true(grepl("Table SEQ Table", tmp_docx$text[1]))

expect_equal(
unlist(lapply(xml2::as_list(xml2::xml_find_all(body_docx, "//w:pgSz")), FUN = function(x) attr(x, "orient"))),
c("portrait", "landscape")
)
})
}
expect_equal(
unlist(lapply(xml2::as_list(xml2::xml_find_all(body_docx, "//w:pgSz")), FUN = function(x) attr(x, "orient"))),
c("portrait", "landscape")
)
})
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
3 changes: 0 additions & 3 deletions tests/testthat/test-independent-testing-rtf_nrow.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# create testing example
svg(tempfile("tmp.svg"))

font <- 2:3
format <- matrix(c("", "i", "b", "ib"), nrow = 4, ncol = 2, byrow = FALSE)
Expand Down Expand Up @@ -174,5 +173,3 @@ test_that("test for rtf-nrow() if 'rtf-nrow' attributes are added correctly for
test_that("test for rtf-nrow() if 'rtf-nrow' attributes are added correctly for pageby_row table", {
expect_equal(irspagebyrows[1], 1)
})

dev.off()
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 c55513d

Please sign in to comment.