-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.Rmd
More file actions
113 lines (100 loc) · 2.55 KB
/
setup.Rmd
File metadata and controls
113 lines (100 loc) · 2.55 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
```{r setup, include=FALSE}
# R options
options(
htmltools.dir.version = FALSE,
dplyr.print_min = 6,
dplyr.print_max = 6,
tibble.width = 65,
width = 65
)
# figure height, width, dpi
knitr::opts_chunk$set(
echo = TRUE,
fig.width = 8,
fig.asp = 0.618,
out.width = "60%",
fig.align = "center",
dpi = 400,
message = FALSE,
knitr.duplicate.label = "allow"
)
# ggplot2
ggplot2::theme_set(ggplot2::theme_gray(base_size = 16))
# set seed
set.seed(1234)
# fontawesome
htmltools::tagList(rmarkdown::html_dependency_font_awesome())
# magick
dev.off <- function() {
invisible(grDevices::dev.off())
}
# conflicted
library(conflicted)
conflict_prefer("filter", "dplyr")
# Remember to compile
# xaringan::inf_mr(cast_from = "..")
# xaringanExtra
# library(xaringanExtra)
# xaringanExtra::use_panelset()
# output number of lines
hook_output <- knitr::knit_hooks$get("output")
knitr::knit_hooks$set(output = function(x, options) {
lines <- options$output.lines
if (is.null(lines)) {
return(hook_output(x, options)) # pass to default hook
}
x <- unlist(strsplit(x, "\n"))
more <- "..."
if (length(lines) == 1) { # first n lines
if (length(x) > lines) {
# truncate the output, but add ....
x <- c(head(x, lines), more)
}
} else {
x <- c(more, x[lines], more)
}
# paste these lines together
x <- paste(c(x, ""), collapse = "\n")
hook_output(x, options)
})
library(magick)
library(tools)
crop_bottom_percent <- function(image_path, pct = 10, output_path = NULL) {
require(magick)
require(tools)
# Check inputs
stopifnot(file.exists(image_path))
stopifnot(is.numeric(pct), pct >= 0, pct <= 100)
# Read and get dimensions
img <- image_read(image_path)
info <- image_info(img)
width <- info$width
height <- info$height
# Compute new height and crop geometry
retain_height <- floor((100 - pct) / 100 * height)
geom <- paste0(width, "x", retain_height, "+0+0")
# Determine output path if not provided
if (is.null(output_path)) {
dir <- dirname(image_path)
base <- file_path_sans_ext(basename(image_path))
ext <- file_ext(image_path)
output_path <- file.path(dir, paste0(base, "_cropped.", ext))
}
# Crop
cropped <- image_crop(img, geometry = geom)
# Save or return
if (!is.null(output_path)) {
image_write(cropped, path = output_path)
return(invisible(output_path))
} else {
return(cropped)
}
}
```
layout: true
<div class="my-footer">
<span>
<a href="https://DataScience4Psych.github.io/DataScience4Psych/" target="_blank">S. Mason Garrison</a>
</span>
</div>
---