Skip to content

Commit 7765c0b

Browse files
committed
examples ::: R/call_utils.R
1 parent 05f4deb commit 7765c0b

File tree

1 file changed

+74
-39
lines changed

1 file changed

+74
-39
lines changed

R/call_utils.R

Lines changed: 74 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ call_check_parse_varname <- function(varname) {
4949
#' }
5050
#'
5151
#' @examples
52-
#' teal.transform:::call_condition_choice("SEX", choices = c(1, 2))
53-
#' teal.transform:::call_condition_choice(as.name("SEX"), choices = "F")
54-
#' teal.transform:::call_condition_choice("SEX", choices = c("F", "M"))
55-
#' teal.transform:::call_condition_choice("SEX", choices = factor(c("F", "M")))
56-
#' teal.transform:::call_condition_choice("x$SEX", choices = Sys.Date())
57-
#' teal.transform:::call_condition_choice("trunc(x$SEX)", choices = Sys.time())
52+
#' # use non-exported function from teal.transform
53+
#' call_condition_choice <- getFromNamespace("call_condition_choice", "teal.transform")
54+
#'
55+
#' call_condition_choice("SEX", choices = c(1, 2))
56+
#' call_condition_choice(as.name("SEX"), choices = "F")
57+
#' call_condition_choice("SEX", choices = c("F", "M"))
58+
#' call_condition_choice("SEX", choices = factor(c("F", "M")))
59+
#' call_condition_choice("x$SEX", choices = Sys.Date())
60+
#' call_condition_choice("trunc(x$SEX)", choices = Sys.time())
5861
#' @return a `call`
5962
#' @keywords internal
6063
call_condition_choice <- function(varname, choices) {
@@ -95,10 +98,14 @@ call_condition_choice <- function(varname, choices) {
9598
#'
9699
#' @return call
97100
#' @examples
98-
#' teal.transform:::call_condition_range("AGE", range = c(1, 2))
99-
#' teal.transform:::call_condition_range(as.name("AGE"), range = c(-1.2, 2.1))
100-
#' teal.transform:::call_condition_range(
101-
#' teal.transform:::call_extract_list("ADSL", "AGE"),
101+
#' # use non-exported function from teal.transform
102+
#' call_condition_range <- getFromNamespace("call_condition_range", "teal.transform")
103+
#' call_extract_list <- getFromNamespace("call_extract_list", "teal.transform")
104+
#'
105+
#' call_condition_range("AGE", range = c(1, 2))
106+
#' call_condition_range(as.name("AGE"), range = c(-1.2, 2.1))
107+
#' call_condition_range(
108+
#' call_extract_list("ADSL", "AGE"),
102109
#' range = c(-1.2, 2.1)
103110
#' )
104111
#' @return a `call`
@@ -126,8 +133,11 @@ call_condition_range <- function(varname, range) {
126133
#'
127134
#' @return call
128135
#' @examples
129-
#' teal.transform:::call_condition_logical("event", choice = TRUE)
130-
#' teal.transform:::call_condition_logical("event", choice = FALSE)
136+
#' # use non-exported function from teal.transform
137+
#' call_condition_logical <- getFromNamespace("call_condition_logical", "teal.transform")
138+
#'
139+
#' call_condition_logical("event", choice = TRUE)
140+
#' call_condition_logical("event", choice = FALSE)
131141
#' @return a `call`
132142
#' @keywords internal
133143
call_condition_logical <- function(varname, choice) {
@@ -164,7 +174,12 @@ call_condition_logical <- function(varname, choice) {
164174
#' By default `Sys.timezone()` is used.
165175
#'
166176
#' @examples
167-
#' teal.transform:::call_condition_range_posixct(
177+
#' # use non-exported function from teal.transform
178+
#' call_condition_range_posixct <- getFromNamespace(
179+
#' "call_condition_range_posixct", "teal.transform"
180+
#' )
181+
#'
182+
#' call_condition_range_posixct(
168183
#' varname = as.name("datetime"),
169184
#' range = c(Sys.time(), Sys.time() + 1),
170185
#' timezone = "UTC"
@@ -203,7 +218,10 @@ call_condition_range_posixct <- function(varname, range, timezone = Sys.timezone
203218
#' range of the variable
204219
#'
205220
#' @examples
206-
#' teal.transform:::call_condition_range_date(
221+
#' # use non-exported function from teal.transform
222+
#' call_condition_range_date <- getFromNamespace("call_condition_range_date", "teal.transform")
223+
#'
224+
#' call_condition_range_date(
207225
#' as.name("date"),
208226
#' range = c(Sys.Date(), Sys.Date() + 1)
209227
#' )
@@ -233,15 +251,19 @@ call_condition_range_date <- function(varname, range) {
233251
#' optional, name of the `row` or condition
234252
#' @return `[` call with all conditions included
235253
#' @examples
236-
#' teal.transform:::call_extract_array(
254+
#' # use non-exported function from teal.transform
255+
#' call_extract_array <- getFromNamespace("call_extract_array", "teal.transform")
256+
#' call_condition_choice <- getFromNamespace("call_condition_choice", "teal.transform")
257+
#'
258+
#' call_extract_array(
237259
#' dataname = "my_array",
238-
#' row = teal.transform:::call_condition_choice("my_array$SEX", "M"),
260+
#' row = call_condition_choice("my_array$SEX", "M"),
239261
#' column = call("c", "SEX", "AGE"),
240262
#' aisle = "RNAseq_rnaaccess"
241263
#' )
242-
#' teal.transform:::call_extract_array(
264+
#' call_extract_array(
243265
#' "mae_object",
244-
#' column = teal.transform:::call_condition_choice("SEX", "M")
266+
#' column = call_condition_choice("SEX", "M")
245267
#' )
246268
#' @return specific \code{\link[base]{Extract}} `call` for 3-dimensional array
247269
#' @keywords internal
@@ -291,14 +313,18 @@ call_extract_array <- function(dataname = ".", row = NULL, column = NULL, aisle
291313
#' optional, name of the `column` or condition
292314
#' @return `[` call with all conditions included
293315
#' @examples
294-
#' teal.transform:::call_extract_matrix(
316+
#' # use non-exported function from teal.transform
317+
#' call_extract_matrix <- getFromNamespace("call_extract_matrix", "teal.transform")
318+
#' call_condition_choice <- getFromNamespace("call_condition_choice", "teal.transform")
319+
#'
320+
#' call_extract_matrix(
295321
#' dataname = "my_array",
296-
#' row = teal.transform:::call_condition_choice("my_array$SEX", "M"),
322+
#' row = call_condition_choice("my_array$SEX", "M"),
297323
#' column = call("c", "SEX", "AGE")
298324
#' )
299-
#' teal.transform:::call_extract_matrix(
325+
#' call_extract_matrix(
300326
#' "mae_object",
301-
#' column = teal.transform:::call_condition_choice("SEX", "M")
327+
#' column = call_condition_choice("SEX", "M")
302328
#' )
303329
#' @return specific \code{\link[base]{Extract}} `call` for matrix
304330
#' @keywords internal
@@ -348,11 +374,14 @@ call_extract_matrix <- function(dataname = ".", row = NULL, column = NULL) {
348374
#'
349375
#' @return `$` or `[[` call
350376
#' @examples
351-
#' teal.transform:::call_extract_list("ADSL", "SEX")
352-
#' teal.transform:::call_extract_list("ADSL", "named element")
353-
#' teal.transform:::call_extract_list(as.name("ADSL"), as.name("AGE"))
354-
#' teal.transform:::call_extract_list(as.name("weird name"), as.name("AGE"))
355-
#' teal.transform:::call_extract_list(as.name("ADSL"), "AGE", dollar = FALSE)
377+
#' # use non-exported function from teal.transform
378+
#' call_extract_list <- getFromNamespace("call_extract_list", "teal.transform")
379+
#'
380+
#' call_extract_list("ADSL", "SEX")
381+
#' call_extract_list("ADSL", "named element")
382+
#' call_extract_list(as.name("ADSL"), as.name("AGE"))
383+
#' call_extract_list(as.name("weird name"), as.name("AGE"))
384+
#' call_extract_list(as.name("ADSL"), "AGE", dollar = FALSE)
356385
#' @keywords internal
357386
call_extract_list <- function(dataname, varname, dollar = TRUE) {
358387
checkmate::assert_flag(dollar)
@@ -386,23 +415,24 @@ call_extract_list <- function(dataname, varname, dollar = TRUE) {
386415
#' @param unlist_args `list` extra arguments passed in a single list,
387416
#' avoids the use of `do.call` with this function
388417
#' @examples
418+
#' # use non-exported function from teal.transform
419+
#' call_with_colon <- getFromNamespace("call_with_colon", "teal.transform")
389420
#'
390-
#' print_call_and_eval <- function(x) {
391-
#' eval(print(x))
392-
#' }
421+
#' print_call_and_eval <- function(x) eval(print(x))
393422
#'
394423
#' print_call_and_eval(
395-
#' teal.transform:::call_with_colon("glue::glue", "x = {x}", x = 10)
424+
#' call_with_colon("glue::glue", "x = {x}", x = 10)
396425
#' )
426+
#'
397427
#' \dontrun{
398428
#' # mtcars$cyl evaluated
399429
#' print_call_and_eval(
400-
#' teal.transform:::call_with_colon("dplyr::filter", as.name("mtcars"), mtcars$cyl == 6)
430+
#' call_with_colon("dplyr::filter", as.name("mtcars"), mtcars$cyl == 6)
401431
#' )
402432
#'
403433
#' # mtcars$cyl argument not evaluated immediately (in call expression)
404434
#' print_call_and_eval(
405-
#' teal.transform:::call_with_colon("dplyr::filter", as.name("mtcars"), quote(cyl == 6))
435+
#' call_with_colon("dplyr::filter", as.name("mtcars"), quote(cyl == 6))
406436
#' )
407437
#'
408438
#' # does not work because argument is evaluated and the
@@ -414,11 +444,11 @@ call_extract_list <- function(dataname, varname, dollar = TRUE) {
414444
#'
415445
#' nb_args <- function(...) nargs()
416446
#' print_call_and_eval(
417-
#' teal.transform:::call_with_colon("nb_args", arg1 = 1, unlist_args = list(arg2 = 2, args3 = 3))
447+
#' call_with_colon("nb_args", arg1 = 1, unlist_args = list(arg2 = 2, args3 = 3))
418448
#' )
419449
#' # duplicate arguments
420450
#' print_call_and_eval(
421-
#' teal.transform:::call_with_colon("nb_args", arg1 = 1, unlist_args = list(arg2 = 2, args2 = 2))
451+
#' call_with_colon("nb_args", arg1 = 1, unlist_args = list(arg2 = 2, args2 = 2))
422452
#' )
423453
#' }
424454
#' @keywords internal
@@ -444,12 +474,17 @@ call_with_colon <- function(name, ..., unlist_args = list()) {
444474
#'
445475
#' @return call
446476
#' @examples
447-
#' teal.transform:::calls_combine_by(
477+
#' # use non-exported function from teal.transform
478+
#' calls_combine_by <- getFromNamespace("calls_combine_by", "teal.transform")
479+
#' call_condition_choice <- getFromNamespace("call_condition_choice", "teal.transform")
480+
#' call_condition_range <- getFromNamespace("call_condition_range", "teal.transform")
481+
#'
482+
#' calls_combine_by(
448483
#' "&",
449484
#' calls = list(
450-
#' teal.transform:::call_condition_choice("SEX", "F"),
451-
#' teal.transform:::call_condition_range("AGE", c(20, 50)),
452-
#' teal.transform:::call_condition_choice("ARM", "ARM: A"),
485+
#' call_condition_choice("SEX", "F"),
486+
#' call_condition_range("AGE", c(20, 50)),
487+
#' call_condition_choice("ARM", "ARM: A"),
453488
#' TRUE
454489
#' )
455490
#' )

0 commit comments

Comments
 (0)