This repository was archived by the owner on Aug 29, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy path_common.R
More file actions
65 lines (53 loc) · 1.66 KB
/
Copy path_common.R
File metadata and controls
65 lines (53 loc) · 1.66 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
54
55
56
57
58
59
60
61
62
63
64
65
set.seed(1014)
options(digits = 3)
knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE,
cache = TRUE,
autodep = TRUE,
out.width = "70%",
fig.align = 'center',
fig.width = 6,
fig.asp = 0.618, # 1 / phi
fig.show = "hold"
)
options(dplyr.print_min = 6, dplyr.print_max = 6)
# set rstan options
rstan::rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
# Helpful Documentation functions
rpkg_url <- function(pkg) {
paste0("https://cran.r-project.org/package=", pkg)
}
rpkg <- function(pkg) {
paste0("**[", pkg, "](", rpkg_url(pkg), ")**")
}
rdoc_url <- function(pkg, fun) {
paste0("https://www.rdocumentation.org/packages/", pkg, "/topics/", fun)
}
rdoc <- function(pkg, fun, full_name = FALSE) {
text <- if (full_name) paste0(pkg, "::", fun) else pkg
paste0("[", text, "](", rdoc_url(pkg, fun), ")")
}
STAN_VERSION <- "2.15.0"
STAN_URL <- "http://mc-stan.org/documentation/"
STAN_MAN_URL <- paste0("https://github.com/stan-dev/stan/releases/download/v", STAN_VERSION, "/stan-reference-", STAN_VERSION, ".pdf")
standoc <- function(x = NULL) {
if (!is.null(x)) {
STAN_MAN_URL
} else {
paste("[", x, "](", STAN_MAN_URL, ")")
}
}
# placeholder for maybe linking directly to docs
stanfunc <- function(x) {
paste0("`", x, "`")
}
knit_print.stanmodel <- function(x, options) {
code_str <- x@model_code
knitr::asis_output(as.character(htmltools::tags$pre(htmltools::tags$code(htmltools::HTML(code_str), class = "stan"))))
}
# From https://sunlightfoundation.com/2014/03/12/datavizguide/
PARTY_COLORS <- c("Republican" = "#9A3E25",
"Democratic" = "#156B90",
"Independent" = "#705259")