Skip to content

Commit fd83e2e

Browse files
committed
Clarified coding exercise and added step-by-step instructions.
1 parent 9823ee1 commit fd83e2e

File tree

8 files changed

+247
-93
lines changed

8 files changed

+247
-93
lines changed

slideshow.html

+164-72
Large diffs are not rendered by default.

slideshow.qmd

+19-10
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ source("load_clean_flower_df.R")
1616

1717
## About this workshop
1818

19-
For novice or inexperienced coders that want to use **R**. We will use RStudio to:
19+
For novice or inexperienced coders that want to use **R**. We will use RStudio to learn:
2020

21-
+ Use and write basic functions.
22-
+ Learn how R stores and handles different types of data.
21+
+ How to use and write basic functions.
22+
+ How R stores and handles different types of data.
2323
+ Basic ways to create, manipulate, import, clean, and summarize data.
24-
+ *NO* statistical modeling.
24+
+ But *NOT* statistical modeling.
2525

2626
## Workshop format
2727

28-
+ From 1 to 5 pm.
28+
+ From 1 to 4:45 pm.
2929
+ Breaks every 90 minutes.
3030
+ A few slides for context and extra information.
3131
+ A lot of hands-on coding and live demonstrations.
3232
+ All materials will be available after the workshop ends.
3333

3434
::: {.notes}
35-
This workshop runs from 1 to 5 pm, with breaks at least every 90 minutes. Right now I will use a few slides for context and extra information. But it is a WORKshop, so there will be plenty of hands-on coding and live demonstrations. All materials will be available after the workshop ends, so don't worry about copying these slides.
35+
This workshop runs from 1 to 4:45 pm, with breaks every 90 minutes. Right now I will use a few slides for context and extra information. But this is a WORKshop, so there will be plenty of hands-on coding and live demonstrations. All materials will be available after the workshop ends, so don't worry about copying these slides.
3636
:::
3737

3838
## Tips for this workshop
@@ -83,7 +83,7 @@ There are several ways to contact CSCAR. You can request a consultation by email
8383
+ ...which means learning it well from the beginning.
8484

8585
::: {.notes}
86-
My name is Abner Heredia Bustos. I am a data science consultant at CSCAR. Apart from this, all you need to know is that, for me, coding is just a mean to an end. This means that I will try hard to make coding as simple and effortless as possible for you; but to achieve this you will need to put some effort in learning the basics.
86+
My name is Abner Heredia Bustos. I am a data science consultant at CSCAR. Apart from this, all you need to know is that, for me, coding is just a mean to an end. So, I will try hard to make coding as simple and effortless as possible for you; but to achieve this you will need to put some effort in learning the basics.
8787
:::
8888

8989
# Why do you want to learn R?
@@ -136,7 +136,7 @@ R is very powerful because it is an environment, not a package. A package is a f
136136
+ Generalized linear models (including linear regression).
137137
+ Survival analysis.
138138
+ Time series analysis.
139-
+ Random and Mixed effects models.
139+
+ Multilevel models.
140140
+ Classification and clustering.
141141
+ Sample size and power calculations.
142142
+ Multivariable analysis (e.g., factor analysis, PCA, and SEM).
@@ -220,7 +220,7 @@ Think of an integer, double it, add six, divide it in half, subtract the number
220220
## Object names have rules
221221

222222
+ Names are case-sensitive (`age`, `Age` and `AGE` are three different objects).
223-
+ Reserved words can *not* be used as names (`TRUE`, `FALSE`, `NULL`, `if`, ...).
223+
+ Reserved words (`TRUE`, `FALSE`, `NULL`, `if`, ...) can *not* be used as names
224224

225225
## Tips for naming objects
226226

@@ -230,7 +230,16 @@ Think of an integer, double it, add six, divide it in half, subtract the number
230230

231231
## Exercise
232232

233-
Write a function that can simulate the roll of a pair of six-sided dice an arbitrary number of times. This function should return a vector with the values of the red die that were strictly larger than the corresponding values of the blue die. Hint: to simulate rolling a die, you can use the function `sample()`.
233+
Write a function that can simulate the roll of two six-sided dice, one red and one blue, an arbitrary number of times. This function should return a vector with the values of the red die that were strictly larger than the corresponding values of the blue die.
234+
235+
## Exercise step by step
236+
237+
+ Step 1: define a function that takes one argument, `num_rolls`, representing the number of times to roll the dice.
238+
+ Step 2: create two objects called `red` and `blue` to store the results from the dice rolls.
239+
+ Step 3: simulate the dice rolls using function `sample()` (read its help page if you need to).
240+
+ Step 4: create a vector of indices that identifies the values in the red die that were larger than the values in the blue die.
241+
+ Step 5: use this vector of indices to extract the values from the red die.
242+
+ Step 6: make sure that your function returns the values you extracted in step 5.
234243

235244
## Coercion
236245

slideshow_files/libs/quarto-html/popper.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/*# sourceMappingURL=0a6b880beb84f9b6f36107a76f82c5b1.css.map */
1+

slideshow_files/libs/quarto-html/quarto-syntax-highlighting.css

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

slideshow_files/libs/revealjs/dist/theme/quarto.css

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

