-
Notifications
You must be signed in to change notification settings - Fork 16
/
global.R
83 lines (68 loc) · 2.24 KB
/
global.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
library(shiny)
library(shinydashboard)
library(DiagrammeR)
library(dagitty)
library(igraph)
library(texPreview)
library(shinyAce)
library(shinyBS)
library(dplyr)
library(ggdag)
library(shinyWidgets)
library(shinyjs)
library(shinycssloaders)
library(shinyThings)
source("R/node.R")
source("R/edge.R")
source("R/columns.R")
source("R/module/clickpad.R")
source("R/module/dagPreview.R")
source("R/module/examples.R")
source("R/xcolorPicker.R")
source("R/aes_ui.R")
# Additional libraries: tidyr, digest, rlang
enableBookmarking(store = "server")
tex_opts$set(list(
density = 1200,
margin = list(left = 0, top = 0, right = 0, bottom = 0),
cleanup = c("aux", "log")
))
# Functions ---------------------------------------------------------------
DEBUG <- getOption("shinydag.debug", FALSE)
debug_input <- function(x, x_name = NULL) {
if (!isTRUE(DEBUG)) return()
if (is.null(x)) {
cat(if (!is.null(x_name)) paste0(x_name, ":"), "NULL", "\n")
} else if (inherits(x, "igraph")) {
cat(capture.output(print(x)), "", sep = "\n")
} else if (length(x) == 1 && !is.list(x)) {
cat(if (!is.null(x_name)) paste0(x_name, ":"), if (length(names(x))) names(x), "-", x, "\n")
} else if (is.list(x) && length(x) == 0) {
cat(if (!is.null(x_name)) paste0(x_name, ":"), "list()", "\n")
} else {
if (!inherits(x, "data.frame")) x <- tibble::enframe(x)
cat(if (!is.null(x_name)) paste0(x_name, ":"), knitr::kable(x), "", sep = "\n")
}
}
debug_line <- function(...) {
if (!isTRUE(DEBUG)) return()
cli::cat_line(...)
}
buildUsepackage <- if (length(find("build_usepackage"))) texPreview::build_usepackage else texPreview::buildUsepackage
# use y if x is.null
`%||%` <- function(x, y) if (is.null(x)) y else x
# use y if x is not null(ish) (otherwise NULL)
`%??%` <- function(x, y) if (!is.null(x) && x != "") y
warnNotification <- function(...) showNotification(
paste0(...), duration = 5, closeButton = TRUE, type = "warning"
)
invertNames <- function(x) setNames(names(x), unname(x))
# String utilities ----
str_and <- function(...) {
x <- c(...)
last <- if (length(x) > 2) ", and " else " and "
glue::glue_collapse(x, sep = ", ", last = last)
}
str_plural <- function(x, word, plural = paste0(word, "s")) {
if (length(x) > 1) plural else word
}