-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathutils.R
More file actions
53 lines (45 loc) · 1.63 KB
/
utils.R
File metadata and controls
53 lines (45 loc) · 1.63 KB
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
#' Load a Server-Side Object by Name
#'
#' Retrieves a server-side object using `get()`, supporting both simple names
#' (e.g. "D") and column access syntax (e.g. "D$LAB_TSC").
#'
#' @param x A character string naming the object, optionally with "$column" syntax.
#' @return The retrieved R object.
#' @noRd
.loadServersideObject <- function(x) {
env <- parent.frame(2)
parts <- unlist(strsplit(x, "$", fixed = TRUE))
obj_name <- parts[1]
has_column <- length(parts) > 1
obj <- tryCatch(
get(obj_name, envir = env),
error = function(e) stop("The server-side object '", x, "' does not exist")
)
if (has_column) {
column_name <- parts[2]
obj <- obj[[column_name]]
}
obj
}
#' Check Class of a Server-Side Object
#'
#' Verifies that a given object is of an allowed class. If not, raises an informative error
#' message listing the permitted classes and the actual class of the object.
#'
#' @param obj The object whose class should be checked.
#' @param obj_name A character string with the name of the object (used in error messages).
#' @param permitted_classes A character vector of allowed class names.
#' @importFrom glue glue glue_collapse
#' @return Invisibly returns `TRUE` if the class check passes; otherwise throws an error.
#' @noRd
.checkClass <- function(obj, obj_name, permitted_classes) {
typ <- class(obj)
if (!any(permitted_classes %in% typ)) {
msg <- glue(
"The server-side object must be of type {glue_collapse(permitted_classes, sep = ', ', last = ' or ')}. ",
"'{obj_name}' is type {glue_collapse(typ, sep = ', ', last = ' and ')}."
)
stop(msg, call. = FALSE)
}
invisible(TRUE)
}