Skip to content

Commit b382d4c

Browse files
pre-release other utils functions document update (#676)
part of #624 --------- Signed-off-by: kartikeya kirar <kirar.kartikeya1@gmail.com> Co-authored-by: Vedha Viyash <49812166+vedhav@users.noreply.github.com>
1 parent 2d70eab commit b382d4c

25 files changed

+199
-212
lines changed

R/data.R

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,39 @@
11
#' Random adverse events
2-
#'
3-
#' @description Random adverse events
42
#' @docType data
5-
#'
63
#' @usage rADAE
7-
#'
84
#' @keywords datasets internal
9-
#'
105
#' @source internal
116
#' @name rADAE
127
"rADAE"
138

149
#' Random lab analysis
15-
#'
16-
#' @description Random lab analysis
1710
#' @docType data
18-
#'
1911
#' @usage rADLB
20-
#'
2112
#' @keywords datasets internal
22-
#'
2313
#' @source internal
2414
#' @name rADLB
2515
"rADLB"
2616

2717
#' Random response
28-
#'
29-
#' @description Random response
3018
#' @docType data
31-
#'
3219
#' @usage rADRS
33-
#'
3420
#' @keywords datasets internal
35-
#'
3621
#' @source internal
3722
#' @name rADRS
3823
"rADRS"
3924

4025
#' Random patient listing
41-
#'
42-
#' @description Random patient listing
4326
#' @docType data
44-
#'
4527
#' @usage rADSL
46-
#'
4728
#' @keywords datasets internal
48-
#'
4929
#' @source internal
5030
#' @name rADSL
5131
"rADSL"
5232

53-
#' Random Time to Event Analysis Dataset
54-
#'
55-
#' @description Random Time to Event Analysis Dataset
33+
#' Random time to event analysis dataset
5634
#' @docType data
57-
#'
5835
#' @usage rADTTE
59-
#'
6036
#' @keywords datasets internal
61-
#'
6237
#' @source internal
6338
#' @name rADTTE
6439
"rADTTE"

R/teal.modules.general.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' teal.modules.general: General modules to add to a teal application
1+
#' `teal.modules.general`: General modules to add to a teal application
22
#'
33
#' The modules in this package are generic modules that should work with any data set
44
#' (not necessarily for clinical trials data).

R/utils.R

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,59 @@
1-
#' Shared Parameters
1+
#' Shared parameters documentation
22
#'
3-
#' @description Contains arguments that are shared between multiple functions
4-
#' in the package to avoid repetition using `inheritParams`.
3+
#' Defines common arguments shared across multiple functions in the package
4+
#' to avoid repetition by using `inheritParams`.
55
#'
6-
#' @param plot_height optional, (`numeric`) A vector of length three with `c(value, min and max)`
7-
#' for a slider encoding the plot height.
8-
#' @param plot_width optional, (`numeric`) A vector of length three with `c(value, min and max)`
9-
#' for a slider encoding the plot width.
6+
#' @param plot_height optional, (`numeric`) Specifies the plot height as a three-element vector of
7+
#' `value`, `min`, and `max` intended for use with a slider UI element.
8+
#' @param plot_width optional, (`numeric`) Specifies the plot width as a three-element vector of
9+
#' `value`, `min`, and `max` for a slider encoding the plot width.
1010
#' @param rotate_xaxis_labels optional, (`logical`) Whether to rotate plot X axis labels. Does not
11-
#' rotate by default (`FALSE`).
11+
#' rotate by default (`FALSE`).
1212
#' @param ggtheme optional, (`character`) `ggplot2` theme to be used by default. Defaults to `"gray"`.
1313
#' @param ggplot2_args (`ggplot2_args`) object created by [teal.widgets::ggplot2_args()]
14-
#' with settings for the module plot.
15-
#' The argument is merged with options variable `teal.ggplot2_args` and default module setup.
14+
#' with settings for the module plot.
15+
#' The argument is merged with options variable `teal.ggplot2_args` and default module setup.
1616
#'
17-
#' For more details see the vignette: `vignette("custom-ggplot2-arguments", package = "teal.widgets")`
17+
#' For more details see the vignette: `vignette("custom-ggplot2-arguments", package = "teal.widgets")`
1818
#' @param basic_table_args (`basic_table_args`) object created by [teal.widgets::basic_table_args()]
19-
#' with settings for the module table.
20-
#' The argument is merged with options variable `teal.basic_table_args` and default module setup.
19+
#' with settings for the module table.
20+
#' The argument is merged with options variable `teal.basic_table_args` and default module setup.
2121
#'
22-
#' For more details see the vignette: `vignette("custom-basic-table-arguments", package = "teal.widgets")`
23-
#' @param pre_output (`shiny.tag`, optional)\cr
22+
#' For more details see the vignette: `vignette("custom-basic-table-arguments", package = "teal.widgets")`
23+
#' @param pre_output (`shiny.tag`, optional) Text or UI element to be displayed before the module's output,
24+
#' providing context or a title.
2425
#' with text placed before the output to put the output into context. For example a title.
25-
#' @param post_output (`shiny.tag`, optional) with text placed after the output to put the output
26-
#' into context. For example the [shiny::helpText()] elements are useful.
26+
#' @param post_output (`shiny.tag`, optional) Text or UI element to be displayed after the module's output,
27+
#' adding context or further instructions. Elements like `shiny::helpText()` are useful.
2728
#'
2829
#' @return Object of class `teal_module` to be used in `teal` applications.
2930
#'
3031
#' @name shared_params
3132
#' @keywords internal
3233
NULL
3334

34-
#' Add axis labels that show facetting variable
35+
#' Add labels for facets to a ggplot2 object
3536
#'
36-
#' Add axis labels that show facetting variable
37+
#' Enhances a ggplot2 plot by adding labels that describe
38+
#' the faceting variables along the x and y axes.
3739
#'
38-
#' @param p `ggplot2` object to add facet labels to
39-
#' @param xfacet_label label of facet along x axis (nothing created if NULL),
40-
#' if vector, will be concatenated with " & "
41-
#' @param yfacet_label label of facet along y axis (nothing created if NULL),
42-
#' if vector, will be concatenated with " & "
40+
#' @param p (`ggplot2`) object to which facet labels will be added.
41+
#' @param xfacet_label (`character`) Label for the facet along the x-axis.
42+
#' If `NULL`, no label is added. If a vector, labels are joined with " & ".
43+
#' @param yfacet_label (`character`) Label for the facet along the y-axis.
44+
#' Similar behavior to `xfacet_label`.
4345
#'
44-
#' @return grid grob object (to be drawn with \code{grid.draw})
45-
#'
46-
#' @export
46+
#' @return Returns `grid` or `grob` object (to be drawn with `grid.draw`)
4747
#'
4848
#' @examples
49-
#' # we put donttest to avoid strictr error with seq along.with argument
50-
#' \donttest{
5149
#' library(ggplot2)
5250
#' library(grid)
5351
#'
5452
#' p <- ggplot(mtcars) +
5553
#' aes(x = mpg, y = disp) +
5654
#' geom_point() +
5755
#' facet_grid(gear ~ cyl)
58-
#' p
56+
#'
5957
#' xfacet_label <- "cylinders"
6058
#' yfacet_label <- "gear"
6159
#' res <- add_facet_labels(p, xfacet_label, yfacet_label)
@@ -68,7 +66,8 @@ NULL
6866
#' grid.draw(add_facet_labels(p, xfacet_label, yfacet_label = NULL))
6967
#' grid.newpage()
7068
#' grid.draw(add_facet_labels(p, xfacet_label = NULL, yfacet_label = NULL))
71-
#' }
69+
#'
70+
#' @export
7271
#'
7372
add_facet_labels <- function(p, xfacet_label = NULL, yfacet_label = NULL) {
7473
checkmate::assert_class(p, classes = "ggplot")
@@ -122,46 +121,42 @@ add_facet_labels <- function(p, xfacet_label = NULL, yfacet_label = NULL) {
122121

123122
#' Call a function with a character vector for the \code{...} argument
124123
#'
125-
#' @param fun (\code{character}) Name of a function where the \code{...} argument
124+
#' @param fun (`character`) Name of a function where the \code{...} argument
126125
#' shall be replaced by values from \code{str_args}.
127-
#' @param str_args (\code{character}) A character vector that the function shall
126+
#' @param str_args (`character`) A character vector that the function shall
128127
#' be executed with
129128
#'
130-
#' @return: call (i.e. expression) of the function provided by \code{fun}
129+
#' @return Call (i.e. expression) of the function provided by \code{fun}
131130
#' with arguments provided by \code{str_args}.
132-
#' @keywords internal
133131
#'
134132
#' @examples
135-
#' \dontrun{
133+
#' call_fun_dots <- getFromNamespace("call_fun_dots", "teal.modules.general")
134+
#'
136135
#' a <- 1
137136
#' b <- 2
138137
#' call_fun_dots("sum", c("a", "b"))
139138
#' eval(call_fun_dots("sum", c("a", "b")))
140-
#' }
139+
#'
140+
#' @keywords internal
141+
#'
141142
call_fun_dots <- function(fun, str_args) {
142143
do.call("call", c(list(fun), lapply(str_args, as.name)), quote = TRUE)
143144
}
144145

145-
#' Get variable name with label
146+
#' Generate a string for a variable including its label
146147
#'
147-
#' @param var_names (\code{character}) Name of variable to extract labels from.
148-
#' @param dataset (\code{dataset}) Name of analysis dataset.
149-
#' @param prefix (\code{character}) String to paste to the beginning of the
148+
#' @param var_names (`character`) Name of variable to extract labels from.
149+
#' @param dataset (`dataset`) Name of analysis dataset.
150+
#' @param prefix (`character`) String to paste to the beginning of the
150151
#' variable name with label.
151-
#' @param suffix (\code{character}) String to paste to the end of the variable
152+
#' @param suffix (`character`) String to paste to the end of the variable
152153
#' name with label.
153-
#' @param wrap_width (\code{numeric}) Number of characters to wrap original
154+
#' @param wrap_width (`numeric`) Number of characters to wrap original
154155
#' label to. Defaults to 80.
155156
#'
156-
#' @return (\code{character}) String with variable name and label.
157+
#' @return (`character`) String with variable name and label.
157158
#' @keywords internal
158159
#'
159-
#' @examples
160-
#' \dontrun{
161-
#' ADSL <- teal.modules.general::rADSL
162-
#'
163-
#' varname_w_label("AGE", ADSL)
164-
#' }
165160
varname_w_label <- function(var_names,
166161
dataset,
167162
wrap_width = 80,
@@ -205,17 +200,20 @@ shape_names <- c(
205200
#' Get icons to represent variable types in dataset
206201
#'
207202
#' @param var_type (`character`)\cr
208-
#' of R internal types (classes).
203+
#' of `R` internal types (classes).
209204
#'
210-
#' @return (`character`)\cr
211-
#' vector of HTML icons corresponding to data type in each column.
212-
#' @keywords internal
205+
#' @return Vector of HTML icons corresponding to data type in each column.
213206
#'
214207
#' @examples
215-
#' teal.modules.general:::variable_type_icons(c(
208+
#' variable_type_icons <- getFromNamespace("variable_type_icons", "teal.modules.general")
209+
#'
210+
#' variable_type_icons(c(
216211
#' "integer", "numeric", "logical", "Date", "POSIXct", "POSIXlt",
217212
#' "factor", "character", "unknown", ""
218213
#' ))
214+
#'
215+
#' @keywords internal
216+
#'
219217
variable_type_icons <- function(var_type) {
220218
checkmate::assert_character(var_type, any.missing = FALSE)
221219

@@ -256,10 +254,11 @@ variable_type_icons <- function(var_type) {
256254
#' not work with `devtools`. Therefore, we redefine this method in each package
257255
#' as needed. Thus, we do not export this method
258256
#'
259-
#' @param pattern (`character`) pattern of files to be included
257+
#' @param pattern (`character`) optional regular expression to match the file names to be included.
260258
#'
261-
#' @return HTML code that includes `CSS` files
259+
#' @return HTML code that includes `CSS` files.
262260
#' @keywords internal
261+
#'
263262
include_css_files <- function(pattern = "*") {
264263
css_files <- list.files(
265264
system.file("css", package = "teal.modules.general", mustWork = TRUE),
@@ -271,12 +270,14 @@ include_css_files <- function(pattern = "*") {
271270
return(shiny::singleton(shiny::tags$head(lapply(css_files, shiny::includeCSS))))
272271
}
273272

274-
275-
#' Get a string with java-script code checking if the specific tab is clicked
276-
#' @description will be the input for `shiny::conditionalPanel()`
277-
#' @param id `character(1)` the id of the tab panel with tabs.
278-
#' @param name `character(1)` the name of the tab.
273+
#' JavaScript condition to check if a specific tab is active
274+
#'
275+
#' @param id (`character(1)`) the id of the tab panel with tabs.
276+
#' @param name (`character(1)`) the name of the tab.
277+
#' @return JavaScript expression to be used in `shiny::conditionalPanel()` to determine
278+
#' if the specified tab is active.
279279
#' @keywords internal
280+
#'
280281
is_tab_active_js <- function(id, name) {
281282
# supporting the bs3 and higher version at the same time
282283
sprintf(

man/add_facet_labels.Rd

Lines changed: 10 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/call_fun_dots.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/include_css_files.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)