|
11 | 11 | # https://rconsortium.github.io/S7/articles/packages.html#:~:text=Documentation%20and%20exports,/S7/issues/315 |
12 | 12 | # and my documentation of the class_dynpv S7 class just results in a codoc error on calling check() |
13 | 13 |
|
14 | | -# @title S7 Class Representing a Dynamic Present Value object |
15 | | -# @description A Dynamic Present Value object has a name and a proscribed dataset. |
16 | | -# @param name Name of object (character string) |
17 | | -# @param df Dataframe of proscribed format, such as generated by `dynamicpv::dynpv()` and `dynamicpv::futurepv()`. |
18 | | -# @return An object of class `class_dynpv`, with additional properties: |
19 | | -# - `ncoh` Number of cohorts of uptaking patients |
20 | | -# - `uptake` Total number of uptaking patients |
21 | | -# - `sum_by_coh` Tibble of summarized calculation results for each uptake cohort |
22 | | -# - `total` Total present value |
23 | | -# - `mean` Average present value per uptaking patient (=total/uptake) |
24 | | -# @export |
| 14 | +#' @title S7 Class Representing a Dynamic Present Value object |
| 15 | +#' @description A Dynamic Present Value object has a name and a proscribed dataset. |
| 16 | +#' @param name Name of object (character string) |
| 17 | +#' @param df Dataframe of proscribed format, such as generated by [dynamicpv::dynpv()] and [dynamicpv::futurepv()]. |
| 18 | +#' @return An object of class [class_dynpv()], with additional properties: |
| 19 | +#' - `ncoh` Number of cohorts of uptaking patients |
| 20 | +#' - `uptake` Total number of uptaking patients |
| 21 | +#' - `sum_by_coh` Tibble of summarized calculation results for each uptake cohort |
| 22 | +#' - `total` Total present value |
| 23 | +#' - `mean` Average present value per uptaking patient (=total/uptake) |
| 24 | +#' @export |
| 25 | +#' @name class_dynpv |
25 | 26 | class_dynpv <- S7::new_class( |
26 | 27 | name = "class_dynpv", |
27 | 28 | properties = list( |
@@ -106,15 +107,16 @@ class_dynpv <- S7::new_class( |
106 | 107 | #`-` <- S7::new_generic("-", c("e1", "e2")) |
107 | 108 | addprod <- S7::new_generic("addprod", c("e1", "e2")) |
108 | 109 |
|
109 | | -# @title Method to add two class_dynpv S7 objects together |
110 | | -# @description Add together two objects each of S7 class `class_dynpv`: e1 + mult * e2 |
111 | | -# @param e1 First `class_dynpv` object |
112 | | -# @param e2 Second `class_dynpv` object |
113 | | -# @param mult Numeric |
114 | | -# Present value is present value from `e1` plus `mult` times the present value from `e2`. |
115 | | -# Total uptake is the uptake from `e1` plus `mult` times the uptake from `e2`. Take care of this when using `@mean` of the summed object. |
116 | | -# @returns S7 object of class `class_dynpv` |
117 | | -# @export |
| 110 | +#' @title Method to add two class_dynpv S7 objects together |
| 111 | +#' @description Add together two objects each of S7 class [class_dynpv()]: e1 + mult * e2 |
| 112 | +#' @param e1 First [class_dynpv()] object |
| 113 | +#' @param e2 Second [class_dynpv()] object |
| 114 | +#' @param mult Numeric |
| 115 | +#' Present value is present value from `e1` plus `mult` times the present value from `e2`. |
| 116 | +#' Total uptake is the uptake from `e1` plus `mult` times the uptake from `e2`. Take care of this when using `@mean` of the summed object. |
| 117 | +#' @returns S7 object of class [class_dynpv()] |
| 118 | +#' @noRd |
| 119 | +#' @name addprod.class_dynpv |
118 | 120 | S7::method(addprod, signature = list(e1 = class_dynpv, e2 = class_dynpv)) <- function(e1, e2, mult) { |
119 | 121 | # Pull out xdata and subset of ydata; add dpvno=1 or 2 depending on source |
120 | 122 | xdata <- e1@df |> |
@@ -148,30 +150,36 @@ S7::method(addprod, signature = list(e1 = class_dynpv, e2 = class_dynpv)) <- fun |
148 | 150 | ) |
149 | 151 | } |
150 | 152 |
|
151 | | -# @title Method to add two class_dynpv S7 objects together |
152 | | -# @description Add together two objects each of S7 class `class_dynpv` |
153 | | -# @param e1 First `class_dynpv` object |
154 | | -# @param e2 Second `class_dynpv` object |
155 | | -# Present value of `e1+e2` is sum of present values from `e1` and `e2`. |
156 | | -# Total uptake of `e1+e2` is sum of uptake from `e1` and `e2`. Take care of this when using `@mean` of the summed object. |
157 | | -# @returns S7 object of class `class_dynpv` |
158 | | -# @export |
| 153 | +#' @title Method to add two class_dynpv S7 objects together |
| 154 | +#' @description Add together two objects each of S7 class [class_dynpv()] |
| 155 | +#' @param e1 First [class_dynpv()] object |
| 156 | +#' @param e2 Second [class_dynpv()] object |
| 157 | +#' Present value of `e1+e2` is sum of present values from `e1` and `e2`. |
| 158 | +#' Total uptake of `e1+e2` is sum of uptake from `e1` and `e2`. Take care of this when using `@mean` of the summed object. |
| 159 | +#' @returns S7 object of class [class_dynpv()] |
| 160 | +#' @noRd |
| 161 | +#' @name `+`.class_dynpv |
159 | 162 | S7::method(`+`, signature = list(e1 = class_dynpv, e2 = class_dynpv)) <- function(e1, e2) { |
160 | 163 | addprod(e1, e2, mult=1) |
161 | 164 | } |
162 | 165 |
|
163 | | -# Method to subtract one class_dynpv S7 object from another |
164 | | -# @description Subtract one object of S7 class `class_dynpv` from another |
165 | | -# @param e1 First `class_dynpv` object |
166 | | -# @param e2 Second `class_dynpv` object |
167 | | -# Present value of `e1-e2` is the present values from `e1` less that from `e2`. |
168 | | -# Total uptake of `e1-e2` is the uptake from `e1` less that from `e2`. Take care of this when using `@mean` of the summed object. |
169 | | -# @returns S7 object of class `class_dynpv` |
| 166 | +#' @title Method to subtract one class_dynpv S7 object from another |
| 167 | +#' @description Subtract one object of S7 class [class_dynpv()] from another |
| 168 | +#' @param e1 First [class_dynpv()] object |
| 169 | +#' @param e2 Second [class_dynpv()] object |
| 170 | +#' Present value of `e1-e2` is the present values from `e1` less that from `e2`. |
| 171 | +#' Total uptake of `e1-e2` is the uptake from `e1` less that from `e2`. Take care of this when using `@mean` of the summed object. |
| 172 | +#' @returns S7 object of class [class_dynpv()] |
| 173 | +#' @noRd |
| 174 | +#' @name `-`.class_dynpv |
170 | 175 | S7::method(`-`, signature = list(e1 = class_dynpv, e2 = class_dynpv)) <- function(e1, e2) { |
171 | 176 | addprod(e1, e2, mult=-1) |
172 | 177 | } |
173 | 178 |
|
174 | | -# Define a print method for the class_dynpv class |
| 179 | +#' @title Print method for the class_dynpv class |
| 180 | +#' @description Print [class_dynpv()] objects |
| 181 | +#' @name print.class_dynpv |
| 182 | +#' @noRd |
175 | 183 | S7::method(print, class_dynpv) <- function(x, ...) { |
176 | 184 | cat("This is a dynamicpv::class_dynpv S7 object, named", x@name, ". \n") |
177 | 185 | cat(" Number of cohorts: ", x@ncoh, "\n") |
|
0 commit comments