slideshow_files/libs/revealjs/plugin/quarto-line-highlight/line-highlight.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ window.QuartoLineHighlight = function () {
3838
divSourceCode.forEach((el) => {
3939
if (el.hasAttribute(kCodeLineNumbersAttr)) {
4040
const codeLineAttr = el.getAttribute(kCodeLineNumbersAttr);
41-
el.removeAttribute("data-code-line-numbers");
41+
el.removeAttribute(kCodeLineNumbersAttr);
4242
if (handleLinesSelector(deck, codeLineAttr)) {
4343
// Only process if attr is a string to select lines to highlights
4444
// e.g "1|3,6|8-11"
@@ -165,17 +165,17 @@ window.QuartoLineHighlight = function () {
165165
if (typeof highlight.last === "number") {
166166
spanToHighlight = [].slice.call(
167167
codeBlock.querySelectorAll(
168-
":scope > span:nth-child(n+" +
168+
":scope > span:nth-of-type(n+" +
169169
highlight.first +
170-
"):nth-child(-n+" +
170+
"):nth-of-type(-n+" +
171171
highlight.last +
172172
")"
173173
)
174174
);
175175
} else if (typeof highlight.first === "number") {
176176
spanToHighlight = [].slice.call(
177177
codeBlock.querySelectorAll(
178-
":scope > span:nth-child(" + highlight.first + ")"
178+
":scope > span:nth-of-type(" + highlight.first + ")"
179179
)
180180
);
181181
}

slideshow_files/libs/revealjs/plugin/quarto-support/support.js

+50-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ window.QuartoSupport = function () {
44
return /print-pdf/gi.test(window.location.search);
55
}
66

7+
// helper for theme toggling
8+
function toggleBackgroundTheme(el, onDarkBackground, onLightBackground) {
9+
if (onDarkBackground) {
10+
el.classList.add('has-dark-background')
11+
} else {
12+
el.classList.remove('has-dark-background')
13+
}
14+
if (onLightBackground) {
15+
el.classList.add('has-light-background')
16+
} else {
17+
el.classList.remove('has-light-background')
18+
}
19+
}
20+
721
// implement controlsAudo
822
function controlsAuto(deck) {
923
const config = deck.getConfig();
@@ -111,8 +125,19 @@ window.QuartoSupport = function () {
111125
}
112126
}
113127

114-
// add footer text
115-
function addFooter(deck) {
128+
// tweak slide-number element
129+
function tweakSlideNumber(deck) {
130+
deck.on("slidechanged", function (ev) {
131+
const revealParent = deck.getRevealElement();
132+
const slideNumberEl = revealParent.querySelector(".slide-number");
133+
const onDarkBackground = Reveal.getSlideBackground(ev.indexh, ev.indexv).classList.contains('has-dark-background');
134+
const onLightBackground = Reveal.getSlideBackground(ev.indexh, ev.indexv).classList.contains('has-light-background');
135+
toggleBackgroundTheme(slideNumberEl, onDarkBackground, onLightBackground);
136+
})
137+
}
138+
139+
// add footer text
140+
function addFooter(deck) {
116141
const revealParent = deck.getRevealElement();
117142
const defaultFooterDiv = document.querySelector(".footer-default");
118143
if (defaultFooterDiv) {
@@ -127,13 +152,17 @@ window.QuartoSupport = function () {
127152
prevSlideFooter.remove();
128153
}
129154
const currentSlideFooter = ev.currentSlide.querySelector(".footer");
155+
const onDarkBackground = Reveal.getSlideBackground(ev.indexh, ev.indexv).classList.contains('has-dark-background')
156+
const onLightBackground = Reveal.getSlideBackground(ev.indexh, ev.indexv).classList.contains('has-light-background')
130157
if (currentSlideFooter) {
131158
defaultFooterDiv.style.display = "none";
132159
const slideFooter = currentSlideFooter.cloneNode(true);
133160
handleLinkClickEvents(deck, slideFooter);
134161
deck.getRevealElement().appendChild(slideFooter);
162+
toggleBackgroundTheme(slideFooter, onDarkBackground, onLightBackground)
135163
} else {
136164
defaultFooterDiv.style.display = "block";
165+
toggleBackgroundTheme(defaultFooterDiv, onDarkBackground, onLightBackground)
137166
}
138167
});
139168
}
@@ -272,6 +301,23 @@ window.QuartoSupport = function () {
272301
}
273302
}
274303

304+
function handleWhiteSpaceInColumns(deck) {
305+
for (const outerDiv of window.document.querySelectorAll("div.columns")) {
306+
// remove all whitespace text nodes
307+
// whitespace nodes cause the columns to be misaligned
308+
// since they have inline-block layout
309+
//
310+
// Quarto emits no whitespace nodes, but third-party tooling
311+
// has bugs that can cause whitespace nodes to be emitted.
312+
// See https://github.com/quarto-dev/quarto-cli/issues/8382
313+
for (const node of outerDiv.childNodes) {
314+
if (node.nodeType === 3 && node.nodeValue.trim() === "") {
315+
outerDiv.removeChild(node);
316+
}
317+
}
318+
}
319+
}
320+
275321
return {
276322
id: "quarto-support",
277323
init: function (deck) {
@@ -280,11 +326,13 @@ window.QuartoSupport = function () {
280326
fixupForPrint(deck);
281327
applyGlobalStyles(deck);
282328
addLogoImage(deck);
329+
tweakSlideNumber(deck);
283330
addFooter(deck);
284331
addChalkboardButtons(deck);
285332
handleTabbyClicks();
286333
handleSlideChanges(deck);
287334
workaroundMermaidDistance(deck);
335+
handleWhiteSpaceInColumns(deck);
288336
},
289337
};
290338
};

0 commit comments

Comments
 (0)