Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

775 implement knit print for subclasses of cohortsize including tests #784

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1c2ac70
Caching progress
Puzzled-Face Jan 16, 2024
ec269fb
Caching progress
Puzzled-Face Jan 16, 2024
cac5700
Caching progress
Puzzled-Face Jan 17, 2024
419cd46
knit_print methods for sub-classes of CohortSize
Puzzled-Face Jan 31, 2024
a949cd2
Add comments
Puzzled-Face Feb 1, 2024
0a15c66
Merge a949cd27db4bef9e05a7f48872d64cd8344a1df8 into 8ff7e45f4f0631b74…
Puzzled-Face Feb 1, 2024
8a789f2
[skip actions] Restyle files
github-actions[bot] Feb 1, 2024
aec7c86
Additional comments, fixing one R CMD CHECK warning elsewhere
Puzzled-Face Feb 1, 2024
0eabe62
Merge branch '775-implement-knit_print-for-subclasses-of-cohortsize-i…
Puzzled-Face Feb 1, 2024
467c698
Fix pkgdown error
Puzzled-Face Feb 1, 2024
308430e
Fix R CMD CHECK warning
Puzzled-Face Feb 1, 2024
2a99fc9
Update documentation
Puzzled-Face Feb 1, 2024
672e1f2
Switch from Quarto to Rmd
Puzzled-Face Feb 1, 2024
a9fd494
Merge 672e1f27ab574642438c5339b712a0674d3e768b into 8ff7e45f4f0631b74…
Puzzled-Face Feb 1, 2024
26bc9ab
[skip actions] Restyle files
github-actions[bot] Feb 1, 2024
8dfe5aa
Fix lintr errors
Puzzled-Face Feb 1, 2024
fc23941
Merge branch '775-implement-knit_print-for-subclasses-of-cohortsize-i…
Puzzled-Face Feb 1, 2024
6d31305
Merge fc23941c9b2283837fed44503d0c68b846e90b9b into 8ff7e45f4f0631b74…
Puzzled-Face Feb 1, 2024
22c79e0
[skip actions] Restyle files
github-actions[bot] Feb 1, 2024
d4c9401
Typo
Puzzled-Face Feb 1, 2024
23574b1
Merge branch '775-implement-knit_print-for-subclasses-of-cohortsize-i…
Puzzled-Face Feb 1, 2024
c5997cd
Allow knit_print tests to work in GitHub actions as well as in devtoo…
Puzzled-Face Feb 2, 2024
2e24fca
Merge c5997cde1f9cb6c60f04daf88ac6194903bb3907 into 8ff7e45f4f0631b74…
Puzzled-Face Feb 2, 2024
09e6060
[skip actions] Restyle files
github-actions[bot] Feb 2, 2024
a06085a
Skip knit_print tests during R CMD Check
Puzzled-Face Feb 2, 2024
4ccdee0
Merge branch '775-implement-knit_print-for-subclasses-of-cohortsize-i…
Puzzled-Face Feb 2, 2024
302b2ae
Revise knit_print tests
Puzzled-Face Feb 2, 2024
f24cb12
Merge 302b2aeb557a4873a9f41421cecef2c98ef97634 into 8ff7e45f4f0631b74…
Puzzled-Face Feb 2, 2024
314c77f
[skip actions] Restyle files
github-actions[bot] Feb 2, 2024
e3a67f7
Updating docs
Puzzled-Face Feb 2, 2024
9ad3131
Merge branch '775-implement-knit_print-for-subclasses-of-cohortsize-i…
Puzzled-Face Feb 2, 2024
a21575f
Respond to review comments
Puzzled-Face Feb 5, 2024
cbd1029
Merge a21575fd2a06f028de3feb6c59afd5038bf0d363 into 8ff7e45f4f0631b74…
Puzzled-Face Feb 5, 2024
066e1d6
[skip actions] Restyle files
github-actions[bot] Feb 5, 2024
fe296a1
Fix lintr complaints
Puzzled-Face Feb 5, 2024
70eff53
Fix conflicts
Puzzled-Face Feb 5, 2024
592da24
Merge 70eff53fa543d2512c14165f277c6861a26a5caa into 8ff7e45f4f0631b74…
Puzzled-Face Feb 5, 2024
d40d1eb
[skip actions] Restyle files
github-actions[bot] Feb 5, 2024
b629f79
Dummy commit to restart action
Puzzled-Face Feb 5, 2024
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
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Imports:
GenSA,
gridExtra,
kableExtra,
knitr,
lifecycle,
magrittr,
methods,
Expand All @@ -64,7 +65,6 @@ Suggests:
covr,
data.tree,
ggmcmc,
knitr,
rmarkdown,
stringr,
testthat (>= 3.0.0),
Expand Down Expand Up @@ -117,6 +117,7 @@ Collate:
'Simulations-methods.R'
'crmPack-package.R'
'helpers_design.R'
'helpers_knitr_CohortSize.R'
'helpers_model.R'
'helpers_samples.R'
'helpers_simulations.R'
Expand Down
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Generated by roxygen2: do not edit by hand

