Skip to content

Commit 028d693

Browse files
authored
Merge pull request #57 from Boehringer-Ingelheim/test
Release Candidate 2.1.10
2 parents db57029 + 453b571 commit 028d693

62 files changed

Lines changed: 5963 additions & 355 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.lintr.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
linters <- lintr::default_linters # -[ diff with dv.templates 3ca8d7a10cfc7ad2307644dcac603e1f1f0feb72]-
2+
linters <- lintr::modify_defaults(
3+
linters
4+
, line_length_linter = NULL # we see how long lines are when we write them
5+
, indentation_linter = NULL
6+
, trailing_whitespace_linter = NULL
7+
, cyclocomp_linter = NULL # prevents trivial amount of nesting and long but straightforward functions
8+
, object_name_linter = NULL # we have reasons to capitalize. nobody in our team CamelCase. shiny does
9+
, object_length_linter = NULL # we don't type long var names just because
10+
, pipe_continuation_linter = NULL # wickham being overly prescriptive
11+
, trailing_blank_lines_linter = NULL # natural extension of trailing_whitespace_linter, present on the template
12+
)
13+
14+
if(identical(Sys.getenv('CI'), "true")){
15+
linters <- lintr::modify_defaults(
16+
linters
17+
, object_usage_linter = NULL # R lacks var declarations; it's easy to assign to the wrong variable by mistake
18+
) # We only disable this lint rule on github because it fails there because
19+
} # of a long-standing lintr bug
20+
21+
exclusions <- list("tests")

DESCRIPTION

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: dv.manager
22
Type: Package
33
Title: DaVinci Module Manager
4-
Version: 2.1.5
4+
Version: 2.1.10
55
Authors@R: c(person("Boehringer-Ingelheim Pharma GmbH & Co.KG", role = c("cph", "fnd")),
66
person('Luis', 'Morís Fernández', email = 'luis.moris.fernandez@gmail.com', role = c('cre', 'aut')),
77
person('Sorin', 'Voicu', email = 'sorin.voicu.ext@boehringer-ingelheim.com', role = c('aut')))
@@ -24,6 +24,9 @@ Imports:
2424
httr (>= 1.4.2),
2525
checkmate (>= 2.1.0),
2626
cli (>= 3.3.0),
27+
jsonlite,
28+
jsonvalidate,
29+
shinyWidgets,
2730
digest
2831
Encoding: UTF-8
2932
LazyData: true

NAMESPACE

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
S3method("$",pack_of_constants)
4-
S3method("[",pack_of_constants)
5-
S3method("[[",pack_of_constants)
63
export("%>%")
74
export(add_date_range)
85
export(build_secure_arguments)

NEWS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# dv.manager 2.1.10
2+
3+
- Includes a new blockly filter in development mode
4+
- Updates old documentation
5+
- De-exports several util functions
6+
- `dv.manager` automatically maps `character` variables into `factors`
7+
- Fixes tab group menu rendering
8+
9+
110
# dv.manager 2.1.5
211

312
- dv.manager dataset filters are now deactivated by default and can be activated by setting `enable_dataset_filter` parameter in `run_app`.

R/aaa_preface.R

Lines changed: 129 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,135 @@
11
# THIS FILE IS NAMED aaa_preface.R SO IT IS LOADED BEFORE ALL OTHER FILES
22
# DO NOT CHANGE ITS NAME. IT MUST BE THE FIRST ONE ALPHABETICALLY.
33

