Skip to content

Commit d29a3ad

Browse files
authored
Tweaks for cran (#278)
1 parent 4e6b0b1 commit d29a3ad

File tree

75 files changed

+376
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+376
-269
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
matrix:
1818
config:
1919
- {os: macOS-latest, r: 'release'}
20-
- {os: windows-latest, r: 'release'}
20+
#- {os: windows-latest, r: 'release'}
2121
- {os: ubuntu-latest, r: 'release'}
2222
env:
2323
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
@@ -38,6 +38,7 @@ jobs:
3838
with:
3939
extra-packages: rcmdcheck, survival, flexsurv, testthat, usethis, vdiffr, tibble, xml2, knitr, rmarkdown, bayesplot, matrixcalc, WeightIt, MatchIt, BayesPPD, ggsurvfit, gbm, ggplot2, cobalt, table1, gt, gtsummary
4040
dependencies: '"hard"'
41+
cache: false
4142

4243
- name: Install system dependencies on Linux
4344
if: runner.os == 'Linux'

DESCRIPTION

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@ Authors@R: c(
2727
Description: Bayesian dynamic borrowing is an approach to incorporating external
2828
data to supplement a randomized, controlled trial analysis in which
2929
external data are incorporated in a dynamic way (e.g., based on similarity
30-
of outcomes); see Viele 2013 \doi{10.1002/pst.1589} for an overview.
30+
of outcomes); see Viele 2013 <doi:10.1002/pst.1589> for an overview.
3131
This package implements the hierarchical commensurate prior approach to dynamic borrowing
32-
as described in Hobbes 2011 \doi{10.1111/j.1541-0420.2011.01564.x}.
32+
as described in Hobbes 2011 <doi:10.1111/j.1541-0420.2011.01564.x>.
3333
There are three main functionalities. First, 'psborrow2' provides a user-friendly
3434
interface for applying dynamic borrowing on the study results handles the Markov Chain
3535
Monte Carlo sampling on behalf of the user. Second, 'psborrow2' provides a
3636
simulation framework to compare different borrowing parameters (e.g. full borrowing, no
3737
borrowing, dynamic borrowing) and other trial and borrowing characteristics
3838
(e.g. sample size, covariates) in a unified way. Third, 'psborrow2' provides
3939
a set of functions to generate data for simulation studies, and also allows
40-
the user to specify their own data generation process.
40+
the user to specify their own data generation process. This package is designed to
41+
use the sampling functions from 'cmdstanr' which can be installed from
42+
<https://mc-stan.org/r-packages/>.
4143
URL: https://github.com/Genentech/psborrow2, https://genentech.github.io/psborrow2/index.html
4244
BugReports: https://github.com/Genentech/psborrow2/issues
4345
License: Apache License 2.0

NAMESPACE

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,18 @@ export(check_cmdstanr)
1818
export(check_data_matrix_has_columns)
1919
export(cont_var)
2020
export(covariance_matrix)
21-
export(create_alpha_string)
2221
export(create_analysis_obj)
2322
export(create_baseline_object)
2423
export(create_data_matrix)
2524
export(create_data_simulation)
2625
export(create_event_dist)
2726
export(create_simulation_obj)
28-
export(create_tau_string)
2927
export(custom_enrollment)
3028
export(cut_off_after_events)
3129
export(cut_off_after_first)
3230
export(cut_off_after_last)
3331
export(cut_off_none)
3432
export(enrollment_constant)
35-
export(eval_constraints)
3633
export(exp_surv_dist)
3734
export(exponential_prior)
3835
export(gamma_prior)
@@ -81,11 +78,10 @@ export(sim_outcome_list)
8178
export(sim_samplesize)
8279
export(sim_treatment_list)
8380
export(treatment_details)
84-
export(trim_cols)
85-
export(trim_rows)
8681
export(uniform_prior)
8782
export(variable_dictionary)
8883
export(weib_ph_surv_dist)
84+
exportMethods(c)
8985
exportMethods(generate)
9086
exportMethods(mcmc_sample)
9187
exportMethods(set_transformations)

R/borrowing_details.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
#' Legacy function for specifying borrowing details
22
#'
3-
#' Please use one of `hierarchical_commensurate_borrowing()`, `no_borrowing()`, or `full_borrowing()` instead.
3+
#' Please use one of `borrowing_hierarchical_commensurate()`, `borrowing_none()`, or `borrowing_full()` instead.
44
#' @export
5+
#'
6+
#' @return
7+
#' This function does not return a value. When called, it triggers an error
8+
#' message indicating that `borrowing_details()` is deprecated and that
9+
#' one of `borrowing_hierarchical_commensurate()`, `borrowing_none()`, or
10+
#' `borrowing_full()` should be used instead.
11+
#'
512
#' @param ... Deprecated arguments to `borrowing_details`.
613
borrowing_details <- function(...) {
714
.Defunct(
8-
"hierarchical_commensurate_borrowing()",
15+
"borrowing_hierarchical_commensurate()",
916
"psborrow2",
1017
paste(
1118
"`borrowing_details()` is deprecated. Use `borrowing_hierarchical_commensurate()` for dynamic borrowing,",

R/check_data_matrix_has_columns.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' @return `stop()` if some columns are missing.
88
#' @export
99
#' @examples
10-
#' anls <- psborrow2:::.analysis_obj(
10+
#' anls <- create_analysis_obj(
1111
#' data_matrix = example_matrix,
1212
#' covariates = add_covariates(
1313
#' covariates = c("cov1", "cov2"),
@@ -25,8 +25,7 @@
2525
#' treatment = treatment_details(
2626
#' "trt",
2727
#' prior_normal(0, 1000)
28-
#' ),
29-
#' ready_to_sample = FALSE
28+
#' )
3029
#' )
3130
#'
3231
#' check_data_matrix_has_columns(anls)

R/generics.R

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
#' @param y Not used.
1111
#' @param add logical. Add density to existing plot.
1212
#' @param ... Optional arguments for plotting.
13-
#'
13+
#' @return No return value, this function generates a plot in the current graphics device.
1414
#' @export
1515
#' @details
1616
#' Plot ranges are selected by default to show 99% of the density for unbounded distributions.
1717
#' The limits can be changed by specifying `xlim = c(lower, upper)`.
1818
#'
1919
#' Colors, line types, and other typical [par()] parameters can be used.
20-
#'
2120
if (!isGeneric("plot")) setGeneric("plot", function(x, y, ...) standardGeneric("plot"))
2221

2322

@@ -29,7 +28,7 @@ if (!isGeneric("plot")) setGeneric("plot", function(x, y, ...) standardGeneric("
2928
#' @aliases get_vars
3029
#'
3130
#' @param object Object
32-
#' @returns A `character` vector containing variable names
31+
#' @return A `character` vector containing variable names
3332
#' @export
3433
#'
3534
setGeneric("get_vars", function(object) standardGeneric("get_vars"))
@@ -57,6 +56,8 @@ setGeneric("mcmc_sample", function(x, ...) standardGeneric("mcmc_sample"))
5756
#'
5857
#' @rdname show_guide
5958
#'
59+
#' @return A `data.frame` showing all simulation scenarios.
60+
#'
6061
#' @export
6162
#'
6263
setGeneric("show_guide", function(object) standardGeneric("show_guide"))
@@ -68,6 +69,8 @@ setGeneric("show_guide", function(object) standardGeneric("show_guide"))
6869
#' @param object `MCMCSimulationResults` object
6970
#'
7071
#' @rdname get_results
72+
#'
73+
#' @return data.frame with simulation results.
7174
#'
7275
#' @export
7376
#'
@@ -80,6 +83,8 @@ setGeneric("get_results", function(object) standardGeneric("get_results"))
8083
#' @param object `MCMCSimulationResults` object
8184
#'
8285
#' @rdname get_cmd_stan_models
86+
#'
87+
#' @return List of lists of `CmdStanModel` objects for each model.
8388
#'
8489
#' @export
8590
#'
@@ -92,6 +97,8 @@ setGeneric("get_cmd_stan_models", function(object) standardGeneric("get_cmd_stan
9297
#'
9398
#' @rdname generate
9499
#'
100+
#' @return Object of class [`SimDataList`][SimDataList-class].
101+
#'
95102
#' @export
96103
setGeneric("generate", function(x, ...) standardGeneric("generate"))
97104

@@ -101,8 +108,6 @@ setGeneric("generate", function(x, ...) standardGeneric("generate"))
101108
#' @param analysis_object analysis object
102109
#'
103110
#' @rdname trim_rows
104-
#'
105-
#' @export
106111
setGeneric("trim_rows", function(borrowing_object, analysis_object) standardGeneric("trim_rows"))
107112

108113
#' Trim columns from Data Matrix Based on Borrowing object type
@@ -111,8 +116,6 @@ setGeneric("trim_rows", function(borrowing_object, analysis_object) standardGene
111116
#' @param analysis_object analysis object
112117
#'
113118
#' @rdname trim_cols
114-
#'
115-
#' @export
116119
setGeneric("trim_cols", function(borrowing_object, analysis_object) standardGeneric("trim_cols"))
117120

118121
#' Create alpha string
@@ -121,20 +124,15 @@ setGeneric("trim_cols", function(borrowing_object, analysis_object) standardGene
121124
#' @param outcome_object outcome object
122125
#'
123126
#' @rdname create_alpha_string
124-
#'
125-
#' @export
126127
setGeneric("create_alpha_string", function(borrowing_object, outcome_object) standardGeneric("create_alpha_string"))
127128

128129
#' Create tau string
129130
#'
130131
#' @param borrowing_object borrowing object
131132
#'
132133
#' @rdname create_tau_string
133-
#'
134-
#' @export
135134
setGeneric("create_tau_string", function(borrowing_object) standardGeneric("create_tau_string"))
136135

137-
138136
#' Create Stan Code for Model
139137
#'
140138
#' @param borrowing borrowing object
@@ -145,12 +143,26 @@ setGeneric("create_tau_string", function(borrowing_object) standardGeneric("crea
145143
#' @return `glue` `character` containing the Stan code for the data block.
146144
#' @export
147145
#' @examples
148-
#' anls_obj <- psborrow2:::.analysis_obj(
149-
#' data_matrix = example_matrix,
150-
#' outcome = outcome_surv_exponential("time", "cnsr", prior_normal(0, 100)),
151-
#' borrowing = borrowing_full("ext"),
152-
#' treatment = treatment_details("trt", prior_normal(0, 100))
153-
#' )
146+
#' anls_obj <- create_analysis_obj(
147+
#' data_matrix = example_matrix,
148+
#' outcome = outcome_surv_exponential(
149+
#' "time",
150+
#' "cnsr",
151+
#' baseline_prior = prior_normal(0, 1000)
152+
#' ),
153+
#' borrowing = borrowing_hierarchical_commensurate(
154+
#' "ext",
155+
#' prior_exponential(.001)
156+
#' ),
157+
#' treatment = treatment_details(
158+
#' "trt",
159+
#' prior_normal(0, 1000)
160+
#' ),
161+
#' covariates = add_covariates(
162+
#' covariates = c("cov1", "cov2"),
163+
#' priors = prior_normal(0, 1000)
164+
#' )
165+
#' )
154166
#' make_model_string_model(anls_obj@borrowing, anls_obj@outcome, anls_obj)
155167
setGeneric("make_model_string_model", function(borrowing, outcome, analysis_obj) {
156168
standardGeneric("make_model_string_model")
@@ -164,7 +176,7 @@ setGeneric("make_model_string_model", function(borrowing, outcome, analysis_obj)
164176
#'
165177
#' @param x object of type: [BaselineDataList-class]
166178
#' @param ... Optional arguments for passed to [data.frame]
167-
#' @returns A `data.frame`
179+
#' @return A `data.frame`
168180
NULL
169181

170182
#' @title Combine objects in `psborrow2`
@@ -173,7 +185,7 @@ NULL
173185
#' @name c
174186
#' @param x object of type: [SimDataList-class]
175187
#' @param ... additional objects to combine
176-
#' @returns A combined object
188+
#' @return A combined object
177189
NULL
178190

179191
#' Get Simulated Data from `SimDataList` object
@@ -183,7 +195,7 @@ NULL
183195
#' @param object `SimDataList` object
184196
#' @param index the index of the scenario (see guide with print(`SimDataList`))
185197
#' @param dataset the dataset out of `n_datasets_per_param`
186-
#' @returns Simulated data as a data frame if the index is specified, else as a list
198+
#' @return Simulated data as a data frame if the index is specified, else as a list
187199
#' @export
188200
setGeneric("get_data", function(object, index = 1, dataset = 1) standardGeneric("get_data"))
189201

@@ -192,12 +204,12 @@ setGeneric("get_data", function(object, index = 1, dataset = 1) standardGeneric(
192204
#' @param object `BaselineObject` object
193205
#' @param ... Additional arguments passed to methods
194206
#' @param overwrite logical. Overwrite existing transformations?
195-
#' @returns `BaselineObject` object with transformations
207+
#' @return `BaselineObject` object with transformations
196208
#' @export
197209
setGeneric("set_transformations", function(object, ..., overwrite = FALSE) standardGeneric("set_transformations"))
198210

199211
#' Get method for Stan model
200212
#' @param object `Analysis` object
201-
#' @returns String containing the Stan model
213+
#' @return String containing the Stan model
202214
#' @export
203215
setGeneric("get_stan_code", function(object) standardGeneric("get_stan_code"))

R/helpers.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
#'
77
#' Plots the density values as a curve with the lower vertical limit set to 0.
88
#'
9-
#' @export
9+
#'
10+
#' @return No return value, this function generates a plot in the current graphics device.
1011
#'
12+
#' @export
13+
#'
1114
#' @examples
1215
#' x <- seq(-2, 2, len = 100)
1316
#' y <- dnorm(x)
@@ -36,6 +39,8 @@ plot_pdf <- function(x, y, ...) {
3639
#'
3740
#' Plots the probability values as a barplot.
3841
#'
42+
#' @return No return value, this function generates a plot in the current graphics device.
43+
#'
3944
#' @export
4045
#'
4146
#' @examples
@@ -73,12 +78,12 @@ plot_pmf <- function(x, y, ..., col = "grey", add = FALSE) {
7378
#' @param collapse_sep string. A character string to separate the original strings in the collapsed string.
7479
#'
7580
#' @return A character (of class `glue`).
76-
#' @noRd
7781
#' @examples
7882
#' name <- "Tom"
7983
#' psborrow2:::h_glue("hello, my name is {{name}}.")
8084
#' name <- c("Tom", "Fred")
8185
#' psborrow2:::h_glue("hello, my name is {{name}}.", collapse = TRUE)
86+
#' @noRd
8287
h_glue <- function(..., collapse = FALSE, collapse_sep = "\n") {
8388
result <- glue::glue(..., .open = "{{", .close = "}}", .envir = parent.frame())
8489
if (isTRUE(collapse)) {
@@ -94,7 +99,7 @@ h_glue <- function(..., collapse = FALSE, collapse_sep = "\n") {
9499
#'
95100
#' @return A `matrix` with columns "lower" and "upper" with rows for each `Prior`.
96101
#' @examples
97-
#' psborrow2:::get_covariate_constraints(
102+
#' get_covariate_constraints(
98103
#' add_covariates(
99104
#' c("cov1", "cov2", "cov3"),
100105
#' list(
@@ -104,7 +109,7 @@ h_glue <- function(..., collapse = FALSE, collapse_sep = "\n") {
104109
#' )
105110
#' )
106111
#' )
107-
#'
112+
#' @noRd
108113
get_covariate_constraints <- function(cov_obj) {
109114
n_covs <- length(cov_obj@covariates)
110115
if (is(cov_obj@priors, "Prior")) {
@@ -125,7 +130,8 @@ get_covariate_constraints <- function(cov_obj) {
125130
#' A list with upper and lower bounds. Any unspecified bounds are set to `-Inf` or `Inf`.
126131
#' @examples
127132
#' np <- prior_normal(0, 100)
128-
#' psborrow2:::parse_constraint(np)
133+
#' parse_constraint(np)
134+
#' @noRd
129135
parse_constraint <- function(object) {
130136
assert_class(object, "Prior")
131137
s <- eval_constraints(object)
@@ -214,7 +220,8 @@ variable_dictionary <- function(analysis_obj) {
214220
#'
215221
#' @return A string containing the Stan code sampling from specified distribution.
216222
#' @examples
217-
#' psborrow2:::get_prior_string(prior_normal(0, 100))
223+
#' get_prior_string(prior_normal(0, 100))
224+
#' @noRd
218225
get_prior_string <- function(object) {
219226
assert_multi_class(object, c("Prior", "list"))
220227
if (is(object, "list")) {

R/make_model_string_data.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
#' Create the Stan string encompassed by data `{}`
44
#'
55
#' @param analysis_obj `Analysis`. Object of class [`Analysis`][Analysis-class] created by
6-
#' `psborrow2:::.analysis_obj()`.
6+
#' `.analysis_obj()`.
77
#'
88
#' @return `glue` `character` containing the text for the data block.
99
#'
1010
#' @examples
11-
#' anls_obj <- psborrow2:::.analysis_obj(
11+
#' anls_obj <- .analysis_obj(
1212
#' data_matrix = example_matrix,
1313
#' outcome = outcome_surv_exponential("time", "cnsr", prior_normal(0, 100)),
1414
#' borrowing = borrowing_full("ext"),
1515
#' treatment = treatment_details("trt", prior_normal(0, 100))
1616
#' )
17-
#'
18-
#' psborrow2:::make_model_string_data(anls_obj)
19-
#'
17+
#'
18+
#' make_model_string_data(anls_obj)
19+
#' @noRd
2020
make_model_string_data <- function(analysis_obj) {
2121
outcome_string <- analysis_obj@outcome@data_stan_code
2222

0 commit comments

Comments
 (0)