S3method(knit_print,CohortSizeConst)
S3method(knit_print,CohortSizeDLT)
S3method(knit_print,CohortSizeMax)
S3method(knit_print,CohortSizeMin)
S3method(knit_print,CohortSizeOrdinal)
S3method(knit_print,CohortSizeParts)
S3method(knit_print,CohortSizeRange)
S3method(plot,gtable)
S3method(print,gtable)
export("%>%")
Expand Down Expand Up @@ -609,6 +616,7 @@ importFrom(kableExtra,column_spec)
importFrom(kableExtra,kable)
importFrom(kableExtra,kable_styling)
importFrom(kableExtra,kbl)
importFrom(knitr,knit_print)
importFrom(lifecycle,badge)
importFrom(magrittr,"%>%")
importFrom(mvtnorm,rmvnorm)
Expand Down
2 changes: 1 addition & 1 deletion R/Design-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ setMethod("simulate",
prob = thisProb,
prob_placebo = thisProb.PL,
cohort_size = thisSize,
cohort_size_pl = thisSize.PL,
cohort_size_placebo = thisSize.PL,
dose_grid = object@data@doseGrid[1],
first_separate = firstSeparate
)
Expand Down
228 changes: 228 additions & 0 deletions R/helpers_knitr_CohortSize.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
#' @importFrom knitr knit_print
NULL

# Integration with knitr ----
#'
#' @description `r lifecycle::badge("experimental")`
#'
#' We provide additional utility functions to allow human-friendly rendition of
#' crmPack objects in Markdown and Quarto files
#'
#' @return a character string that represents the object in markdown.
#' @name knit_print
NULL

# CohortSize ----

#' Render a CohortSizeConst Object
#'
#' @description `r lifecycle::badge("experimental")`
#' @param x (`CohortSize`)\cr The object to knit_print.
#' @param asis (`flag`)\cr Should the return value be wrapped in a call to `knitr::asis_output`?
#' @param label (`character`)\cr The word used to label the participants. See Usage Notes below.
#' @param ... Not used at present
#'
#' @section Usage Notes:
#' `label` describes the trial's participants.
#'
#' It should be a character vector of length 1 or 2. If of length 2, the first
#' element describes a `cohort_size` of 1 and the second describes all other
#' `cohort_size`s. If of length 1, the character `s` is appended to the value
#' when `cohort_size` is not 1.
#' @return The markdown representation of the object, as a character string
#' @seealso [`knit_print`] for more details.
#'
#' @export
#' @rdname knit_print
knit_print.CohortSizeConst <- function(x, ..., asis = TRUE, label = c("participant", "participants")) {
assert_character(label, min.len = 1, max.len = 2, any.missing = FALSE)
assert_flag(asis)

if (length(label) == 1) {
label[2] <- paste0(label[1], "s")
}
rv <- paste0("A constant size of ", x@size, " ", label[ifelse(x@size == 1, 1, 2)], ".")
if (asis) {
rv <- knitr::asis_output(rv)
}
rv
}

#' Render a CohortSizeRange Object
#'
#' @description `r lifecycle::badge("experimental")`
#' @inherit knit_print.CohortSizeConst return
#'
#' @export
#' @rdname knit_print
knit_print.CohortSizeRange <- function(x, ..., asis = TRUE) {
assert_flag(asis)

param <- list(...)
if (!("col.names" %in% names(param))) {
param[["col.names"]] <- c("Lower", "Upper", "Cohort size")
}
if (!("caption" %in% names(param))) {
param[["caption"]] <- "Defined by the dose to be used in the next cohort"
}
x <- tidy(x)
param[["x"]] <- x
rv <- kableExtra::add_header_above(
do.call(knitr::kable, param),
c("Dose" = 2, " " = 1)
)
if (asis) {
rv <- knitr::asis_output(rv)
}
rv
}