4+
#' @noRd
5+
#' @keywords internal
6+
7+
safe_list_ns <- local({
8+
# Defines a safe-list that:
9+
# - Fails when trying to access a non-existant element by name, either by $, [] and [[]]
10+
# - Disables partial matching when using $
11+
# - Supports numerical indexing as usual
12+
#
13+
# R does not fail when accesing non-existant elements by name, it returns NULL.
14+
# If we want to be defensive and forbiding access to non-existant elements, we should do that on an element by
15+
# element basis (!is.null, name %in names(), ...)
16+
# With this type we avoid including these checks and also forgetting to add a check when accessing a
17+
# new element.
18+
#
19+
# The intention is to use it in specific scopes where this conditions hold true.
20+
#
21+
# It exports elements individually and includes a `define_safe_list` that exports all individual elements
22+
# with the correct names for the operators to work
23+
24+
#' @keywords internal
25+
safe_list <- function(...) {
26+
result <- list(...)
27+
class(result) <- c("safe_list", class(result))
28+
return(result)
29+
}
30+
31+
#' @keywords internal
32+
`[[.safe_list` <- function(x, name) {
33+
if (is.character(name) && !name %in% names(x)) {
34+
stop(sprintf("Element '%s' not found in safe_list.", name), call. = FALSE)
35+
}
36+
NextMethod("[[")
37+
}
38+
39+
#' @keywords internal
40+
`$.safe_list` <- `[[.safe_list`
41+
42+
#' @keywords internal
43+
`[.safe_list` <- function(x, i) {
44+
if (is.character(i) && length(setdiff(i, names(x))) > 0) {
45+
stop(sprintf("Elements '%s' not found in safe_list", paste(missing_elements, collapse = ", ")), call. = FALSE)
46+
}
47+
x <- NextMethod("[")
48+
as_safe_list(x)
49+
}
50+
51+
as_safe_list <- function(x) {
52+
if (!is.list(x)) stop("x must be a list")
53+
class(x) <- c("safe_list", class(x))
54+
x
55+
}
56+
57+
is_safe_list <- function(x) isTRUE(is.list(x) && inherits(x, "safe_list"))
58+
59+
test <- function() {
60+
assert <- function(expr, msg) if (!isTRUE(expr)) stop(msg)
61+
x <- safe_list(aa = 0, bb = 1)
62+
63+
assert(is.list(x) && inherits(x, "safe_list"), "Classes are correctly set")
64+
65+
assert(x[["aa"]] == 0, "Present element 'aa' can be accessed via [[]]")
66+
assert(x[["bb"]] == 1, "Present element 'bb' can be accessed via [[]]")
67+
68+
err <- try(x[["c"]], silent = TRUE)
69+
assert(inherits(err, "try-error"), "Not present element 'c' cannot be accessed via [[]]")
70+
assert(
71+
attr(err, "condition")[["message"]] == "Element 'c' not found in safe_list.",
72+
"Not present element 'c' cannot be accessed via [[]] and throws the correct error"
73+
)
74+
75+
assert(x$aa == 0, "Present element 'aa' can be accessed via $")
76+
assert(x$bb == 1, "Present element 'bb' can be accessed via $")
77+
78+
err <- try(x$c, silent = TRUE)
79+
assert(inherits(err, "try-error"), "Not present element 'c' cannot be accessed via $")
80+
assert(
81+
attr(err, "condition")[["message"]] == "Element 'c' not found in safe_list.",
82+
"Not present element 'c' cannot be accessed via $ and throws the correct error"
83+
)
84+
85+
err <- try(x$b, silent = TRUE)
86+
assert(inherits(err, "try-error"), "Partial matching is not possible via $")
87+
88+
assert(isTRUE(is_safe_list(x)), "safe_list return TRUE when passed a safe_list")
89+
assert(isFALSE(is_safe_list(list())), "safe_list return FALSE when passed a regular list")
90+
91+
assert(identical(x[c("aa")], safe_list(aa = 0)), "[] returns a subset safe_list")
92+
93+
assert(x[[1]] == 0, "[[]] allows numerical indexing")
94+
assert(identical(x[1], safe_list(aa = 0)), "[] allows numerical indexing")
95+
96+
assert(is_safe_list(as_safe_list(list(aa = 0))), "as_safe_list returns a safe_list")
97+
98+
TRUE
99+
}
100+
101+
individual_list <- list(
102+
safe_list = safe_list,
103+
"$.safe_list" = `$.safe_list`,
104+
"[[.safe_list" = `[[.safe_list`,
105+
"[.safe_list" = `[.safe_list`,
106+
as_safe_list = as_safe_list,
107+
is_safe_list = is_safe_list
108+
)
109+
110+
c(
111+
individual_list,
112+
define_safe_list = function(env = parent.frame()) {
113+
list2env(individual_list, env)
114+
invisible(NULL)
115+
},
116+
test = test
117+
)
118+
})
119+
120+
#' @keywords internal
121+
safe_list <- safe_list_ns[["safe_list"]]
122+
#' @keywords internal
123+
`$.safe_list` <- safe_list_ns[["$.safe_list"]]
124+
#' @keywords internal
125+
`[[.safe_list` <- safe_list_ns[["[[.safe_list"]]
126+
#' @keywords internal
127+
`[.safe_list` <- safe_list_ns[["[.safe_list"]]
128+
#' @keywords internal
129+
as_safe_list <- safe_list_ns[["as_safe_list"]]
130+
#' @keywords internal
131+
is_safe_list <- safe_list_ns[["is_safe_list"]]
132+
4133
#' Build a collection of named constants
5134
#'
6135
#' @param ... Named parameters to be collected as constants
@@ -50,18 +179,14 @@ pack_of_constants <- function(...) {
50179
#' This function differs from the base list extraction method in that it avoids partial matching of keys and throws
51180
#' an error if the looked-for constant is not contained within the pack.
52181
#' @keywords internal
53-
#' @export
54182
`$.pack_of_constants` <- function(pack, name) {
55183
checkmate::assert_true(name %in% names(pack), .var.name = paste0(deparse(substitute(pack)), "$", name))
56184
NextMethod()
57185
}
58186

59-
# This exports are recent requirement for devtools check https://github.com/r-lib/roxygen2/issues/1592#issue-2121199122
60187
#' @keywords internal
61-
#' @export
62188
`[[.pack_of_constants` <- `$.pack_of_constants`
63189

64-
#' @export
65190
#' @keywords internal
66191
`[.pack_of_constants` <- function(pack, name) {
67192
stop("Invalid pack_of_constants method")

0 commit comments

Comments
 (0)