VeenaLim commited on
Commit
c26ce43
·
verified ·
1 Parent(s): 49be005

Delete api/plumber.R

Browse files
Files changed (1) hide show
  1. api/plumber.R +0 -70
api/plumber.R DELETED
@@ -1,70 +0,0 @@
1
- library(dampack)
2
- library(readr)
3
- library(assertthat)
4
-
5
- #* @apiTitle Client API hosting sensitive data
6
- #*
7
- #* @apiDescription This API contains sensitive data, the client does not
8
- #* want to share this data but does want a consultant to build a health
9
- #* economic model using it, and wants that consultant to be able to run
10
- #* the model for various inputs
11
- #* (while holding certain inputs fixed and leaving them unknown).
12
-
13
- #* Run the DARTH model
14
- #* @serializer csv
15
- #* @param path_to_psa_inputs is the path of the csv file containing the PSA parameters
16
- #* @param model_functions gives the GitHub repo to source the model code
17
- #* @param param_updates gives the replacement values of the editable parameters
18
- #* @post /runDARTHmodel
19
- function(path_to_psa_inputs = "parameter_distributions.csv",
20
- model_functions = paste0("https://raw.githubusercontent.com/",
21
- "BresMed/plumberHE/main/R/darth_funcs.R"),
22
- param_updates = data.frame(
23
- parameter = c("p_HS1", "p_S1H"),
24
- distribution = c("beta", "beta"),
25
- v1 = c(25, 50),
26
- v2 = c(150, 70)
27
- )) {
28
-
29
-
30
- # source the model functions from the shared GitHub repo...
31
- source(model_functions)
32
-
33
- # read in the csv containing parameter inputs
34
- psa_inputs <- as.data.frame(readr::read_csv(path_to_psa_inputs))
35
-
36
- # for each row of the data-frame containing the variables to be changed...
37
- for(n in 1:nrow(param_updates)){
38
-
39
- # update parameters from API input
40
- psa_inputs <- overwrite_parameter_value(
41
- existing_df = psa_inputs,
42
- parameter = param_updates[n,"parameter"],
43
- distribution = param_updates[n,"distribution"],
44
- v1 = param_updates[n,"v1"],
45
- v2 = param_updates[n,"v2"])
46
- }
47
-
48
- # run the model using the single run-model function.
49
- results <- run_model(psa_inputs)
50
-
51
- # check that the model results being returned are the correct dimensions
52
- # here we expect a single dataframe with 6 columns and 1000 rows
53
- assertthat::assert_that(
54
- all(dim(x = results) == c(1000, 6)),
55
- class(results) == "data.frame",
56
- msg = "Dimensions or type of data are incorrect,
57
- please check the model code is correct or contact an administrator.
58
- This has been logged"
59
- )
60
-
61
- # check that no data matching the sensitive csv data is included in the output
62
- # searches through the results data-frame for any of the parameter names,
63
- # if any exist they will flag a TRUE, therefore we assert that all = F
64
- assertthat::assert_that(all(psa_inputs[, 1] %in%
65
- as.character(unlist(x = results,
66
- recursive = T)) == F))
67
-
68
- return(results)
69
-
70
- }