get_exercises.Rd
Extracts exercises from a DataCamp chapter
get_exercises(chapter_file)
chapter_file |
---|
chapter_file_path <- system.file("extdata/", package="decampr") chapter_list <- get_chapters(chapter_file_path) exercise_list <- get_exercises(chapter_list[[1]]) exercise_list[[1]]#> [1] "## Quick Data Frame Introduction\n\nBefore we start: please join the [RBootcamp OHSU Group!](https://www.datacamp.com/groups/de163cc541d0d9bde4956157d17dbedfb1149225/invite)\n\nA `data.frame` is basically a table-like format which has the following properties: \n\n- Columns can each have a different type (`numeric`, `character`, `boolean`, `factor`)\n- Columns are called \"variables\"\n- Rows correspond to a single observation (ideally)\n- Can be subset or filtered based on criteria\n\nIndividual variables within a `data.frame` can be accessed with the `$` operator (such as `gap1992$pop`). We won't use this very often, as the `tidyverse` lets us access the variables without it, as you'll see.\n\n*** =instructions\nRun `colnames()` and `head()` on the `gap1992` data to see what's in each column. Then see how many rows there are in the dataset using `nrow()`. Run these in console before you submit your answer.\n\n*** =pre_exercise_code\n```{r}\nlibrary(dplyr)\nlibrary(gapminder)\nlibrary(ggplot2)\ngap1992 <- gapminder %>% filter(year == 1992)\n```\n\n*** =sample_code\n```{r}\n##run head on gap1992\nhead(----)\n##run colnames here on gap1992\ncolnames(----)\n##run nrow() on gap1992\nnrow(-----)\n```\n\n*** =solution\n```{r}\n##run head on gap1992\nhead(gap1992)\n##run colnames here on gap1992\ncolnames(gap1992)\n##run nrow() on gap1992\nnrow(gap1992)\n```\n\n*** =sct\n```{r}\nsuccess_msg(\"Great! You learned some basics about `data.frame`s! Let's move on.\")\ntest_function(\"colnames\", incorrect_msg = \"did you use colnames(gap1992)?\")\ntest_function(\"nrow\", incorrect_msg = \"did you use nrow(gap1992)\")\n```"