Skip to content

Commit 4ee7f54

Browse files
authored
Merge pull request #19 from jdblischak/s3
Convert from S7 to S3 OOP
2 parents dd8bc1e + 533dcf0 commit 4ee7f54

16 files changed

+292
-262
lines changed

DESCRIPTION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Imports:
1717
dplyr,
1818
readr,
1919
rlang,
20-
S7,
2120
tidyr
2221
Suggests:
2322
flexsurv,

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method("+",dynpv)
4+
S3method("-",dynpv)
5+
S3method(print,dynpv)
6+
export(addprod)
37
export(class_dynpv)
48
export(dynpv)
59
export(futurepv)

R/dynamic.R

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ trim_vec <- function(vec){
3737
}
3838

3939
#' Calculate present value for a payoff with dynamic pricing and dynamic uptake
40-
#'
40+
#'
4141
#' Present value of a payoff affected by dynamic pricing, with uptake across multiple cohorts (dynamic uptake)
4242
#' @param uptakes Vector of patient uptake over time
4343
#' @param horizon Time horizon for the calculation (length must be less than or equal to the length of payoffs)
4444
#' @param tzero Time at the date of calculation, to be used in lookup in prices vector
45-
#' @param payoffs Vector of payoffs of interest (numeric vector)
45+
#' @param payoffs Vector of payoffs of interest (numeric vector)
4646
#' @param prices Vector of price indices through the time horizon of interest
4747
#' @param discrate Discount rate per timestep, corresponding to price index
4848
#' @param dpv_name Name to be given to Dynamic Present Value object created by this function call
4949
#' @returns A list containing `inputs` and `results`.
50-
#' The `inputs` list contains a list of the following parameters called with the function: `uptakes, payoffs, horizon, tzero, prices`, and `discrate`.
51-
#' The `results` output is a [class_dynpv()] S7 object that contains the following elements:
50+
#' The `inputs` list contains a list of the following parameters called with the function: `uptakes, payoffs, horizon, tzero, prices`, and `discrate`.
51+
#' The `results` output is a "dynpv" object (created by [class_dynpv()]) that contains the following elements:
5252
#' - `name`: Name given to the object
5353
#' - `df`: Tibble of calculation results
5454
#' - `ncoh`: Number of cohorts of uptaking patients
@@ -66,19 +66,19 @@ trim_vec <- function(vec){
6666
#' payoffs = c("cost_daq_new", "cost_total", "qaly"),
6767
#' discount = "disc"
6868
#' )
69-
#'
69+
#'
7070
#' # Obtain short payoff vector of interest
7171
#' payoffs <- democe |>
7272
#' dplyr::filter(int=="new", model_time<11) |>
7373
#' dplyr::mutate(cost_oth = cost_total - cost_daq_new)
7474
#' Nt <- nrow(payoffs)
75-
#'
75+
#'
7676
#' # Example calculation
7777
#' dynpv(
7878
#' uptakes = rep(1, Nt),
7979
#' payoffs = payoffs$cost_oth,
8080
#' prices = 1 + (0:(Nt-1))*0.05,
81-
#' discrate = 0.08
81+
#' discrate = 0.08
8282
#' )
8383
dynpv <- function(
8484
uptakes = 1,
@@ -106,9 +106,10 @@ dynpv <- function(
106106
v = (1+discrate)^(1 - t),
107107
pv = uj * pk * R * v
108108
)
109+
109110
# Put dataset into a dynpv_class object
110-
cds <- class_dynpv(name = dpv_name, df = df)
111-
# Return
111+
cds <- class_dynpv(name = dpv_name, df = df)
112+
112113
return(list(
113114
inputs = list(
114115
uptakes = uptakes,

R/future.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#' @seealso [dynpv()]
2929
#' @returns A list `inputs`, `results` and `pv`.
3030
#' The `inputs` list contains a list of the following parameters called with the function: `uptakes, payoffs, horizon, tzero, prices`, and `discrate`.
31-
#' The `results` output is a [class_dynpv()] S7 object that contains the following elements:
31+
#' The `results` output is a "dynpv" object (created by [class_dynpv()]) that contains the following elements:
3232
#' - `name`: Name given to the object
3333
#' - `df`: Tibble of calculation results
3434
#' - `ncoh`: Number of cohorts of uptaking patients (always 1)
@@ -80,6 +80,6 @@ futurepv <- function(tzero=0, payoffs, prices, discrate){
8080
list(
8181
inputs = dpv$inputs,
8282
results = dpv$results,
83-
pv = dpv$results@mean
83+
pv = dpv$results$mean
8484
)
85-
}
85+
}

0 commit comments

Comments
 (0)