#' Render a CohortSizeDLT Object
#'
#' @description `r lifecycle::badge("experimental")`
#' @inherit knit_print.CohortSizeConst return
#' @param ... Passed to `knitr::kable`.
#'
#' @section Usage Notes:
#' The by default, the columns are labelled `Lower`, `Upper` and `Cohort size`. The table's caption is
#' `Defined by the number of DLTs so far observed`. These values can be overridden by passing
#' `col.names` and `caption` in the function call.
#'
#' @export
#' @rdname knit_print
knit_print.CohortSizeDLT <- function(x, ..., asis = TRUE) {
assert_flag(asis)

param <- list(...)
if (!("col.names" %in% names(param))) {
param[["col.names"]] <- c("Lower", "Upper", "Cohort size")
}
if (!("caption" %in% names(param))) {
param[["caption"]] <- "Defined by the number of DLTs so far observed"
}
param[["x"]] <- tidy(x)
rv <- kableExtra::add_header_above(
do.call(knitr::kable, param),
c("No of DLTs" = 2, " " = 1)
)
if (asis) {
rv <- knitr::asis_output(rv)
}
rv
}

#' Render a CohortSizeParts Object
#'
#' @description `r lifecycle::badge("experimental")`
#' @inherit knit_print.CohortSizeConst return
#' @inheritSection knit_print.CohortSizeConst Usage Notes
#'
#' @export
#' @rdname knit_print
knit_print.CohortSizeParts <- function(x, ..., asis = TRUE, label = c("participant", "participants")) {
assert_character(label, min.len = 1, max.len = 2, any.missing = FALSE)
assert_flag(asis)

if (length(label) == 1) {
label[2] <- paste0(label[1], "s")
}
rv <- paste0(
"A size of ",
x@cohort_sizes[1],
" ",
label[ifelse(x@cohort_sizes[1] == 1, 1, 2)],
" in the first part and ",
x@cohort_sizes[2],
" ",
label[ifelse(x@cohort_sizes[2] == 1, 1, 2)],
" in the second."
)
if (asis) {
rv <- knitr::asis_output(rv)
}
rv
}

#' Render a CohortSizeMax Object
#'
#' @description `r lifecycle::badge("experimental")`
#' @inherit knit_print.CohortSizeConst return
#' @param ... passed through to the `knit_print` methods of the constituent
#' rules
#'
#' @export
#' @rdname knit_print
knit_print.CohortSizeMax <- function(x, ..., asis = TRUE) {
assert_flag(asis)
rv <- paste0(
"The maximum of the cohort sizes defined in the following rules:",
paste0(
lapply(
x@cohort_sizes,
function(x, ...) {
knit_print(x, asis = asis, ...)
}
),
collapse = "\n"
),
paste = "\n"
)

if (asis) {
rv <- knitr::asis_output(rv)
}
rv
}

#' Render a CohortSizeMin Object
#'
#' @description `r lifecycle::badge("experimental")`
#' @inherit knit_print.CohortSizeConst return
#' @param ... passed through to the `knit_print` methods of the constituent
#' rules
#'
#' @export
#' @rdname knit_print
knit_print.CohortSizeMin <- function(x, ..., asis = TRUE) {
assert_flag(asis)
rv <- paste0(
"The minimum of the cohort sizes defined in the following rules:",
paste0(
lapply(
x@cohort_sizes,
function(x, ...) {
knit_print(x, asis = asis, ...)
}
),
collapse = "\n"
),
paste = "\n"
)
if (asis) {
rv <- knitr::asis_output(rv)
}
rv
}

#' Render a CohortSizeOrdinal Object
#'
#' @description `r lifecycle::badge("experimental")`
#' @inherit knit_print.CohortSizeConst return
#' @param ... passed through to the `knit_print` method of the standard rule
#'
#' @export
#' @rdname knit_print
knit_print.CohortSizeOrdinal <- function(x, ..., asis = TRUE) {
rv <- paste0(
"Based on a toxicity grade of ",
x@grade,
": ",
paste0(knit_print(x@rule, asis = asis, ...), collapse = "\n"),
paste = "\n"
)

if (asis) {
rv <- knitr::asis_output(rv)
}
rv
}
1 change: 1 addition & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ reference:
- is_logging_enabled
- log_trace
- dapply
- knit_print
- title: Classes
contents:
- CohortSizeOrdinal-class
Expand Down
92 changes: 92 additions & 0 deletions man/knit_print.Rd

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

Loading
Loading