ropensci / chlorpromazineR

@@ -22,9 +22,9 @@
Loading
22 22
#' conversion factors
23 23
#' @param route_label if "mixed" route is specified, provide the column that
24 24
#' stores the route information
25 -
#' @param q_label if long-acting injectable doses are included, provide the column
26 -
#' that stores the injection frequency (days), or only if the doses have already
27 -
#' been divided, set q_label = 1.
25 +
#' @param q_label if long-acting injectable doses are included, provide the 
26 +
#' column that stores the injection frequency (days), or only if the doses have
27 +
#' already been divided, set q_label = 1.
28 28
#' @return data.frame with new variables storing conversion factor and 
29 29
#' CPZ-equivalent doses
30 30
#' @family conversion functions
@@ -65,8 +65,15 @@
Loading
65 65
    x[, factor_label] <- as.numeric(key[[route]][x[, ap_label]])
66 66
    x[, eq_label] <- apply(x[, c(dose_label, factor_label)], 1, prod)
67 67
68 -
    if (route == "lai" && q_label != 1) x[, eq_label] <- x[, eq_label] /
69 -
                                                                   x[, q_label]
68 +
    if (route == "lai") {
69 +
      if (is.null(q_label)) {
70 +
        stop("q_label must be specified for lai route.")
71 +
      }
72 +
      if (q_label != 1) {
73 +
        x[, eq_label] <- x[, eq_label] / x[, q_label]
74 +
    }
75 +
  } 
76 +
                                                                   
70 77
  }
71 78
72 79
  if (route == "mixed") {
@@ -230,12 +237,24 @@
Loading
230 237
                  ref_eq_label="ap_eq", factor_label="cpz_conv_factor",
231 238
                  route_label=NULL, q_label=NULL) {
232 239
  
240 +
  if (route == "sai") {
241 +
    if (convert_to_route != "sai") {
242 +
      stop("For \"sai\" route, convert_to_route must be \"sai\" as well.")
243 +
    }
244 +
  }
245 +
233 246
  check_params(input_data, ap_label, dose_label, route, eq_label=cpz_eq_label,
234 247
               factor_label, route_label, q_label)
235 248
  check_key(key)
236 249
  
237 250
  if (!(convert_to_ap %in% names(key[[convert_to_route]]))) {
238 -
      stop("The specified convert_to antipsychotic/route is not in the key")
251 +
    stop("The specified convert_to antipsychotic/route is not in the key")
252 +
  }
253 +
254 +
  if (route == "sai") {
255 +
    if (convert_to_route != "sai") {
256 +
      stop("For \"sai\" route, convert_to_route must be \"sai\" as well.")
257 +
    }
239 258
  }
240 259
  
241 260
  out <- to_cpz(input_data = input_data, ap_label = ap_label,
@@ -271,7 +290,7 @@
Loading
271 290
      stop("route_label should be null if route is not mixed.")
272 291
    }
273 292
  }
274 -
  
293 +
275 294
  if (!(is.character(eq_label))) {
276 295
    stop("eq_label/cpz_eq_label must be a character string.")
277 296
  }
Files Coverage
R 86.16%
Project Totals (2 files) 86.16%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading