Skip to content

Commit

Permalink
Function pull() added
Browse files Browse the repository at this point in the history
  • Loading branch information
fpahlke committed Mar 28, 2024
1 parent f09af59 commit e2294a7
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 30 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rpact
Title: Confirmatory Adaptive Clinical Trial Design and Analysis
Version: 4.0.0.9236
Date: 2024-03-26
Version: 4.0.0.9238
Date: 2024-03-28
Authors@R: c(
person(
given = "Gernot",
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ S3method(print,ParameterSet)
S3method(print,SimulationResults)
S3method(print,SummaryFactory)
S3method(print,TrialDesignCharacteristics)
S3method(pull,ParameterSet)
S3method(summary,AnalysisResults)
S3method(summary,Dataset)
S3method(summary,ParameterSet)
Expand Down Expand Up @@ -119,6 +120,7 @@ export(mvstud)
export(plotTypes)
export(ppwexp)
export(printCitation)
export(pull)
export(qpwexp)
export(rcmd)
export(readDataset)
Expand Down
18 changes: 11 additions & 7 deletions R/class_analysis_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
## |
## | Contact us for information about our services: info@rpact.com
## |
## | File version: $Revision: 7742 $
## | Last changed: $Date: 2024-03-22 13:46:29 +0100 (Fr, 22 Mrz 2024) $
## | File version: $Revision: 7763 $
## | Last changed: $Date: 2024-03-28 14:35:29 +0100 (Do, 28 Mrz 2024) $
## | Last changed by: $Author: pahlke $
## |

Expand Down Expand Up @@ -463,7 +463,9 @@ writeDatasets <- function(datasets, file, ..., append = FALSE, quote = TRUE, sep
}
}

return(.getEnrichmentDatasetFromArgs(...))
dataset <- .getEnrichmentDatasetFromArgs(...)
dataset$.design <- design
return(dataset)
}

