Skip to content

Commit d2c9bbe

Browse files
committed
update slides
1 parent 5eaefd4 commit d2c9bbe

Some content is hidden

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

49 files changed

+4704
-210
lines changed

CONTRIBUTING.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Contributing to quarto-template
1+
# Contributing to training-summary
22

3-
First off, thanks for taking the time to contribute to `quarto-template`!
3+
First off, thanks for taking the time to contribute to `training-summary`!
44

55
All types of contributions are encouraged and valued. See the
66
[Table of contents](#table-of-contents) for different ways to help and details
@@ -24,13 +24,13 @@ maintainers and smooth out the experience for all involved.
2424

2525
## Code of conduct
2626

27-
This project is released with a [Contributor Code of Conduct](https://github.com/rdatatoolbox/quarto-template/blob/main/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to <[email protected]>.
27+
This project is released with a [Contributor Code of Conduct](https://github.com/frbcesab/training-summary/blob/main/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to <[email protected]>.
2828

2929

3030

3131
## Style guide
3232

33-
We use the [Tidyverse style guide](https://style.tidyverse.org/) for writing R code. Functions are documented with the [roxygen2](https://roxygen2.r-lib.org/articles/roxygen2.html) syntax. `quarto-template` uses the `lower_snake_case`.
33+
We use the [Tidyverse style guide](https://style.tidyverse.org/) for writing R code. Functions are documented with the [roxygen2](https://roxygen2.r-lib.org/articles/roxygen2.html) syntax. `training-summary` uses the `lower_snake_case`.
3434

3535

3636

@@ -42,12 +42,12 @@ If you want to contribute by commiting changes, please try to use the [Conventio
4242

4343
## Asking questions
4444

45-
Before you ask a question, it is best to search for existing [Issues](https://github.com/rdatatoolbox/quarto-template/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue.
45+
Before you ask a question, it is best to search for existing [Issues](https://github.com/frbcesab/training-summary/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue.
4646

4747
If you then still feel the need to ask a question and need clarification, we recommend the following:
4848

49-
- Open a new [Issue](https://github.com/rdatatoolbox/quarto-template/issues/new).
50-
- Use the template [other_issue.md](https://github.com/rdatatoolbox/quarto-template/blob/main/.github/ISSUE_TEMPLATE/other_issue.md).
49+
- Open a new [Issue](https://github.com/frbcesab/training-summary/issues/new).
50+
- Use the template [other_issue.md](https://github.com/frbcesab/training-summary/blob/main/.github/ISSUE_TEMPLATE/other_issue.md).
5151
- Provide as much context as you can about what you're running into.
5252
- Provide project and platform versions (paste the output of `sessionInfo()`).
5353

@@ -63,19 +63,19 @@ We will then take care of the issue as soon as possible.
6363

6464
A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible.
6565

66-
- Make sure that you are using the latest version of `quarto-template`.
66+
- Make sure that you are using the latest version of `training-summary`.
6767
- Determine if your bug is really a bug and not an error on your side.
68-
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/rdatatoolbox/quarto-template/issues?q=label%3Abug).
68+
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/frbcesab/training-summary/issues?q=label%3Abug).
6969

7070

7171

7272
### How do I submit a bug report?
7373

74-
We use [GitHub Issues](https://github.com/rdatatoolbox/quarto-template/issues) to
74+
We use [GitHub Issues](https://github.com/frbcesab/training-summary/issues) to
7575
track bugs and errors. If you run into an issue with the project:
7676

77-
- Open a new [Issue](https://github.com/rdatatoolbox/quarto-template/issues/new).
78-
- Use the template [bug_report.md](https://github.com/rdatatoolbox/quarto-template/blob/main/.github/ISSUE_TEMPLATE/bug_report.md).
77+
- Open a new [Issue](https://github.com/frbcesab/training-summary/issues/new).
78+
- Use the template [bug_report.md](https://github.com/frbcesab/training-summary/blob/main/.github/ISSUE_TEMPLATE/bug_report.md).
7979
- Explain the behavior you would expect and the actual behavior.
8080
- Please provide as much context as possible and describe the
8181
*reproduction steps* that someone else can follow to recreate the issue on
@@ -91,21 +91,21 @@ We will then take care of the issue as soon as possible.
9191

9292
### Before requesting a feature
9393

94-
- Make sure that you are using the latest version of `quarto-template`.
95-
- Read the [documentation](https://github.com/rdatatoolbox/quarto-template/) and the [wiki](https://github.com/rdatatoolbox/quarto-template/wiki) carefully and find out if the functionality is already covered.
96-
- Perform a [search](https://github.com/rdatatoolbox/quarto-template/issues) to see if this enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
94+
- Make sure that you are using the latest version of `training-summary`.
95+
- Read the [documentation](https://github.com/frbcesab/training-summary/) and the [wiki](https://github.com/frbcesab/training-summary/wiki) carefully and find out if the functionality is already covered.
96+
- Perform a [search](https://github.com/frbcesab/training-summary/issues) to see if this enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
9797

9898

9999

100100
### How do I submit a feature request?
101101

102-
Feature requests are tracked as [GitHub Issues](https://github.com/rdatatoolbox/quarto-template/issues).
102+
Feature requests are tracked as [GitHub Issues](https://github.com/frbcesab/training-summary/issues).
103103

104-
- Open a new [Issue](https://github.com/rdatatoolbox/quarto-template/issues/new).
105-
- Use the template [feature_request.md](https://github.com/rdatatoolbox/quarto-template/blob/main/.github/ISSUE_TEMPLATE/feature_request.md).
104+
- Open a new [Issue](https://github.com/frbcesab/training-summary/issues/new).
105+
- Use the template [feature_request.md](https://github.com/frbcesab/training-summary/blob/main/.github/ISSUE_TEMPLATE/feature_request.md).
106106
- Provide a clear and descriptive title for the issue to identify the suggestion.
107107
- Provide a step-by-step description of the suggested enhancement in as many details as possible.
108-
- Explain why this enhancement would be useful to most `quarto-template` users.
108+
- Explain why this enhancement would be useful to most `training-summary` users.
109109

110110
We will then take care of the issue as soon as possible.
111111

@@ -122,7 +122,7 @@ We use the [GitHub flow](https://docs.github.com/en/get-started/quickstart/githu
122122
1. Make your contribution.
123123
1. Stage (`git add`) and commit (`git commit`) your changes as often as necessary
124124
1. Push your changes to GitHub w/ `git push origin branch-name`.
125-
3. Submit a [Pull Request](https://docs.github.com/en/get-started/quickstart/contributing-to-projects#making-a-pull-request) on the [original repo](https://github.com/rdatatoolbox/quarto-template/compare).
125+
3. Submit a [Pull Request](https://docs.github.com/en/get-started/quickstart/contributing-to-projects#making-a-pull-request) on the [original repo](https://github.com/frbcesab/training-summary/compare).
126126

127127
We will then review the PR as soon as possible.
128128

DESCRIPTION

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Package: training-summary
2+
Type: Package
3+
Title: The Title of the Project
4+
Version: 0.0.0.9000
5+
Authors@R: c(
6+
person(given = "Nicolas",
7+
family = "Casajus",
8+
role = c("aut", "cre", "cph"),
9+
email = "[email protected]",
10+
comment = c(ORCID = "0000-0002-5537-5294")))
11+
Description: A paragraph providing a full description of the project (on
12+
several lines...)
13+
URL: https://github.com/ahasverus/training-summary
14+
BugReports: https://github.com/ahasverus/training-summary/issues
15+
License: CC-BY 4.0
16+
Encoding: UTF-8
17+
Roxygen: list(markdown = TRUE)
18+
RoxygenNote: 7.3.2
19+
Imports:
20+
devtools,
21+
dplyr,
22+
graphics,
23+
gsheet,
24+
here,
25+
jpeg,
26+
knitr,
27+
png,
28+
readxl,
29+
rmarkdown

R/add_image.R

+244
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
#' Title
2+
#'
3+
#' @param image
4+
#' @param file
5+
#' @param x
6+
#' @param y
7+
#' @param adj
8+
#' @param size
9+
#' @param col
10+
#' @param alpha
11+
#' @param angle
12+
#' @param fill
13+
#' @param border
14+
#' @param padding
15+
#' @param add
16+
#' @param ...
17+
#'
18+
#' @return
19+
#' @export
20+
#'
21+
#' @examples
22+
23+
24+
add_image <- function(image, file, x, y, adj = c(0.5, 0.5), size = NULL,
25+
col = NA, alpha = NULL, angle = 0, fill = NA, border = NA,
26+
padding = NULL, add = TRUE, ...) {
27+
28+
if (missing(image)) image <- NULL
29+
if (missing(file)) file <- NULL
30+
31+
if (missing(x)) x <- NULL
32+
if (missing(y)) y <- NULL
33+
34+
if (is.null(image) & is.null(file)) {
35+
stop("One of 'image' or 'file' is required.")
36+
}
37+
38+
if (!is.null(image) & !is.null(file)) {
39+
stop("Only one of 'image' or 'file' is required.")
40+
}
41+
42+
if (is.null(image)) {
43+
44+
if (sum(is.na(file))) {
45+
stop("Argument 'file' cannot contain missing value.")
46+
}
47+
48+
if (length(file) != 1 | !is.character(file)) {
49+
stop("Argument 'file' must be a character (filename) of length 1.")
50+
}
51+
52+
file_formats <- c("jpg$", "jpeg$", "png$")
53+
file_format <- unlist(lapply(file_formats, grepl, file))
54+
55+
if (!sum(file_format)) stop("Picture must be a JP(E)G or a PNG.")
56+
57+
if (grepl("^https?://", file)) {
58+
59+
file_ext <- switch(which(file_format), "jpg", "jpg", "png")
60+
61+
path <- tempfile(fileext = file_ext)
62+
download.file(url = file, destfile = path, quiet = TRUE)
63+
64+
file <- path
65+
66+
} else {
67+
68+
if (!file.exists(file)) stop("File does not exist.")
69+
}
70+
71+
image <- switch(
72+
which(file_format),
73+
jpeg::readJPEG(file, native = FALSE),
74+
jpeg::readJPEG(file, native = FALSE),
75+
png::readPNG(file, native = FALSE)
76+
)
77+
}
78+
79+
if (class(image) != "array") {
80+
stop("Argument 'image' must be a '3D array' (use `native = FALSE`).")
81+
}
82+
83+
if (dim(image)[3] < 3 | dim(image)[3] > 4) {
84+
stop("Wrong image format: Must a 3-channels (RGB) or 4-channels (RGBA).")
85+
}
86+
87+
if (is.null(padding)) padding <- rep(0, 4)
88+
89+
if (sum(is.na(padding))) stop("Argument 'padding' cannot contain NA.")
90+
if (!is.numeric(padding)) stop("Argument 'padding' must be a numeric.")
91+
92+
if (length(padding) == 1) {
93+
padding <- rep(padding, 4)
94+
95+
} else {
96+
97+
if (length(padding) == 2) {
98+
padding <- rep(padding, 2)
99+
100+
} else {
101+
102+
if (length(padding) != 4) {
103+
stop("Argument 'padding' must be a numeric of length 1, 2, or 4.")
104+
}
105+
}
106+
}
107+
108+
if (!add) {
109+
110+
plot(0, xlim = c(-1, 1), ylim = c(-1, 1), type = "n", ann = FALSE,
111+
bty = "n", axes = FALSE)
112+
}
113+
114+
if (is.null(dev.list())) stop("No open graphical device (use `add = TRUE`).")
115+
116+
if (is.null(x)) x <- par()$usr[1] + (par()$usr[2] - par()$usr[1]) / 2
117+
if (is.null(y)) y <- par()$usr[3] + (par()$usr[4] - par()$usr[3]) / 2
118+
119+
if (sum(is.na(x))) {
120+
stop("Argument 'x' cannot contain missing value.")
121+
}
122+
123+
if (!is.numeric(x)) {
124+
stop("Argument 'x' must be a numeric.")
125+
}
126+
127+
if (sum(is.na(y))) {
128+
stop("Argument 'y' cannot contain missing value.")
129+
}
130+
131+
if (!is.numeric(y)) {
132+
stop("Argument 'y' must be a numeric.")
133+
}
134+
135+
if (length(x) != length(y)) {
136+
stop("Arguments 'x and 'y' must have the same length.")
137+
}
138+
139+
140+
aspect_ratio <- dim(image)[1] / dim(image)[2]
141+
142+
143+
if (is.null(size)) size <- 100
144+
size <- rep(size, length(x))
145+
146+
if (!is.na(col)) col <- rep(col, length(x))
147+
if (!is.null(alpha)) alpha <- rep(alpha, length(x))
148+
149+
original <- image
150+
151+
for (i in 1:length(x)) {
152+
153+
image <- original
154+
155+
## Change Image Colors (monochromatic transformation) ---
156+
157+
if (!is.na(col[i])) {
158+
159+
col_i <- col2rgb(col[i], alpha = TRUE)
160+
161+
for (channel in 1:3) {
162+
163+
image[ , , channel][image[ , , channel] != 1] <- col_i[channel] / 255
164+
}
165+
166+
if (dim(image)[3] == 4) image[ , , 4][image[ , , 4] != 0] <- col_i[4] / 255
167+
}
168+
169+
if (!is.null(alpha)) {
170+
171+
alpha_i <- alpha[i]
172+
173+
if (alpha_i > 1) alpha_i <- alpha_i / 255
174+
175+
if (dim(image)[3] == 4) image[ , , 4][image[ , , 4] != 0] <- alpha_i
176+
}
177+
178+
179+
## Adjusting Image Dimensions ----
180+
181+
size_i <- size[i] / 100
182+
183+
width <- ifelse(aspect_ratio > 1, NA, size_i * (par()$usr[2] - par()$usr[1]))
184+
height <- ifelse(aspect_ratio <= 1, NA, size_i * (par()$usr[4] - par()$usr[3]))
185+
186+
if (is.na(width)) {
187+
188+
height_in <- height * par()$pin[2] / (par()$usr[4] - par()$usr[3])
189+
width_in <- height_in / aspect_ratio
190+
width <- width_in * (par()$usr[2] - par()$usr[1]) / par()$pin[1]
191+
192+
}
193+
194+
if (is.na(height)) {
195+
196+
width_in <- width / (par()$usr[2] - par()$usr[1]) * par()$pin[1]
197+
height_in <- width_in * aspect_ratio
198+
height <- height_in / par()$pin[2] * (par()$usr[4] - par()$usr[3])
199+
}
200+
201+
## Adjusting Image Position ----
202+
203+
x1 <- x[i] - ((1 - adj[1]) * width)
204+
y1 <- y[i] - ((1 - adj[2]) * height)
205+
x2 <- x1 + width
206+
y2 <- y1 + height
207+
208+
209+
## Add a background ----
210+
211+
if (!is.na(fill) || !is.na(border)) {
212+
213+
padding[1] <- padding[1] * height
214+
padding[2] <- padding[2] * width
215+
padding[3] <- padding[3] * height
216+
padding[4] <- padding[4] * width
217+
218+
rect(
219+
xleft = x1 - padding[2],
220+
xright = x2 + padding[4],
221+
ybottom = y1 - padding[1],
222+
ytop = y2 + padding[3],
223+
col = fill,
224+
border = border,
225+
...
226+
)
227+
}
228+
229+
230+
## Plot Image ----
231+
232+
graphics::rasterImage(
233+
image = as.raster(image),
234+
xleft = x1,
235+
xright = x2,
236+
ybottom = y1,
237+
ytop = y2,
238+
interpolate = TRUE,
239+
angle = angle
240+
)
241+
}
242+
243+
invisible(c(x1, y1, x2, y2))
244+
}

R/color-scheme.R

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
color_scheme <- function() {
2+
3+
c("reproducibility" = "#7d3c98",
4+
"theoretical-models" = "#2e86c1",
5+
"literature-synthesis" = "#c23438",
6+
"network-analysis" = "#cb9a4d",
7+
"biodiversity-data" = "#5a4e41",
8+
"artificial-intelligence" = "#93c47d")
9+
}

0 commit comments

Comments
 (0)