-
Notifications
You must be signed in to change notification settings - Fork 1
/
ruminate.R
154 lines (130 loc) · 4.29 KB
/
ruminate.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#' ruminate: Shiny app and module to facilitate pharamacometrics analysis
#'
#' This is done by creating a Shiny interface to different tools for data
#' transformation (`dplyr` and `tidyr`), plotting (`ggplot2`), and
#' noncompartmental analysis (`PKNCA`). These results can be reported in Excel,
#' Word or PowerPoint. The state of the app can be saved and loaded at a later
#' date. When saved, a script is generated to reproduce the different actions in
#' the Shiny interface.
#'
#' @seealso \url{https://ruminate.ubiquity.tools/}
#' @docType package
#' @name ruminate
"_PACKAGE"
#'@import shiny
.onLoad <- function(libname, pkgname){
#------------------------------------
# Checking for rxpackages
# If all the suggested packages are found this will be true:
suggested_found = TRUE
#mr = FM_message("Loading ruminate", entry_type="h1")
#mr = FM_message("Checking for required nlmixr2 family of tools", entry_type="h2")
pkgs = c("rxode2", "nonmem2rx", "nlmixr2lib", "rxode2et")
for(pkg in pkgs){
pkg_var = paste0("ruminate_", pkg, "_found")
if(!requireNamespace(pkg, quietly=TRUE)){
pkg_val = FALSE
suggested_found = FALSE
#mr = FM_message(paste0("missing ", pkg), entry_type="danger")
} else {
pkg_val = TRUE
#mr = FM_message(paste0("found ", pkg), entry_type="success")
}
eval(parse( text= paste0("Sys.setenv(", pkg_var, "=", pkg_val,")") ))
}
Sys.setenv(ruminate_rxfamily_found = suggested_found)
}
#'@export
#'@title Checks `ruminate` Dependencies
#'@description Looks at the suggested dependencies and checks to make sure
#'they are installed.
#'@param verbose Logical indicating if messages should be displayed
#'@return List with the following elements:
#' \itemize{
#' \item{all_found:} Boolean indicating if all packages were found
#' \item{found_pkgs:} Character vector of found packages
#' \item{missing_pkgs:} Character vector of missing packages
#'}
#'@examples
#' fcres =ruminate_check()
ruminate_check <- function(verbose=TRUE){
#------------------------------------
# Checking for rxpackages
# If all the suggested packages are found this will be true:
suggested_found = TRUE
if(verbose){
mr = FM_message("Checking ruminate for suggested packages", entry_type="h1")
}
pkgs = c(
"clipr",
"gridExtra",
"knitr",
"nlmixr2lib",
"nonmem2rx",
"prompter",
"rmarkdown",
"readxl",
"rxode2et",
"shinydashboard",
"testthat",
"ubiquity")
pkg_found = c()
pkg_missing = c()
for(pkg in pkgs){
if(!requireNamespace(pkg, quietly=TRUE)){
if(verbose){
mr = FM_message(paste0("missing ", pkg), entry_type="danger")
}
pkg_missing = c(pkg_missing, pkg)
suggested_found = FALSE
} else {
if(verbose){
mr = FM_message(paste0("found ", pkg), entry_type="success")
}
pkg_found = c(pkg_found , pkg)
}
}
res = list(
all_found = suggested_found,
found_pkgs = pkg_found,
missing_pkgs = pkg_missing
)
res}
#'@export
#'@title Run the {ruminate} Shiny App
#'@description Runs the pharmacometrics ruminate app.
#'@param host Hostname of the server ("127.0.0.1")
#'@param port Port number for the app (3838)
#'@param server_opts List of options (names) and their vlues (value) e.g.
#'\code{list(shiny.maxRequestSize = 30 * 1024^2)}.
#'@param mksession Boolean value, when TRUE will load test session data
#'for app testing
#'@return Nothing is returned, this function just runs the built-in ruminate
#'app.
#'@examples
#'if (interactive()) {
#' ruminate()
#'}
ruminate = function(host = "127.0.0.1",
port = 3838,
server_opts = list(shiny.maxRequestSize = 30 * 1024^2),
mksession = FALSE){
if(exists("server_opts")){
for(oname in names(server_opts)){
eval(parse(text=paste0('options(',oname,'= server_opts[[oname]])')))
}
}
# File used to indicate we're in test mode
ftmptest = file.path(tempdir(), "ruminate.test")
# Deleteing any existing files
if(file.exists(ftmptest)){
unlink(ftmptest)
}
# If mksession is true we create the temporary file
if(mksession){
file.create(ftmptest)
}
shiny::runApp(system.file(package="ruminate", "templates","ruminate.R"),
host = host,
port = port)
}