exampleType <- args[["example"]]
Expand Down Expand Up @@ -881,12 +883,13 @@ getDataSet <- function(..., floatingPointNumbersEnabled = FALSE) {
subsetNumbers <- as.integer(subsetNumbers)
gMax <- max(subsetNumbers) + 1
validSubsetNames <- .createSubsetsByGMax(gMax, stratifiedInput = stratifiedInput, all = FALSE)
for (subsetName in subsetNames) {
if (subsetName == "") {
for (i in 1:length(subsetNames)) {
subsetName <- subsetNames[i]
if (subsetName == "" && !inherits(args[[i]], "TrialDesign")) {
stop(C_EXCEPTION_TYPE_ILLEGAL_ARGUMENT, "all subsets must be named")
}

if (!(subsetName %in% validSubsetNames)) {
if (subsetName != "" && !(subsetName %in% validSubsetNames)) {
suffix <- ifelse(stratifiedInput, " (stratified analysis)", " (non-stratified analysis)")
if (length(validSubsetNames) < 10) {
stop(
Expand All @@ -903,7 +906,8 @@ getDataSet <- function(..., floatingPointNumbersEnabled = FALSE) {
}
}
}


subsetNames <- subsetNames[subsetNames != ""]
subsets <- NULL
subsetType <- NA_character_
emptySubsetNames <- validSubsetNames[!(validSubsetNames %in% subsetNames)]
Expand Down
54 changes: 51 additions & 3 deletions R/class_core_parameter_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
## |
## | Contact us for information about our services: info@rpact.com
## |
## | File version: $Revision: 7750 $
## | Last changed: $Date: 2024-03-26 15:44:44 +0100 (Di, 26 Mrz 2024) $
## | File version: $Revision: 7763 $
## | Last changed: $Date: 2024-03-28 14:35:29 +0100 (Do, 28 Mrz 2024) $
## | Last changed by: $Author: pahlke $
## |

Expand Down Expand Up @@ -1631,14 +1631,62 @@ print.ParameterSet <- function(x, ..., markdown = NA) {

if (markdown) {
x$.catMarkdownText()
cat("\n\n")
} else {
x$show()
}

if (isTRUE(markdown)) {
attr(x, "markdown") <- TRUE
}

return(invisible(x))
}

#' @export
pull <- function(x, var) UseMethod("pull")

#'
#' Extract a single parameter
#'
#' Pull a parameter from a parameter set.
#'
#' @param var A variable specified as:
#' - a literal variable name
#' - a positive integer, giving the position counting from the left
#' - a negative integer, giving the position counting from the right.
#' The default returns the last column (on the assumption that's the column you've created most recently).
#' This argument is taken by expression and supports quasiquotation (you can unquote column names and column locations).
#'
#' @export
#'
pull.ParameterSet <- function(x, var = -1) {
fCall <- match.call(expand.dots = FALSE)
varName <- deparse(fCall$var)
if (!exists(varName) || (!is.character(var) && !is.integer(var))) {
var <- gsub('"', "", varName)
var <- gsub("'", "", var)
}

if (is.character(var)) {
if (!(var %in% names(x))) {
stop(C_EXCEPTION_TYPE_ILLEGAL_ARGUMENT, "variable ", sQuote(var), " does not exist")
}

return(x[[var]])
}

.assertIsSingleInteger(x, "x", validateType = FALSE)
.assertIsInClosedInterval(x, "x", lower = -length(x), upper = length(x))
if (var == 0) {
stop(C_EXCEPTION_TYPE_ILLEGAL_ARGUMENT, "'x' (", x, ") must != 0")
}
x <- addTrace(x, "pull", var)
if (var < 0) {
var <- length(x) + 1 - var
}
return(x[[var]])
}

#'
#' @title
#' Parameter Set Plotting
Expand Down
54 changes: 38 additions & 16 deletions R/class_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
## |
## | Contact us for information about our services: info@rpact.com
## |
## | File version: $Revision: 7742 $
## | Last changed: $Date: 2024-03-22 13:46:29 +0100 (Fr, 22 Mrz 2024) $
## | File version: $Revision: 7763 $
## | Last changed: $Date: 2024-03-28 14:35:29 +0100 (Do, 28 Mrz 2024) $
## | Last changed by: $Author: pahlke $
## |

Expand Down Expand Up @@ -123,6 +123,11 @@ knit_print.SummaryFactory <- function(x, ...) {
paste0(utils::capture.output(x$object$.catMarkdownText()), collapse = "\n")
)
}

if (isTRUE(x[["markdown"]])) {
sep <- "\n-----\n\n"
result <- paste0(sep, result)
}

return(knitr::asis_output(result))
}
Expand Down Expand Up @@ -152,9 +157,10 @@ print.SummaryFactory <- function(x, ...,
markdown <- .isMarkdownEnabled()
}

if (markdown) {
if (markdown || isTRUE(x[["markdown"]])) {
result <- paste0(utils::capture.output(x$.catMarkdownText()), collapse = "\n")
cat(result, "\n")
cat(sep)
cat(trimws(result), "\n")
return(invisible())
}

Expand Down Expand Up @@ -183,11 +189,13 @@ SummaryFactory <- R6::R6Class("SummaryFactory",
intervalFormat = NULL,
justify = NULL,
output = NULL,
initialize = function(..., object = NULL, intervalFormat = "[%s; %s]", output = "all") {
markdown = NULL,
initialize = function(..., object = NULL, intervalFormat = "[%s; %s]", output = "all", markdown = FALSE) {
super$initialize(...)
self$object <- object
self$intervalFormat <- intervalFormat
self$output <- output
self$markdown <- markdown
self$summaryItems <- list()
self$justify <- getOption("rpact.summary.justify", "right")
},
Expand Down Expand Up @@ -2370,29 +2378,41 @@ SummaryFactory <- R6::R6Class("SummaryFactory",

.createSummary <- function(object, digits = NA_integer_, output = c("all", "title", "overview", "body")) {
output <- match.arg(output)

markdown <- attr(object, "markdown")
if (is.null(markdown) || length(markdown) == 0 || !is.logical(markdown)) {
markdown <- FALSE
}

if (inherits(object, "TrialDesignCharacteristics")) {
return(.createSummaryDesignPlan(object, digits = digits, output = output, showStageLevels = TRUE))
return(.createSummaryDesignPlan(object, digits = digits, output = output,
showStageLevels = TRUE, markdown = markdown))
}

if (.isTrialDesign(object) || .isTrialDesignPlan(object) || inherits(object, "SimulationResults")) {
return(.createSummaryDesignPlan(object, digits = digits, output = output, showStageLevels = !.isTrialDesignPlan(object)))
return(.createSummaryDesignPlan(object, digits = digits, output = output,
showStageLevels = !.isTrialDesignPlan(object), markdown = markdown))
}

if (inherits(object, "AnalysisResults")) {
return(.createSummaryAnalysisResults(object, digits = digits, output = output))
return(.createSummaryAnalysisResults(object, digits = digits, output = output, markdown = markdown))
}

if (inherits(object, "PerformanceScore")) {
return(.createSummaryPerformanceScore(object, digits = digits, output = output))
return(.createSummaryPerformanceScore(object, digits = digits, output = output, markdown = markdown))
}

stop(C_EXCEPTION_TYPE_RUNTIME_ISSUE, "function 'summary' not implemented yet for class ", .getClassName(object))
}

.createSummaryPerformanceScore <- function(object, digits = NA_integer_, output = c("all", "title", "overview", "body")) {
.createSummaryPerformanceScore <- function(object, ...,
digits = NA_integer_,
output = c("all", "title", "overview", "body"),
markdown = FALSE) {
.createSummaryDesignPlan(object$.simulationResults,
digits = digits, output = output,
showStageLevels = TRUE, performanceScore = object
showStageLevels = TRUE, performanceScore = object,
markdown = markdown
)
}

Expand Down Expand Up @@ -2420,7 +2440,8 @@ SummaryFactory <- R6::R6Class("SummaryFactory",
#'
#' @noRd
#'
.createSummaryAnalysisResults <- function(object, digits = NA_integer_, output = c("all", "title", "overview", "body")) {
.createSummaryAnalysisResults <- function(object, ..., digits = NA_integer_,
output = c("all", "title", "overview", "body"), markdown = FALSE) {
output <- match.arg(output)
if (!inherits(object, "AnalysisResults")) {
stop(
Expand Down Expand Up @@ -2457,7 +2478,8 @@ SummaryFactory <- R6::R6Class("SummaryFactory",
}
}

summaryFactory <- SummaryFactory$new(object = object, intervalFormat = intervalFormat, output = output)
summaryFactory <- SummaryFactory$new(object = object,
intervalFormat = intervalFormat, output = output, markdown = markdown)

.addDesignInformationToSummary(design, object, summaryFactory, output = output)

Expand Down Expand Up @@ -2957,7 +2979,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory",
#'
.createSummaryDesignPlan <- function(object, digits = NA_integer_,
output = c("all", "title", "overview", "body"), showStageLevels = FALSE,
performanceScore = NULL) {
performanceScore = NULL, markdown = FALSE) {
output <- match.arg(output)
designPlan <- NULL
if (.isTrialDesignPlan(object) || inherits(object, "SimulationResults")) {
Expand Down Expand Up @@ -2987,7 +3009,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory",
intervalFormat <- getOption("rpact.summary.intervalFormat", "[%s; %s]")
.assertIsValidSummaryIntervalFormat(intervalFormat)

summaryFactory <- SummaryFactory$new(object = object, intervalFormat = intervalFormat, output = output)
summaryFactory <- SummaryFactory$new(object = object, intervalFormat = intervalFormat, output = output, markdown = markdown)

if (output %in% c("all", "title", "overview")) {
.addDesignInformationToSummary(design, designPlan, summaryFactory, output = output)
Expand Down Expand Up @@ -3155,7 +3177,7 @@ SummaryFactory <- R6::R6Class("SummaryFactory",
}

# simulation multi-arm #5: earlyStop per mu_max
if (outputSize %in% c("medium", "large")) {
if (design$kMax > 1 && outputSize %in% c("medium", "large")) {
summaryFactory$addParameter(designPlan,
parameterName = "earlyStop",
parameterCaption = "Overall exit probability", # (under H1)
Expand Down
4 changes: 2 additions & 2 deletions inst/doc/rpact_getting_started.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<meta name="author" content="Friedrich Pahlke and Gernot Wassmer" />

<meta name="date" content="2024-03-26" />
<meta name="date" content="2024-03-28" />

<title>Getting started with rpact</title>

Expand Down Expand Up @@ -239,7 +239,7 @@

<h1 class="title toc-ignore">Getting started with rpact</h1>
<h4 class="author">Friedrich Pahlke and Gernot Wassmer</h4>
<h4 class="date">2024-03-26</h4>
<h4 class="date">2024-03-28</h4>



Expand Down
21 changes: 21 additions & 0 deletions man/pull.ParameterSet.Rd

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

0 comments on commit e2294a7

Please sign in to comment.