Skip to content

Commit

Permalink
Clarified coding exercise and added step-by-step instructions.
Browse files Browse the repository at this point in the history
  • Loading branch information
abner-hb committed Sep 5, 2024
1 parent 9823ee1 commit fd83e2e
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 93 deletions.
236 changes: 164 additions & 72 deletions slideshow.html

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions slideshow.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ source("load_clean_flower_df.R")

## About this workshop

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

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

## Workshop format

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

::: {.notes}
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.
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.
:::

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

::: {.notes}
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.
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.
:::

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

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

## Tips for naming objects

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

## Exercise

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()`.
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.

## Exercise step by step

+ Step 1: define a function that takes one argument, `num_rolls`, representing the number of times to roll the dice.
+ Step 2: create two objects called `red` and `blue` to store the results from the dice rolls.
+ Step 3: simulate the dice rolls using function `sample()` (read its help page if you need to).
+ 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.
+ Step 5: use this vector of indices to extract the values from the red die.
+ Step 6: make sure that your function returns the values you extracted in step 5.

## Coercion

Expand Down
4 changes: 2 additions & 2 deletions slideshow_files/libs/quarto-html/popper.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion slideshow_files/libs/quarto-html/quarto-html.min.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/*# sourceMappingURL=0a6b880beb84f9b6f36107a76f82c5b1.css.map */

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions slideshow_files/libs/revealjs/dist/theme/quarto.css

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ window.QuartoLineHighlight = function () {
divSourceCode.forEach((el) => {
if (el.hasAttribute(kCodeLineNumbersAttr)) {
const codeLineAttr = el.getAttribute(kCodeLineNumbersAttr);
el.removeAttribute("data-code-line-numbers");
el.removeAttribute(kCodeLineNumbersAttr);
if (handleLinesSelector(deck, codeLineAttr)) {
// Only process if attr is a string to select lines to highlights
// e.g "1|3,6|8-11"
Expand Down Expand Up @@ -165,17 +165,17 @@ window.QuartoLineHighlight = function () {
if (typeof highlight.last === "number") {
spanToHighlight = [].slice.call(
codeBlock.querySelectorAll(
":scope > span:nth-child(n+" +
":scope > span:nth-of-type(n+" +
highlight.first +
"):nth-child(-n+" +
"):nth-of-type(-n+" +
highlight.last +
")"
)
);
} else if (typeof highlight.first === "number") {
spanToHighlight = [].slice.call(
codeBlock.querySelectorAll(
":scope > span:nth-child(" + highlight.first + ")"
":scope > span:nth-of-type(" + highlight.first + ")"
)
);
}
Expand Down
52 changes: 50 additions & 2 deletions slideshow_files/libs/revealjs/plugin/quarto-support/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ window.QuartoSupport = function () {
return /print-pdf/gi.test(window.location.search);
}

// helper for theme toggling
function toggleBackgroundTheme(el, onDarkBackground, onLightBackground) {
if (onDarkBackground) {
el.classList.add('has-dark-background')
} else {
el.classList.remove('has-dark-background')
}
if (onLightBackground) {
el.classList.add('has-light-background')
} else {
el.classList.remove('has-light-background')
}
}

// implement controlsAudo
function controlsAuto(deck) {
const config = deck.getConfig();
Expand Down Expand Up @@ -111,8 +125,19 @@ window.QuartoSupport = function () {
}
}

// add footer text
function addFooter(deck) {
// tweak slide-number element
function tweakSlideNumber(deck) {
deck.on("slidechanged", function (ev) {
const revealParent = deck.getRevealElement();
const slideNumberEl = revealParent.querySelector(".slide-number");
const onDarkBackground = Reveal.getSlideBackground(ev.indexh, ev.indexv).classList.contains('has-dark-background');
const onLightBackground = Reveal.getSlideBackground(ev.indexh, ev.indexv).classList.contains('has-light-background');
toggleBackgroundTheme(slideNumberEl, onDarkBackground, onLightBackground);
})
}

// add footer text
function addFooter(deck) {
const revealParent = deck.getRevealElement();
const defaultFooterDiv = document.querySelector(".footer-default");
if (defaultFooterDiv) {
Expand All @@ -127,13 +152,17 @@ window.QuartoSupport = function () {
prevSlideFooter.remove();
}
const currentSlideFooter = ev.currentSlide.querySelector(".footer");
const onDarkBackground = Reveal.getSlideBackground(ev.indexh, ev.indexv).classList.contains('has-dark-background')
const onLightBackground = Reveal.getSlideBackground(ev.indexh, ev.indexv).classList.contains('has-light-background')
if (currentSlideFooter) {
defaultFooterDiv.style.display = "none";
const slideFooter = currentSlideFooter.cloneNode(true);
handleLinkClickEvents(deck, slideFooter);
deck.getRevealElement().appendChild(slideFooter);
toggleBackgroundTheme(slideFooter, onDarkBackground, onLightBackground)
} else {
defaultFooterDiv.style.display = "block";
toggleBackgroundTheme(defaultFooterDiv, onDarkBackground, onLightBackground)
}
});
}
Expand Down Expand Up @@ -272,6 +301,23 @@ window.QuartoSupport = function () {
}
}

function handleWhiteSpaceInColumns(deck) {
for (const outerDiv of window.document.querySelectorAll("div.columns")) {
// remove all whitespace text nodes
// whitespace nodes cause the columns to be misaligned
// since they have inline-block layout
//
// Quarto emits no whitespace nodes, but third-party tooling
// has bugs that can cause whitespace nodes to be emitted.
// See https://github.com/quarto-dev/quarto-cli/issues/8382
for (const node of outerDiv.childNodes) {
if (node.nodeType === 3 && node.nodeValue.trim() === "") {
outerDiv.removeChild(node);
}
}
}
}

return {
id: "quarto-support",
init: function (deck) {
Expand All @@ -280,11 +326,13 @@ window.QuartoSupport = function () {
fixupForPrint(deck);
applyGlobalStyles(deck);
addLogoImage(deck);
tweakSlideNumber(deck);
addFooter(deck);
addChalkboardButtons(deck);
handleTabbyClicks();
handleSlideChanges(deck);
workaroundMermaidDistance(deck);
handleWhiteSpaceInColumns(deck);
},
};
};

0 comments on commit fd83e2e

Please # to comment.