Skip to content

Commit

Permalink
Merge branch 'develop' into visc_git_ignore_dataspec_html
Browse files Browse the repository at this point in the history
  • Loading branch information
slager committed Jan 8, 2025
2 parents ad9c007 + 8aacbf7 commit 01a8b2e
Show file tree
Hide file tree
Showing 25 changed files with 311 additions and 40 deletions.
1 change: 0 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: '4.0.4', pandoc-version: '2.11.4'}

env:
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master, develop]
pull_request:
branches: [main, master, develop]

name: test-coverage.yaml

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

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

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

- name: Preinstall required latex packages
run: >
tlmgr install
lastpage morefloats parskip pdflscape textpos multirow lipsum
fancyhdr colortbl soul setspace relsize makecell threeparttable
threeparttablex environ trimspaces
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: VISCtemplates
Title: Tools for writing reproducible reports at VISC
Version: 1.3.2
Version: 1.3.2.9000
Authors@R:
person(given = "Jimmy",
family = "Fulp",
Expand Down
17 changes: 16 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# VISCtemplates (development version)

Bug fixes
* Provide default CRAN mirror if missing in install_load_cran_packages(), e.g., in a child R session during knitting. Fixes 'trying to use CRAN without setting a mirror' error (#218)
* Update template.tex so that flextable package can be used to create tables in PDF documents (#226)
* Clean up invalid ORCID placeholder generated by usethis 3.0.0 that threw error on R version 4.5.x (#248)
* Fix error when running skeleton.Rmd file interactively (#249)
* Include pdata object name and data package name in visc_load_pdata() error message (#252)

Other improvements
* create_visc_project() now discards README.Rmd after knitting template to README.md (#223)
* Update PT report naming practices to the format VDCnnn_assay_PTreport_interim/final_(un)blinded.Rmd (#202)
* Add auxiliary files to template .gitignore (.aux, .toc, .lof, .lot, .out, cache files, and .smbdelete files) (#230)
* Update names in template acknowledgements section (#234)
* Include dataspec html in the files to ignore in use_visc_gitignore() (#254)

# VISCtemplates 1.3.2

Bug Fix
Expand Down Expand Up @@ -50,7 +66,6 @@ Package Maintenance
* Adjust dependencies in DESCRIPTION (#164)
* Update package authors and maintainer (#190)
* Clean up latex template code, removing commented-out code and reorganizing for better readability (#196)
* Include dataspec html in the files to ignore in use_visc_gitignore() (#254)

# VISCtemplates 1.2.0

Expand Down
10 changes: 9 additions & 1 deletion R/create_visc_project.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ create_visc_project <- function(path, interactive = TRUE){
usethis::create_package(
path = path,
rstudio = TRUE,
open = interactive
open = interactive,
# fields override for usethis 3.0.0 ORCID placeholder that errored in R 4.5
# https://github.com/r-lib/usethis/issues/2059
fields = list(
`Authors@R` = paste0(
"person(\"First\", \"Last\", email = \"first.last",
"@example.com\", role = c(\"aut\", \"cre\"))"
)
)
)

# must set active project otherwise it is <no active project>
Expand Down
5 changes: 4 additions & 1 deletion R/report_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ install_load_cran_packages <- function(packages) {
stop(paste0("The package ", package, " must be installed through GitHub:
https://github.com/FredHutch/", package, ".git"))
} else {
utils::install.packages(package)
# provide a default CRAN mirror if missing (e.g. in knitr R session)
repos <- getOption("repos")
if ("@CRAN@" %in% repos) repos <- "https://cloud.r-project.org/"
utils::install.packages(package, repos = repos)
# install.packages() installs packages from the repository identified in
# options('repos'), which is CRAN by default. To change this
# setting, edit your .Rprofile. To view a list of available CRAN
Expand Down
9 changes: 9 additions & 0 deletions R/use_visc_gitignore.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@ use_visc_gitignore <- function(directory = ".") {
"Thumbs.db",
# files from Latex
"*.log",
"*.aux",
"*.toc",
"*.lof",
"*.lot",
"*.out",
"**/figure-latex/*.pdf",
"**/figure-docx/*.pdf",
"*.zip",
"*dataspec*.html"
# cache files
"*_cache/",
# other
".smbdelete*"
),
directory = directory
)
Expand Down
45 changes: 30 additions & 15 deletions R/use_visc_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ use_visc_readme <- function(study_name, save_as = "README.Rmd") {
data = list(study_name = study_name),
package = "VISCtemplates"
)
# knit the md from the Rmd on request of SRA team
rmarkdown::render(
usethis::proj_path('README.Rmd'),
quiet = TRUE
)
# remove Rmd at request of SRA team; they just manually edit the *.md
# so the Rmd file merely clutters their working directory
unlink(
usethis::proj_path(
paste0(
'README',
c('.Rmd', '.html')
)
)
)
}

#' Create a VISC docs directory with template files
Expand Down Expand Up @@ -105,7 +120,7 @@ use_bib <- function(study_name) {
#'
#' @param report_name name of the file (character)
#' @param path path of the file within the active project
#' @param report_type "empty", "generic", "bama", or "nab"
#' @param report_type "empty", "generic", "bama", "nab", or "adcc"
#' @param interactive TRUE by default. FALSE is for non-interactive unit testing
#' only.
#'
Expand All @@ -119,20 +134,20 @@ use_bib <- function(study_name) {
#' report_type = "bama"
#' )
#' }
use_visc_report <- function(report_name = "PT-Report",
use_visc_report <- function(report_name = "PTreport",
path = ".",
report_type = c("empty", "generic", "bama", "nab"),
report_type = c("empty", "generic", "bama", "nab", "adcc"),
interactive = TRUE) {

stopifnot(report_type %in% c("empty", "generic", "bama", "nab"))
stopifnot(report_type %in% c("empty", "generic", "bama", "nab", "adcc"))

# suppress usethis output when non-interactive
old_usethis_quiet <- getOption('usethis.quiet')
on.exit(options(usethis.quiet = old_usethis_quiet))
options(usethis.quiet = ! interactive)
options(usethis.quiet = !interactive)

if (report_type != 'empty') challenge_visc_report(report_name, interactive)
if (! dir.exists(path)) dir.create(path, recursive = TRUE)
if (!dir.exists(path)) dir.create(path, recursive = TRUE)
use_template <- paste0(
'visc', '_', if (report_type == 'empty') 'empty' else 'report'
)
Expand All @@ -145,7 +160,7 @@ use_visc_report <- function(report_name = "PT-Report",
usethis::ui_done(
glue::glue("Creating {{report_type}} VISC report at '{{file.path(path, report_name)}}'")
)
if (report_type != 'empty'){
if (report_type != 'empty') {
use_visc_methods(path = file.path(path, report_name), assay = report_type,
interactive = interactive)
}
Expand All @@ -154,15 +169,15 @@ use_visc_report <- function(report_name = "PT-Report",
}

challenge_visc_report <- function(report_name, interactive = TRUE) {
if (! interactive) return(invisible(NULL))
if (!interactive) return(invisible(NULL))

continue <- usethis::ui_yeah("
Creating a new VISC PT Report called {report_name}.
At VISC, we use a naming convention for PT reports:
'VDCnnn_assay_PT_Report_statusifapplicable'
where 'statusifapplicable' distinguishes blinded reports,
HIV status, or something that distinguishes a type/subset
of a report.
'VDCnnn_assay_PTreport_status_blindingifapplicable'
where 'status' should be either 'interim' or 'final'
and 'blindingifapplicable' should be either 'blinded'
or 'unblinded' (applicable to interim reports only).
'VDC' is the PI name and 'nnn' is the study number.
Would you like to continue?")

Expand All @@ -177,7 +192,7 @@ challenge_visc_report <- function(report_name, interactive = TRUE) {
#' used in PT reports: statistical-methods.Rmd, lab-methods.Rmd,
#' and biological-endpoints.Rmd
#'
#' @param assay "bama" or "generic"
#' @param assay "generic", "bama", "nab" or "adcc"
#' @param path path within the active project
#' @param interactive TRUE by default. FALSE is for non-interactive unit testing
#' only.
Expand All @@ -188,13 +203,13 @@ challenge_visc_report <- function(report_name, interactive = TRUE) {
#' \dontrun{
#' use_visc_methods(path = "bama/BAMA-PT-Report", assay = "bama")
#' }
use_visc_methods <- function(path = ".", assay = c("generic", "bama", "nab"),
use_visc_methods <- function(path = ".", assay = c("generic", "bama", "nab", "adcc"),
interactive = TRUE) {

# suppress usethis output when non-interactive
old_usethis_quiet <- getOption('usethis.quiet')
on.exit(options(usethis.quiet = old_usethis_quiet))
options(usethis.quiet = ! interactive)
options(usethis.quiet = !interactive)

pkg_ver <- utils::packageVersion("VISCtemplates")

Expand Down
8 changes: 7 additions & 1 deletion R/visc_load_pdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ visc_load_pdata <- function(.data,
lazyLoad(filebase = system.file(file.path('data', 'Rdata'),
package = pkg_name), envir = pdata_env)
} else {
stop('Unable to find data object file')
stop(
sprintf(
"Unable to find data object '%s' in package '%s'",
pdata_name,
pkg_name
)
)
}
}

Expand Down
7 changes: 6 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ knitr::opts_chunk$set(
)
```

<!-- badges: start -->
[![R-CMD-check](https://github.com/FredHutch/VISCtemplates/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/FredHutch/VISCtemplates/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/FredHutch/VISCtemplates/graph/badge.svg)](https://app.codecov.io/gh/FredHutch/VISCtemplates)
<!-- badges: end -->

# VISCtemplates

The goal of VISCtemplates is to:
Expand Down Expand Up @@ -76,7 +81,7 @@ Use a VISC Report:

```{r eval=FALSE}
use_visc_report(
report_name = "VDCnnn_BAMA_PT_Report_statusifapplicable", # the name of the report file
report_name = "VDCnnn_BAMA_PTreport_interim_blinded", # the name of the report file
path = "BAMA", # the path within the active directory, usually the name of the assay
report_type = "bama" # "empty", "generic", "bama", or "nab"
)
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->
<!-- badges: start -->

[![R-CMD-check](https://github.com/FredHutch/VISCtemplates/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/FredHutch/VISCtemplates/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/FredHutch/VISCtemplates/graph/badge.svg)](https://app.codecov.io/gh/FredHutch/VISCtemplates)
<!-- badges: end -->

# VISCtemplates

Expand Down Expand Up @@ -66,7 +72,7 @@ Use a VISC Report:

``` r
use_visc_report(
report_name = "VDCnnn_BAMA_PT_Report_statusifapplicable", # the name of the report file
report_name = "VDCnnn_BAMA_PTreport_interim_blinded", # the name of the report file
path = "BAMA", # the path within the active directory, usually the name of the assay
report_type = "bama" # "empty", "generic", "bama", or "nab"
)
Expand Down
2 changes: 1 addition & 1 deletion inst/rmarkdown/templates/visc_empty/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ opts_chunk$set(cache = FALSE,
out.extra = "",
fig.pos = "H")
# fig.align argument is not supported in Word (align in template docx)
if (knitr::opts_knit$get('rmarkdown.pandoc.to') == 'latex'){
if (get_output_type() == 'latex'){
opts_chunk$set(fig.align = "center")
}
Expand Down
5 changes: 5 additions & 0 deletions inst/rmarkdown/templates/visc_report/resources/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
\usepackage{threeparttable} % provides a scheme for tables that have a structured (foot)note section, after the caption
\usepackage{threeparttablex} % provides the functionality of the threeparttable package to tables created using the longtable package

% needed for flextable to work
\usepackage{hhline}
\newlength\Oldarrayrulewidth
\newlength\Oldtabcolsep

% being able to set emphasis for entire table row
\newcommand\setrow[1]{\gdef\rowmac{#1}#1\ignorespaces}
\newcommand\clearrow{\global\let\rowmac\relax}
Expand Down
4 changes: 2 additions & 2 deletions inst/rmarkdown/templates/visc_report/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ opts_chunk$set(cache = FALSE,
out.extra = "",
fig.pos = "H")
# fig.align argument is not supported in Word (align in template docx)
if (knitr::opts_knit$get('rmarkdown.pandoc.to') == 'latex'){
if (get_output_type() == 'latex'){
opts_chunk$set(fig.align = "center")
}
Expand Down Expand Up @@ -398,7 +398,7 @@ kable(

The authors thank the following individuals for their invaluable contributions to this report.
From [insert group name or affiliation, for example: the CAVIMC/Duke team] we thank [insert individual names, and roles here, for example: Kelli Greene and Hongmei Gao (Experimental Design, Data Interpretation, Study Management); Nicole Yates (Scientific Research Laboratory Manager) and Sheetal Sawant (Biostatistician)].
From Fred Hutch Cancer Center, we also thank [insert names and roles here, for example: Ratana Som (SCHARP Lab Data Manager); Marie Vendettuoli and Valeria Duran (SCHARP Statistical Programmers); and Lindsey Mwoga and Drienna Holman (VISC Project Management)].
From Fred Hutch Cancer Center, we also thank [insert names and roles here, for example: Ratana Som (SCHARP Lab Data Manager); Valeria Duran (SCHARP Statistical Programmer); and Lindsey Mwoga and Drienna Holman (VISC Project Management)].

Note: names may be listed in bullet point format instead of paragraph format if that helps with
readability, for example:
Expand Down
Loading

0 comments on commit 01a8b2e

Please sign in to comment.