|
| 1 | + |
| 2 | +--- |
| 3 | +title: "Using RMarkdown" |
| 4 | +teaching: 10 |
| 5 | +exercises: 2 |
| 6 | +--- |
| 7 | + |
| 8 | +:::::::::::::::::::::::::::::::::::::: questions |
| 9 | + |
| 10 | +- How do you write a lesson using R Markdown and `{sandpaper}`? |
| 11 | + |
| 12 | +:::::::::::::::::::::::::::::::::::::::::::::::: |
| 13 | + |
| 14 | +::::::::::::::::::::::::::::::::::::: objectives |
| 15 | + |
| 16 | +- Explain how to use markdown with the new lesson template |
| 17 | +- Demonstrate how to include pieces of code, figures, and nested challenge blocks |
| 18 | + |
| 19 | +:::::::::::::::::::::::::::::::::::::::::::::::: |
| 20 | + |
| 21 | +## Introduction |
| 22 | + |
| 23 | +This is a lesson created via The Carpentries Workbench. It is written in |
| 24 | +[Pandoc-flavored Markdown](https://pandoc.org/MANUAL.txt) for static files and |
| 25 | +[R Markdown][r-markdown] for dynamic files that can render code into output. |
| 26 | +Please refer to the [Introduction to The Carpentries |
| 27 | +Workbench](https://carpentries.github.io/sandpaper-docs/) for full documentation. |
| 28 | + |
| 29 | +What you need to know is that there are three sections required for a valid |
| 30 | +Carpentries lesson template: |
| 31 | + |
| 32 | + 1. `questions` are displayed at the beginning of the episode to prime the |
| 33 | + learner for the content. |
| 34 | + 2. `objectives` are the learning objectives for an episode displayed with |
| 35 | + the questions. |
| 36 | + 3. `keypoints` are displayed at the end of the episode to reinforce the |
| 37 | + objectives. |
| 38 | + |
| 39 | +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: instructor |
| 40 | + |
| 41 | +Inline instructor notes can help inform instructors of timing challenges |
| 42 | +associated with the lessons. They appear in the "Instructor View" |
| 43 | + |
| 44 | +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
| 45 | + |
| 46 | +::::::::::::::::::::::::::::::::::::: challenge |
| 47 | + |
| 48 | +## Challenge 1: Can you do it? |
| 49 | + |
| 50 | +What is the output of this command? |
| 51 | + |
| 52 | +```r |
| 53 | +paste("This", "new", "lesson", "looks", "good") |
| 54 | +``` |
| 55 | + |
| 56 | +:::::::::::::::::::::::: solution |
| 57 | + |
| 58 | +## Output |
| 59 | + |
| 60 | +```output |
| 61 | +[1] "This new lesson looks good" |
| 62 | +``` |
| 63 | + |
| 64 | +::::::::::::::::::::::::::::::::: |
| 65 | + |
| 66 | + |
| 67 | +## Challenge 2: how do you nest solutions within challenge blocks? |
| 68 | + |
| 69 | +:::::::::::::::::::::::: solution |
| 70 | + |
| 71 | +You can add a line with at least three colons and a `solution` tag. |
| 72 | + |
| 73 | +::::::::::::::::::::::::::::::::: |
| 74 | +:::::::::::::::::::::::::::::::::::::::::::::::: |
| 75 | + |
| 76 | +## Figures |
| 77 | + |
| 78 | +You can also include figures generated from R Markdown: |
| 79 | + |
| 80 | +```{r pyramid, fig.alt = "pie chart illusion of a pyramid", fig.cap = "Sun arise each and every morning"} |
| 81 | +pie( |
| 82 | + c(Sky = 78, "Sunny side of pyramid" = 17, "Shady side of pyramid" = 5), |
| 83 | + init.angle = 315, |
| 84 | + col = c("deepskyblue", "yellow", "yellow3"), |
| 85 | + border = FALSE |
| 86 | +) |
| 87 | +``` |
| 88 | + |
| 89 | +Or you can use standard markdown for static figures with the following syntax: |
| 90 | + |
| 91 | +`{alt='alt text for |
| 92 | +accessibility purposes'}` |
| 93 | + |
| 94 | +{alt='Blue Carpentries hex person logo with no text.'} |
| 95 | + |
| 96 | +::::::::::::::::::::::::::::::::::::: callout |
| 97 | + |
| 98 | +Callout sections can highlight information. |
| 99 | + |
| 100 | +They are sometimes used to emphasise particularly important points |
| 101 | +but are also used in some lessons to present "asides": |
| 102 | +content that is not central to the narrative of the lesson, |
| 103 | +e.g. by providing the answer to a commonly-asked question. |
| 104 | + |
| 105 | +:::::::::::::::::::::::::::::::::::::::::::::::: |
| 106 | + |
| 107 | + |
| 108 | +## Math |
| 109 | + |
| 110 | +One of our episodes contains $\LaTeX$ equations when describing how to create |
| 111 | +dynamic reports with {knitr}, so we now use mathjax to describe this: |
| 112 | + |
| 113 | +`$\alpha = \dfrac{1}{(1 - \beta)^2}$` becomes: $\alpha = \dfrac{1}{(1 - \beta)^2}$ |
| 114 | + |
| 115 | +Cool, right? |
| 116 | + |
| 117 | +::::::::::::::::::::::::::::::::::::: keypoints |
| 118 | + |
| 119 | +- Use `.md` files for episodes when you want static content |
| 120 | +- Use `.Rmd` files for episodes when you need to generate output |
| 121 | +- Run `sandpaper::check_lesson()` to identify any issues with your lesson |
| 122 | +- Run `sandpaper::build_lesson()` to preview your lesson locally |
| 123 | + |
| 124 | +:::::::::::::::::::::::::::::::::::::::::::::::: |
| 125 | + |
| 126 | +[r-markdown]: https://rmarkdown.rstudio.com/ |
0 commit comments