diff --git a/config.yml b/config.yml index 3ad34ac1..360e2f15 100644 --- a/config.yml +++ b/config.yml @@ -11,7 +11,7 @@ default: #final_due_date: "January 24th at 11:59pm ET" #grades_due: "January 26" holiday: "In recognition of [Martin Luther King Jr. Day](https://en.wikipedia.org/wiki/Martin_Luther_King_Jr._Day), there will be **no class on Monday January 15th, 2024**." - google_survey: "https://forms.gle/hQ7jdHZSZoDpHAdE6" + google_survey: "https://forms.gle/JAsLbyRDtCtxwgFG9" slack_workspace: "https://daseh.slack.com/" # ta: "Padmashri Saravanan (psarava1 at jhu.edu), Alex Newman (anewma28 at jhu.edu)" ds: "Candace Savonen (csavonen at fredhutch.org)" diff --git a/config_automation.yml b/config_automation.yml index d68a4e3a..223932b1 100644 --- a/config_automation.yml +++ b/config_automation.yml @@ -2,7 +2,7 @@ # Check quiz formatting check-quizzes: no # Check that urls in the content are not broken -url-checker: yes +url-checker: no # Render preview of content with changes (Rmd's and md's are checked) render-preview: yes # Spell check Rmds and quizzes diff --git a/docs/_schedule_table.Rmd b/docs/_schedule_table.Rmd index 37aac668..49463935 100644 --- a/docs/_schedule_table.Rmd +++ b/docs/_schedule_table.Rmd @@ -1,32 +1,31 @@ -| **Day** | **Module** | **Slides** | **Code** | **Resource** | **Cheatsheets/Guides** | -| :------------------------------------: | :-------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------: | -| [Day 0](docs/module_details/day0.html) | Homework 1 | | [HTML](modules/HW/homework1.html) | | | -| | | | | | | -| [Day 1](docs/module_details/day1.html) | Intro | [HTML](modules/Intro/Intro.html), [PDF](modules/Intro/Intro.pdf) | [Rmd](modules/Intro/Intro.Rmd) | | [Day 1 Cheatsheet](modules/cheatsheets/Day-1.pdf) | -| | RStudio | [HTML](modules/RStudio/RStudio.html), [PDF](modules/RStudio/RStudio.pdf) | [Rmd](modules/RStudio/RStudio.Rmd) | [Lab](modules/RStudio/lab/RStudio_Lab.Rmd), [Key](modules/RStudio/lab/RStudio_Lab_Key.Rmd), [Key HTML](modules/RStudio/lab/RStudio_Lab_Key.html) | | -| | Basic R | [HTML](modules/Basic_R/Basic_R.html), [PDF](modules/Basic_R/Basic_R.pdf) | [Rmd](modules/Basic_R/Basic_R.Rmd) | [Lab](modules/Basic_R/lab/Basic_R_Lab.Rmd), [Key](modules/Basic_R/lab/Basic_R_Lab_Key.Rmd), [Key HTML](modules/Basic_R/lab/Basic_R_Lab_Key.html) | | -| | | | | | | -| [Day 2](docs/module_details/day2.html) | Basic R (cont.) | [HTML](modules/Basic_R/Basic_R.html), [PDF](modules/Basic_R/Basic_R.pdf) | [Rmd](modules/Basic_R/Basic_R.Rmd) | [Lab](modules/Basic_R/lab/Basic_R_Lab.Rmd), [Key](modules/Basic_R/lab/Basic_R_Lab_Key.Rmd), [Key HTML](modules/Basic_R/lab/Basic_R_Lab_Key.html) | [Day 2 Cheatsheet](modules/cheatsheets/Day-2.pdf) | -| | Reproducibility | [HTML](modules/Reproducibility/Reproducibility.html), [PDF](modules/Reproducibility/Reproducibility.pdf) | [Rmd](modules/Reproducibility/Reproducibility.Rmd) | [Lab](modules/Reproducibility/lab/Reproducibility_Lab.Rmd), [Key](modules/Reproducibility/lab/Reproducibility_Lab_Key.Rmd), [Key HTML](modules/Reproducibility/lab/Reproducibility_Lab_Key.html) | [Good scientific coding practices](resources/good-scientific-coding-practices.pdf) | -| | Data Input | [HTML](modules/Data_Input/Data_Input.html), [PDF](modules/Data_Input/Data_Input.pdf) | [Rmd](modules/Data_Input/Data_Input.Rmd) | [Lab](modules/Data_Input/lab/Data_Input_Lab.Rmd), [Key](modules/Data_Input/lab/Data_Input_Lab_Key.Rmd), [Key HTML](modules/Data_Input/lab/Data_Input_Lab_Key.html) | [Debugging tips guide](resources/debugging_guide.pdf) | -| | | | | | | -| [Day 3](docs/module_details/day3.html) | Subsetting Data in R | [HTML](modules/Subsetting_Data_in_R/Subsetting_Data_in_R.html), [PDF](modules/Subsetting_Data_in_R/Subsetting_Data_in_R.pdf) | [Rmd](modules/Subsetting_Data_in_R/Subsetting_Data_in_R.Rmd) | [Lab](modules/Subsetting_Data_in_R/lab/Subsetting_Data_in_R_Lab.Rmd), [Key](modules/Subsetting_Data_in_R/lab/Subsetting_Data_in_R_Lab_Key.Rmd), [Key HTML](modules/Subsetting_Data_in_R/lab/Subsetting_Data_in_R_Lab_Key.html) | [Day 3 Cheatsheet](modules/cheatsheets/Day-3.pdf) | -| | Optional Homework 2 | | [Rmd](modules/HW/homework2.Rmd), [HTML](modules/HW/homework2.html), [Key](modules/HW/homework2_Key.Rmd), [Key HTML](modules/HW/homework2_Key.html) | | | -| | | | | | | -| [Day 4](docs/module_details/day4.html) | Data Summarization | [HTML](modules/Data_Summarization/Data_Summarization.html), [PDF](modules/Data_Summarization/Data_Summarization.pdf) | [Rmd](modules/Data_Summarization/Data_Summarization.Rmd) | [Lab](modules/Data_Summarization/lab/Data_Summarization_Lab.Rmd), [Key](modules/Data_Summarization/lab/Data_Summarization_Lab_Key.Rmd), [Key HTML](modules/Data_Summarization/lab/Data_Summarization_Lab_Key.html) | [Day 4 Cheatsheet](modules/cheatsheets/Day-4.pdf) | -| | Data Classes | [HTML](modules/Data_Classes/Data_Classes.html), [PDF](modules/Data_Classes/Data_Classes.pdf) | [Rmd](modules/Data_Classes/Data_Classes.Rmd) | [Lab](modules/Data_Classes/lab/Data_Classes_Lab.Rmd), [Key](modules/Data_Classes/lab/Data_Classes_Lab_Key.Rmd), [Key HTML](modules/Data_Classes/lab/Data_Classes_Lab_Key.html) | | -| | | | | | | -| [Day 5](docs/module_details/day5.html) | Data Cleaning | [HTML](modules/Data_Cleaning/Data_Cleaning.html),[PDF](modules/Data_Cleaning/Data_Cleaning.pdf) | [Rmd](modules/Data_Cleaning/Data_Cleaning.Rmd) | [Lab](modules/Data_Cleaning/lab/Data_Cleaning_Lab.Rmd), [Key](modules/Data_Cleaning/lab/Data_Cleaning_Lab_Key.Rmd), [Key HTML](modules/Data_Cleaning/lab/Data_Cleaning_Lab_Key.html) | [Day 5 Cheatsheet](modules/cheatsheets/Day-5.pdf) | -| -| [Day 6](docs/module_details/day6.html) | Manipulating Data in R | [HTML](modules/Manipulating_Data_in_R/Manipulating_Data_in_R.html), [PDF](modules/Manipulating_Data_in_R/Manipulating_Data_in_R.pdf) | [Rmd](modules/Manipulating_Data_in_R/Manipulating_Data_in_R.Rmd) | [Lab](modules/Manipulating_Data_in_R/lab/Manipulating_Data_in_R_Lab.Rmd), [Key](modules/Manipulating_Data_in_R/lab/Manipulating_Data_in_R_Lab_Key.Rmd), [Key HTML](modules/Manipulating_Data_in_R/lab/Manipulating_Data_in_R_Lab_Key.html) | [Day 6 Cheatsheet](modules/cheatsheets/Day-6.pdf) | -| | Intro to Data Visualization | [HTML](modules/Esquisse_Data_Visualization/Esquisse_Data_Visualization.html), [PDF](modules/Esquisse_Data_Visualization/Esquisse_Data_Visualization.pdf) | [Rmd](modules/Esquisse_Data_Visualization/Esquisse_Data_Visualization.Rmd) | [Lab](modules/Esquisse_Data_Visualization/lab/Esquisse_Data_Visualization_Lab.Rmd), [Key](modules/Esquisse_Data_Visualization/lab/Esquisse_Data_Visualization_Lab_Key.Rmd), [Key HTML](modules/Esquisse_Data_Visualization/lab/Esquisse_Data_Visualization_Lab_Key.html) | | -| | Optional Homework 3 | | [Rmd](modules/HW/homework3.Rmd), [HTML](modules/HW/homework3.html), [Key](modules/HW/homework3_Key.Rmd), [Key HTML](modules/HW/homework3_Key.html) | | | -| | | | | | | -| [Day 7](docs/module_details/day7.html) | Data Visualization | [HTML](modules/Data_Visualization/Data_Visualization.html), [PDF](modules/Data_Visualization/Data_Visualization.pdf) | [Rmd](modules/Data_Visualization/Data_Visualization.Rmd) | [Lab](modules/Data_Visualization/lab/Data_Visualization_Lab.Rmd), [Key](modules/Data_Visualization/lab/Data_Visualization_Lab_Key.Rmd), [Key HTML](modules/Data_Visualization/lab/Data_Visualization_Lab_Key.html) | [Day 7 Cheatsheet](modules/cheatsheets/Day-7.pdf) | -| | Factors | [HTML](modules/Factors/Factors.html), [PDF](modules/Factors/Factors.pdf) | [Rmd](modules/Factors/Factors.Rmd) | [Lab](modules/Factors/lab/Factors_Lab.Rmd), [Key](modules/Factors/lab/Factors_Lab_Key.Rmd), [Key HTML](modules/Factors/lab/Factors_Lab_Key.html) | | -| | | | | | | -| [Day 8](docs/module_details/day8.html) | Statistics | [HTML](modules/Statistics/Statistics.html), [PDF](modules/Statistics/Statistics.pdf) | [Rmd](modules/Statistics/Statistics.Rmd) | [Lab](modules/Statistics/lab/Statistics_Lab.Rmd), [Key](modules/Statistics/lab/Statistics_Lab_Key.Rmd), [Key HTML](modules/Statistics/lab/Statistics_Lab_Key.html) | [Day 8 Cheatsheet](modules/cheatsheets/Day-8.pdf) | -| | Data Output | [HTML](modules/Data_Output/Data_Output.html), [PDF](modules/Data_Output/Data_Output.pdf) | [Rmd](modules/Data_Output/Data_Output.Rmd) | [Lab](modules/Data_Output/lab/Data_Output_Lab.Rmd), [Key](modules/Data_Output/lab/Data_Output_Lab_Key.Rmd), [Key HTML](modules/Data_Output/lab/Data_Output_Lab_Key.html) | | -| -| [Day 9](docs/module_details/day9.html) | Functions | [HTML](modules/Functions/Functions.html), [PDF](modules/Functions/Functions.pdf) | [Rmd](modules/Functions/Functions.Rmd) | [Lab](modules/Functions/lab/Functions_Lab.Rmd), [Key](modules/Functions/lab/Functions_Lab_Key.Rmd), [Key HTML](modules/Functions/lab/Functions_Lab_Key.html) | [Day 9 Cheatsheet](modules/cheatsheets/Day-9.pdf) | -| +| **Day** | **Module** | **Lecture** | **Activity** | **Cheatsheets/Guides** | +|--:-:-----------------------------------|--:-:------------------------|--:-:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--:-:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--:-:-------------------------------------------------------------------------------| +| [Day 0](docs/module_details/day0.html) | Homework 1 | | [HTML](modules/HW/homework1.html) | | +| | | | | | +| [Day 1](docs/module_details/day1.html) | Intro | [HTML](modules/Intro/Intro.html), [PDF](modules/Intro/Intro.pdf), [Rmd](modules/Intro/Intro.Rmd) | | [Day 1 Cheatsheet](modules/cheatsheets/Day-1.pdf) | +| | Basic R | [HTML](modules/Basic_R/Basic_R.html), [PDF](modules/Basic_R/Basic_R.pdf), [Rmd](modules/Basic_R/Basic_R.Rmd) | [Lab Rmd](modules/Basic_R/lab/Basic_R_Lab.Rmd), [Key](modules/Basic_R/lab/Basic_R_Lab_Key.Rmd), [Key HTML](modules/Basic_R/lab/Basic_R_Lab_Key.html) | | +| | RStudio | [HTML](modules/RStudio/RStudio.html), [PDF](modules/RStudio/RStudio.pdf), [Rmd](modules/RStudio/RStudio.Rmd) | [Lab Rmd](modules/RStudio/lab/RStudio_Lab.Rmd), [Key](modules/RStudio/lab/RStudio_Lab_Key.Rmd), [Key HTML](modules/RStudio/lab/RStudio_Lab_Key.html) | | +| | | | | | +| [Day 2](docs/module_details/day2.html) | Reproducibility | [HTML](modules/Reproducibility/Reproducibility.html), [PDF](modules/Reproducibility/Reproducibility.pdf), [Rmd](modules/Reproducibility/Reproducibility.Rmd) | [Lab Rmd](modules/Reproducibility/lab/Reproducibility_Lab.Rmd), [Key](modules/Reproducibility/lab/Reproducibility_Lab_Key.Rmd), [Key HTML](modules/Reproducibility/lab/Reproducibility_Lab_Key.html) | [Good scientific coding practices](resources/good-scientific-coding-practices.pdf) | +| | Data Input | [HTML](modules/Data_Input/Data_Input.html), [PDF](modules/Data_Input/Data_Input.pdf), [Rmd](modules/Data_Input/Data_Input.Rmd) | [Lab Rmd](modules/Data_Input/lab/Data_Input_Lab.Rmd), [Key](modules/Data_Input/lab/Data_Input_Lab_Key.Rmd), [Key HTML](modules/Data_Input/lab/Data_Input_Lab_Key.html) | [Debugging tips guide](resources/debugging_guide.pdf) [Day 2 Cheatsheet](modules/cheatsheets/Day-2.pdf) | +| | | | | | +| [Day 3](docs/module_details/day3.html) | Subsetting Data in R | [HTML](modules/Subsetting_Data_in_R/Subsetting_Data_in_R.html), [PDF](modules/Subsetting_Data_in_R/Subsetting_Data_in_R.pdf), [Rmd](modules/Subsetting_Data_in_R/Subsetting_Data_in_R.Rmd) | [Lab Rmd](modules/Subsetting_Data_in_R/lab/Subsetting_Data_in_R_Lab.Rmd), [Key](modules/Subsetting_Data_in_R/lab/Subsetting_Data_in_R_Lab_Key.Rmd), [Key HTML](modules/Subsetting_Data_in_R/lab/Subsetting_Data_in_R_Lab_Key.html) | [Day 3 Cheatsheet](modules/cheatsheets/Day-3.pdf) | +| | Optional Homework 2 | | [HW Rmd](modules/HW/homework2.Rmd), [HTML](modules/HW/homework2.html), [Key](modules/HW/homework2_Key.Rmd), [Key HTML](modules/HW/homework2_Key.html) | | +| | | | | | +| [Day 4](docs/module_details/day4.html) | Data Summarization | [HTML](modules/Data_Summarization/Data_Summarization.html), [PDF](modules/Data_Summarization/Data_Summarization.pdf), [Rmd](modules/Data_Summarization/Data_Summarization.Rmd) | [Lab Rmd](modules/Data_Summarization/lab/Data_Summarization_Lab.Rmd), [Key](modules/Data_Summarization/lab/Data_Summarization_Lab_Key.Rmd), [Key HTML](modules/Data_Summarization/lab/Data_Summarization_Lab_Key.html) | [Day 4 Cheatsheet](modules/cheatsheets/Day-4.pdf) | +| | Data Classes | [HTML](modules/Data_Classes/Data_Classes.html), [PDF](modules/Data_Classes/Data_Classes.pdf), [Rmd](modules/Data_Classes/Data_Classes.Rmd) | [Lab Rmd](modules/Data_Classes/lab/Data_Classes_Lab.Rmd), [Key](modules/Data_Classes/lab/Data_Classes_Lab_Key.Rmd), [Key HTML](modules/Data_Classes/lab/Data_Classes_Lab_Key.html) | | +| | | | | | +| [Day 5](docs/module_details/day5.html) | Data Cleaning | [HTML](modules/Data_Cleaning/Data_Cleaning.html),[PDF](modules/Data_Cleaning/Data_Cleaning.pdf), [Rmd](modules/Data_Cleaning/Data_Cleaning.Rmd) | [Lab Rmd](modules/Data_Cleaning/lab/Data_Cleaning_Lab.Rmd), [Key](modules/Data_Cleaning/lab/Data_Cleaning_Lab_Key.Rmd), [Key HTML](modules/Data_Cleaning/lab/Data_Cleaning_Lab_Key.html) | [Day 5 Cheatsheet](modules/cheatsheets/Day-5.pdf) | +| | | | | | +| [Day 6](docs/module_details/day6.html) | Manipulating Data in R | [HTML](modules/Manipulating_Data_in_R/Manipulating_Data_in_R.html), [PDF](modules/Manipulating_Data_in_R/Manipulating_Data_in_R.pdf), [Rmd](modules/Manipulating_Data_in_R/Manipulating_Data_in_R.Rmd) | [Lab Rmd](modules/Manipulating_Data_in_R/lab/Manipulating_Data_in_R_Lab.Rmd), [Key](modules/Manipulating_Data_in_R/lab/Manipulating_Data_in_R_Lab_Key.Rmd), [Key HTML](modules/Manipulating_Data_in_R/lab/Manipulating_Data_in_R_Lab_Key.html) | [Day 6 Cheatsheet](modules/cheatsheets/Day-6.pdf) | +| | Intro to Data Visualization | [HTML](modules/Esquisse_Data_Visualization/Esquisse_Data_Visualization.html), [PDF](modules/Esquisse_Data_Visualization/Esquisse_Data_Visualization.pdf), [Rmd](modules/Esquisse_Data_Visualization/Esquisse_Data_Visualization.Rmd) | [Lab Rmd](modules/Esquisse_Data_Visualization/lab/Esquisse_Data_Visualization_Lab.Rmd), [Key](modules/Esquisse_Data_Visualization/lab/Esquisse_Data_Visualization_Lab_Key.Rmd), [Key HTML](modules/Esquisse_Data_Visualization/lab/Esquisse_Data_Visualization_Lab_Key.html) | | +| | Optional Homework 3 | | [HW Rmd](modules/HW/homework3.Rmd), [HTML](modules/HW/homework3.html), [Key](modules/HW/homework3_Key.Rmd), [Key HTML](modules/HW/homework3_Key.html) | | +| | | | | | +| [Day 7](docs/module_details/day7.html) | Data Visualization | [HTML](modules/Data_Visualization/Data_Visualization.html), [PDF](modules/Data_Visualization/Data_Visualization.pdf), [Rmd](modules/Data_Visualization/Data_Visualization.Rmd) | [Lab Rmd](modules/Data_Visualization/lab/Data_Visualization_Lab.Rmd), [Key](modules/Data_Visualization/lab/Data_Visualization_Lab_Key.Rmd), [Key HTML](modules/Data_Visualization/lab/Data_Visualization_Lab_Key.html) | [Day 7 Cheatsheet](modules/cheatsheets/Day-7.pdf) | +| | Factors | [HTML](modules/Factors/Factors.html), [PDF](modules/Factors/Factors.pdf), [Rmd](modules/Factors/Factors.Rmd) | [Lab Rmd](modules/Factors/lab/Factors_Lab.Rmd), [Key](modules/Factors/lab/Factors_Lab_Key.Rmd), [Key HTML](modules/Factors/lab/Factors_Lab_Key.html) | | +| | | | | | +| [Day 8](docs/module_details/day8.html) | Statistics | [HTML](modules/Statistics/Statistics.html), [PDF](modules/Statistics/Statistics.pdf), [Rmd](modules/Statistics/Statistics.Rmd) | [Lab Rmd](modules/Statistics/lab/Statistics_Lab.Rmd), [Key](modules/Statistics/lab/Statistics_Lab_Key.Rmd), [Key HTML](modules/Statistics/lab/Statistics_Lab_Key.html) | [Day 8 Cheatsheet](modules/cheatsheets/Day-8.pdf) | +| | Data Output | [HTML](modules/Data_Output/Data_Output.html), [PDF](modules/Data_Output/Data_Output.pdf), [Rmd](modules/Data_Output/Data_Output.Rmd) | [Lab Rmd](modules/Data_Output/lab/Data_Output_Lab.Rmd), [Key](modules/Data_Output/lab/Data_Output_Lab_Key.Rmd), [Key HTML](modules/Data_Output/lab/Data_Output_Lab_Key.html) | | +| | | | | | +| [Day 9](docs/module_details/day9.html) | Functions | [HTML](modules/Functions/Functions.html), [PDF](modules/Functions/Functions.pdf), [Rmd](modules/Functions/Functions.Rmd) | [Lab Rmd](modules/Functions/lab/Functions_Lab.Rmd), [Key](modules/Functions/lab/Functions_Lab_Key.Rmd), [Key HTML](modules/Functions/lab/Functions_Lab_Key.html) | [Day 9 Cheatsheet](modules/cheatsheets/Day-9.pdf) | +| | | | | | diff --git a/materials_schedule.Rmd b/materials_schedule.Rmd index cdec2d7c..1564e8bb 100644 --- a/materials_schedule.Rmd +++ b/materials_schedule.Rmd @@ -11,13 +11,13 @@ It's helpful to [install software](modules/Setup/Setup.html) before you start Da ## Online Overview -| Time (ET) | Content | -|-------------------|-----------| -| 1:30pm - 2:30pm | Session 1 | -| 2:30pm - 2:40pm | Break | -| 2:40pm - 3:40pm | Session 2 | -| 3:40pm - 3:50pm | Break | -| 3:50pm - 5:00pm | Session 3 | +| Time (PT) | Content | +|---------------------|-----------| +| 10:30am - 11:30am | Session 1 | +| 11:30am - 11:40am | Break | +| 11:40am - 12:40pm | Session 2 | +| 12:40pm - 12:50pm | Break | +| 12:50pm - 2:00pm | Session 3 | *Note: Timing is approximate* diff --git a/modules/Basic_R/Basic_R.Rmd b/modules/Basic_R/Basic_R.Rmd index 431badbf..17052f52 100644 --- a/modules/Basic_R/Basic_R.Rmd +++ b/modules/Basic_R/Basic_R.Rmd @@ -11,92 +11,51 @@ library(knitr) opts_chunk$set(comment = "") ``` -## Explaining output on slides +## Working in R -In slides, a command (we'll also call them code or a code chunk) will look like this +For now, we will be working in the **Console** (Pane 1 ) -```{r code} -class(3) -``` - -And then directly after it, will be the output of the code. -So `class(3)` is the code chunk and '[1] "numeric" ' is the output. - -## Running code chunks - -Send code to run in the console: - -- Run the whole chunk with the green play button (top right of the chunk) -- Run single line with ⌘+return or ctrl+return - -```{r, fig.alt="The green RStudio play button is highlighted with an arrow. Press this button to run all the code inside the chunk.", out.width = "60%", echo = FALSE, out.extra='style="float:left"'} -knitr::include_graphics("images/green_play_button.png") +```{r, fig.align='center', out.width="70%", echo = FALSE, fig.alt= "When RStudio is first opened you will see 3 panes"} +knitr::include_graphics("../RStudio/images/three_panes.png") ``` ## R as a calculator -```{r calcDemo} -2 + 2 -2 * 4 -2^3 -``` - -Note: when you enter your command in the Console, R inherently thinks you want to print the result. +- The R console is a full calculator +- Try to play around with it: + - +, -, /, \* are add, subtract, divide and multiply + - \^ or \*\* is power + - parentheses -- ( and ) -- work with order of operations + - %% finds the remainder ## R as a calculator -- The R console is a full calculator -- Try to play around with it: - - +, -, /, * are add, subtract, divide and multiply - - ^ or ** is power - - parentheses -- ( and ) -- work with order of operations - - %% finds the remainder - -## R as a calculator +Try evaluating the following. Type these in the Console and press *return* to evaluate: -```{r calcDemo2} -2 + (2 * 3)^2 -(1 + 3) / 2 + 45 -6 / 2 * (1 + 2) -``` +- `2 + 2` +- `2 * 3 / 4` +- `2^4 - 1` ```{r, fig.alt="Problem gives answer of 1 or 9 depending on calculator.", out.width = "30%", echo = FALSE, out.extra='style="float:left"'} knitr::include_graphics("images/Basic_R_calculator.jpg") ``` -```{r, fig.alt="Problem gives answer of 1 or 9 depending on calculator.", out.width = "60%", echo = FALSE, out.extra='style="float:left"'} -knitr::include_graphics("images/Basic_R_viral_math_problem.png") -``` - -## R as a calculator - -Try evaluating the following: +## Basic terms: "object" -- `2 + 2 * 3 / 4 -3` -- `2 * 3 / 4 * 2` -- `2^4 - 1` +**Object** - an object is something that can be worked with or on in R - can be lots of different things! -## Commenting in Scripts +You can think of objects as **nouns** in R. -`#` creates a comment in R code - -```{r} -# this is a comment +- a variable +- a dataset +- a plot -# nothing to its right is evaluated - -# this # is still a comment -### you can use many #'s as you want - -1 + 2 # Can be the right of code -``` - -In an `.Rmd` file, you can write notes outside the R chunks. +... many more ## Assigning values to objects -- You can create objects from within the R environment and from files on your computer -- R uses `<-` to assign values to an object name (you might also see `=` used, but this is not best practice) +- You can create objects within the R environment and from files on your computer +- R uses `<-` to create objects (you might also see `=` used, but this is not best practice) ```{r} x <- 2 @@ -105,22 +64,21 @@ x * 4 x + 2 ``` -## Assigning values to objects +## GUT CHECK: What is an "object"? -- The most comfortable and familiar class/data type for many of you will be `data.frame` -- You can think of these as essentially spreadsheets with rows (usually subjects or observations) and columns (usually variables) -- `data.frame`s are somewhat advanced objects in R; we will start with simpler objects +A. Something I can touch -## Assigning values to objects +B. Something that can be worked with in R + +C. A software version -- Here we introduce "1 dimensional" classes; often referred to as 'vectors' -- Vectors can have multiple sets of observations, but each observation has to be the same class. -- Use the `class()` function to check the class of an object. +## Objects with text -```{r assignClass} -class(x) +Create objects with text using quotation marks: + +```{r} y <- "hello world!" -class(y) +y ``` ## numeric vs. character classes? @@ -129,8 +87,8 @@ We will talk in-depth about classes. For now: **numeric** -- Numbers -- No quotation marks +- Numbers +- No quotation marks ```{r eval = FALSE} 2 @@ -138,8 +96,8 @@ We will talk in-depth about classes. For now: **character** -- Text with quotation marks -- Green lettering (default) +- Text with quotation marks +- Green lettering (default) ```{r eval = FALSE} "hello!" @@ -191,122 +149,113 @@ Try assigning your full name to an R object called `name` Try assigning your full name to an R object called `name` -```{r myName} +```{r} name <- "Ava Hoffman" name ``` -## The 'combine' function `c()` +## Combining objects with `c()` -The function `c()` collects/combines/joins single R objects into a vector of R objects. It is mostly used for creating vectors of numbers, character strings, and other data types. +Use `c()` to collect/combine single R objects into a vector of R objects. It is mostly used for creating vectors of numbers and character strings. -```{r assign3a} +```{r} x <- c(1, 4, 6, 8) x -class(x) ``` -## The 'combine' function `c()` +## Combining objects with `c()` -Try assigning your first and last name as 2 separate character strings into a single vector called `name2` +Try assigning your first and last name as 2 separate character strings into a vector called `name2` -## The 'combine' function `c()` +## Combining objects with `c()` -Try assigning your first and last name as 2 separate character strings into a length-2 vector called `name2` +Try assigning your first and last name as 2 separate character strings into a vector called `name2` -```{r myName2} +```{r} name2 <- c("Ava", "Hoffman") name2 ``` -## Arguments inside R functions +## Basic terms: "function" -- The contents you give to an R function are called "arguments" -- Here, R assumes all arguments should be objects contained in the vector -- We will talk more about arguments as we use more complicated functions! +**Function** - a function is a piece of code that allows you to do something in R. You can write your own, use functions that come directly from installing R, or use functions from additional packages. -```{r eval = FALSE} -name2 <- c("Ava", "Hoffman") -# Arg 1 ^^^^^ -``` +You can think of a function as **verb** in R. -```{r eval = FALSE} -name2 <- c("Ava", "Hoffman") -# Arg 2 ^^^^^^^^^ -``` +A function might help you add numbers together, create a plot, or organize your data. -## `length` of R objects +## Using functions on our vector -`length()`: Get or set the length of vectors (including lists) and factors, and of any other R object for which a method has been defined. +- `class()` tells us what kind of values the object contains (numeric, character, etc) +- `length()` tells us how many elements. -```{r assign3b} +```{r} +name +class(name) +x length(x) -y -length(y) ``` -## `length` of R objects +## GUT CHECK: What is a "function"? -What do you expect for the length of the `name` object? What about the `name2` object? +A. a number or text -What are the lengths of each? +B. a button inside RStudio -## `length` of R objects +C. code that does something -What do you expect for the length of the `name` object? What about the `name2` object? +## Combining vectors -What are the lengths of each? +It's fine to combine vectors, but all values will end up with the same class! -```{r myName3} -length(name) -length(name2) +```{r} +vect <- c(name, x) +vect +class(vect) ``` -## Math + vector objects +## Practicing functions -You can perform functions to entire vectors of numbers very easily. +What do you expect for the length of the `name2` object? -```{r assign4} -x + 2 -x * 3 -x + c(1, 2, 3, 4) -``` +What is the class? -## Lab Part 1 +## Practicing functions -- Assign values to objects with `<-` (new name on left side) -- `class()` tells you the class (kind) of object -- Use the `c()` function to combine text/numbers/etc. into a vector -- Use the `length()` function to determine number of elements +What do you expect for the length of the `name2` object? -💻 [Lab](https://daseh.org/modules/Basic_R/lab/Basic_R_Lab.Rmd) +What is the class? +```{r} +length(name2) +class(name2) +``` -# Pause for Day 1 +## Commenting in code -## Recap So Far +`#` creates a comment in R code -RStudio +```{r} +# 1 + 2 <- this does not get run -- The Editor is for static code like scripts or R Markdown documents -- Send code to the Console to run it -- The Console can be used for quickly testing code on the fly -- R code goes within what is called a chunk (the gray box with a green play button) +1 + 2 # <- this does +``` -📃[RStudio Cheatsheet](https://raw.githubusercontent.com/rstudio/cheatsheets/main/rstudio-ide.pdf) +## Lab Part 1 -## Recap So Far +- Assign values to objects with `<-` (new name on left side) +- Use the `c()` function to combine text/numbers/etc. into a vector +- `class()` tells you the class (kind) of object +- Use the `length()` function to determine number of elements +- `#` for comments or to deactivate a line of code -Basic R +Just open up the file to see the questions for lab. More about the file type soon! -- Use `c()` to **combine** vectors -- Use `<-` to save (assign) values to objects -- if you don't use `<-` to reassign objects that you want to modify, they will stay the same -- `length()` and `class()` tell you information about an object +💻 [Lab](https://daseh.org/modules/Basic_R/lab/Basic_R_Lab.Rmd) ## Math + vector objects -You can perform functions to entire vectors of numbers very easily. +You can perform math with vectors. ```{r} x + 2 @@ -316,7 +265,7 @@ x + c(1, 2, 3, 4) ## Math + vector objects -But things like algebra can only be performed on numbers. +But math can only be performed on numbers. ```{r, error=TRUE} name2 + 4 @@ -331,7 +280,7 @@ y <- x + c(1, 2, 3, 4) y ``` -Note that the R object `y` is no longer "hello world!" - It has been overwritten by assigning new data to the same name. +Note that the R object `y` is no longer "hello world!" - It has been overwritten by assigning new data to the same name. ## Reassigning to a new object @@ -359,20 +308,24 @@ str(y) This tells you that `x` is a numeric vector and tells you the length. -## Lab Part 2 +## Basic terms: "argument" -- Reassigning allows you to make changes "in place" -- `str()` tells you a lot of information about an object in your environment +**Argument** - what you pass to a function -💻 [Lab](https://daseh.org/modules/Basic_R/lab/Basic_R_Lab.Rmd) +- can be data like the number 1 or 20234 +- can be options about how you want the function to work +- separated by commas + +Like an **adverb**. + +## Create vectors with `seq()` -## Useful functions to create vectors `seq()` +For numeric: `seq()` -For numeric: `seq()` can be very useful- both integer and double. -The `from` argument says what number to start on. -The `to` argument says what number to not go above. -The `by` argument says how much to increment by. -The `length.out` argument says how long the vector should be overall. +- The `from` argument says what number to start on.\ +- The `to` argument says what number to not go above.\ +- The `by` argument says how much to increment by.\ +- The `length.out` argument says how long the vector should be overall. ```{r} seq(from = 0, to = 1, by = 0.2) @@ -382,11 +335,9 @@ seq(from = -5, to = 5, length.out = 10) ## Useful functions to create vectors `rep()` -For character: `rep()` can create very long vectors. -Works for creating character and numeric vectors. +For character: `rep()` can create very long vectors. Works for creating character and numeric vectors. -The `each` argument specifies how many of each item you want repeated. -The `times` argument specifies how many times you want the vector repeated. +The `each` argument specifies how many of each item you want repeated. The `times` argument specifies how many times you want the vector repeated. `rep(WHAT_TO_REPEAT, arguments)` @@ -398,10 +349,7 @@ rep(c("black", "white"), each = 2, times = 2) ## Creating numeric vectors `sample()` - You can use the `sample()` function to make a random sequence. - The `x` argument specifies what you are sampling from. - The `size` argument specifies how many values there should be. - The `replace` argument specifies if values should be replaced or not. +You can use the `sample()` function to make a random sequence. The `x` argument specifies what you are sampling from. The `size` argument specifies how many values there should be. The `replace` argument specifies if values should be replaced or not. ```{r} seq_hun <- seq(from = 0, to = 100, by = 1) @@ -410,15 +358,46 @@ y <- sample(x = seq_hun, size = 5, replace = TRUE) y ``` +## Installing packages to do more! + +Some functions and data come with R right out of the box ("base R"). We will add more functionality with packages. Think of these like "expansion packs" for R. + +Must be done **once** for each installation of R (e.g., version 4.2 \>\> 4.3). + +An important package we will use is `tidyverse`. It is a mega-package great for data import, wrangling, and visualization. + +```{r eval = FALSE} +install.packages("tidyverse") +``` + +## Loading packages + +After installing packages, you will need to "load" them into memory so that you can use them. + +This must be done **every time** you start R. + +We use a function called `library` to load packages. + +```{r, eval = FALSE} +library(tidyverse) +``` + +## Installing + Loading packages + +```{r, fig.alt="Installing must be done once via 'install.packages() while loading must be done every R session via 'library()'.", out.width = "80%", echo = FALSE, fig.align='center'} +knitr::include_graphics("../../images/lol/install_packages.jpg") +``` + ## Summary -- R functions as a calculator -- Use `<-` to save (assign) values to objects -- Use `c()` to **combine** vectors -- `length()`, `class()`, and `str()` tell you information about an object -- The sequence `seq()` function helps you create numeric vectors (`from`,`to`, `by`, and `length.out` arguments) -- The repeat `rep()` function helps you create vectors with the `each` and `times` arguments -- `sample()` makes random vectors +- R functions as a calculator +- Use `<-` to save (assign) values to objects. Reassigning allows you to make changes "in place". +- Use `c()` to **combine** into vectors +- `length()`, `class()`, and `str()` tell you information about an object +- The sequence `seq()` function helps you create numeric vectors (`from`,`to`, `by`, and `length.out` arguments) +- The repeat `rep()` function helps you create vectors with the `each` and `times` arguments +- `sample()` makes random vectors +- `install.packages()` and `library()` install and load packages, respectively. ## Summary diff --git a/modules/Basic_R/lab/Basic_R_Lab_Key.Rmd b/modules/Basic_R/lab/Basic_R_Lab_Key.Rmd index b91b2707..478498f9 100644 --- a/modules/Basic_R/lab/Basic_R_Lab_Key.Rmd +++ b/modules/Basic_R/lab/Basic_R_Lab_Key.Rmd @@ -9,24 +9,21 @@ editor_options: knitr::opts_chunk$set(echo = TRUE) ``` - -In this lab you can use the interactive console to explore or **Knit** the document. -Remember anything you type here can be "sent" to the console with Cmd-Enter (OS-X) or Ctrl-Enter (Windows/Linux) in an R code chunk. - +Instructions: Paste your code from the console in the gray boxes below. # Part 1 ### 1.1 -Create a new object called `my.num` that contains 6 numbers. +Create a new object called `my.num` that contains any number. ``` # General format -my.num <- c(number1, number2, ...) +my.num <- ? ``` ```{r 1.1response} -my.num <- c(5, 4, 7, 8, 12, 14) # These can be any real numbers +my.num <- 2 ``` ### 1.2 @@ -96,7 +93,56 @@ vec_2 <- c(vec_1, vec_1, vec_1, vec_1) # Part 2 -### 2.1 +### 2.1 + +Create a vector with elements 1, 10, 100, 1000 and call it `z`. + +``` +# General format +z <- c(...) +``` + +```{r 2.1response} +z <- c(1, 10, 100, 1000) +``` + +### 2.2 + +Multiply each number in `z` by 5. + +```{r 2.2response} +z * 5 +``` + +### 2.3 + +Create a vector object called `int_vect` that starts at 1 and goes up to 10. Use `seq()`. + +``` +# General format +seq(from = NUMBER, to = NUMBER) +``` + +```{r 2.3response} +int_vect <- seq(from = 1, to = 10) +int_vect +``` + +### 2.4 + +What is the length of `int_vect`? + +```{r 2.4response} +length(int_vect) +``` + +### 2.5 + +Install the tidyverse package using `install.packages("tidyverse")`. Load this package using `library(tidyverse)`. + +# Practice on Your Own! + +### P.2 Create a vector with elements 1, 2, 3, 4, 5 and call it `x`. @@ -105,11 +151,11 @@ Create a vector with elements 1, 2, 3, 4, 5 and call it `x`. x <- c(...) ``` -```{r 2.1response} +```{r P.2response} x <- c(1, 2, 3, 4, 5) ``` -### 2.2 +### P.3 Create another vector with elements 10, 20, 30, 40, 50 and call it `y`. @@ -118,22 +164,22 @@ Create another vector with elements 10, 20, 30, 40, 50 and call it `y`. y <- c(...) ``` -```{r 2.2response} +```{r P.3response} y <- c(10, 20, 30, 40, 50) ``` -### 2.3 +### P.4 Determine the length of `x` and `y`. Next, add the vectors x and y together. -```{r 2.3response} +```{r P.4response} length(x) length(y) x + y # [1] 11 22 33 44 55 ``` -### 2.4 +### P.5 Append the value 60 onto the vector `y` (hint: you can use the `c()` function). @@ -142,24 +188,24 @@ Append the value 60 onto the vector `y` (hint: you can use the `c()` function). y <- c(y, ...) ``` -```{r 2.4response} +```{r P.5response} y <- c(y, 60) ``` -### 2.5 +### P.6 Determine the length of `x` and `y`. -```{r 2.5response} +```{r P.6response} length(x) length(y) ``` -### 2.6 +### P.7 Add `x` and `y` together. What happens? -```{r 2.6response} +```{r P.7response} x + y # [1] 11 22 33 44 55 61 # Warning message: @@ -168,10 +214,7 @@ x + y # In this case, it reads x as c(1, 2, 3, 4, 5, 1)! ``` - -# Practice on Your Own! - -### P.2 +### P.8 Multiply the following `a` and `b` together. How is this similar to the way R performs addition in question 2.6 ? @@ -180,69 +223,27 @@ a <- c(1, 2, 3) b <- c(10, 100, 1000) ``` -```{r P.2response} +```{r P.8response} a * b # R adds together the first element of each vector, then the second, and so on. This order also applies when multiplying! ``` - -# Part 3 - -### 3.1 - -Create a vector object called `int_vect` that starts at 1 and goes up to 10. Use `seq()`. - -``` -# General format -seq(from = NUMBER, to = NUMBER) -``` - -```{r 3.1response} -int_vect <- seq(from = 1, to = 10) -int_vect -``` - -### 3.2 - -Repeat the `int_vect` object this sequence 3 times using `rep()` and store the new object as `int_vect_3`. - -``` -# General format - times and each are optional -rep(x = OBJECT_TO_REPEAT, times = NUM_TIMES_TO_REPEAT, each = NUM_TIMES_TO_REPEAT_EACH_ELEMENT) -``` - -```{r 3.2response} -int_vect_3 <- rep(int_vect, times = 3) -int_vect_3 -``` - -### 3.3 - -What is the length of `int_vect_3`? - -```{r 3.3response} -length(int_vect_3) -``` - -### 3.4 +### P.9 Create a vector that takes the sequence "Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree" and repeats each element 10 times. -```{r 3.4response} +```{r P.9response} my_seq <- c("Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree") rep(my_seq, each = 10) rep(c("Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree"), each = 10) ``` - -# Practice on Your Own! - -### P.3 +### P.10 "Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree" are often responses to surveys. Create a randomly sampled vector of 30 survey responses. (hint use `sample()` and set the replace argument to `TRUE`). Store the output as `my_responses`. Examine the data by typing the name `my_responses` in the Console. -```{r P.3response} +```{r P.10response} my_responses <- sample( x = c("Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree"), size = 30, @@ -251,11 +252,11 @@ my_responses <- sample( my_responses ``` -### P.4 +### P.11 Let's say you change your survey so participants can rank their response 1-10 (inclusive). Create a randomly sampled vector of 30 survey responses. (hint use `seq()` and `sample()` and set the replace argument to `TRUE`). Store the output as `my_responses_2`. Examine the data by typing the name `my_responses_2` in the Console. -```{r P.4response} +```{r P.11response} my_responses_2 <- sample( x = seq(from = 1, to = 10), size = 30, diff --git a/modules/Intro/Intro.Rmd b/modules/Intro/Intro.Rmd index 42054ef8..258984de 100644 --- a/modules/Intro/Intro.Rmd +++ b/modules/Intro/Intro.Rmd @@ -37,7 +37,7 @@ Associate, Department of Biostatistics, JHSPH PhD in Biomedical Sciences -Email: [cwright2\@fredhutch.org](mailto:cwright2@fredhutch.org){.email} Web: https://carriewright11.github.io +Email: [cwright2\@fredhutch.org](mailto:cwright2@fredhutch.org){.email} Web: [`https://carriewright11.github.io`](https://carriewright11.github.io) ```{r, fig.alt="Carrie's picture", out.width = "30%", echo = FALSE, fig.align='center'} knitr::include_graphics(here::here("modules", "Intro", "images", "carrie.png")) @@ -53,7 +53,7 @@ Associate, Department of Biostatistics, JHSPH PhD in Ecology -Email: [ahoffma2\@fredhutch.org](mailto:ahoffma2@fredhutch.org){.email} Web: https://avahoffman.com +Email: [ahoffma2\@fredhutch.org](mailto:ahoffma2@fredhutch.org){.email} Web: [`https://avahoffman.com`](https://avahoffman.com) ```{r, fig.alt="Ava's picture", out.width = "30%", echo = FALSE, fig.align='center'} knitr::include_graphics(here::here("modules", "Intro", "images", "ava.png")) @@ -79,8 +79,7 @@ knitr::include_graphics(here::here("modules", "Intro", "images", "elizabeth.jpg" Please introduce yourself on Slack! -[Slack Workspace](`r config::get("slack_workspace")`) - +[Slack Workspace](%60r%20config::get(%22slack_workspace%22)%60) ## The Learning Curve @@ -108,27 +107,13 @@ knitr::include_graphics("images/low-five-high-five.gif") - R is a language and environment for statistical computing and graphics developed in 1991 -- R is the open source implementation of the [S language](https://en.wikipedia.org/wiki/S_(programming_language)), which was developed by [Bell laboratories](https://ca.slack-edge.com/T023TPZA8LF-U024EN26Q0L-113294823b2c-512) in the 70s. - -- The aim of the S language, as expressed by John Chambers, is "to turn ideas into software, quickly and faithfully" - -```{r, fig.alt="Bell Labs old logo", out.width = "40%", echo = FALSE, fig.align='center'} -knitr::include_graphics("https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Bell_Laboratories_logo.svg/2880px-Bell_Laboratories_logo.svg.png") -``` - -[source: , [https://en.wikipedia.org/wiki/S\_(programming_language)](https://en.wikipedia.org/wiki/S_(programming_language)){.uri}, )] - -## What is R? - -- **R**oss Ihaka and **R**obert Gentleman at the University of Auckland, New Zealand developed R - - R is both [open source](https://en.wikipedia.org/wiki/Open_source) and [open development](https://en.wikipedia.org/wiki/Open-source_software_development) ```{r, fig.alt="R logo", out.width = "20%", echo = FALSE, fig.align='center'} knitr::include_graphics("images/Rlogo.png") ``` -[source: , [https://en.wikipedia.org/wiki/R\_(programming_language)](https://en.wikipedia.org/wiki/R_(programming_language)){.uri}] +[source: ] ## Why R? @@ -204,14 +189,18 @@ ONLINE VIRTUAL COURSE - Lecture with slides, interactive\ - Lab/Practical experience\ - Two 10 min breaks each day - timing may vary\ -- July 8-18, 10:30am - 2:00pm PST on Zoom +- Sep 30 - Oct 10, 10:30am - 2:00pm PST on Zoom + +## Course Format IN-PERSON CODE-A-THON - Mostly independent group work\ - Frequent check-ins with instructors and other groups\ - Some lectures about the practical aspects of coding\ -- July 29-31 (in person in Seattle) +- Oct 23 - 25 (in person in Seattle) + +**Deadline for arranging travel assistance is October 11!** ## Pulse Check Survey @@ -233,9 +222,11 @@ We encourage you to try the assignments, as the best way to get comfortable with ## Your Setup -If you can, we suggest working virtually with a **large monitor or two screens**. This setup allows you to follow along on Zoom while also doing the hands-on coding. +If you can, we suggest working virtually with a **large monitor or two screens**. -```{r, fig.alt="Surveys count", out.width = "40%", echo = FALSE, fig.align='center'} +This setup allows you to follow along on Zoom while also doing the hands-on coding. + +```{r, fig.alt="Surveys count", out.width = "30%", echo = FALSE, fig.align='center'} knitr::include_graphics("images/monitors.jpg") ``` @@ -247,251 +238,13 @@ knitr::include_graphics("images/monitors.jpg") We are collecting data about user experience with our course to learn more about how to improve the data science education experience. This data may ultimately be used for a research publication and reporting to the NIH. -https://forms.gle/e2CQFDJsgyZwLV3S9 - -# Getting Started - -## Installing R - -- Install the [latest R version](http://cran.r-project.org/) `r config::get("r_version")` - -- [Install RStudio](https://www.rstudio.com/products/rstudio/download/) - -More detailed instructions [on the website](https://daseh.org/docs/module_details/day0.html). - -RStudio is an **integrated development environment** (IDE) that makes it easier to work with R. - -More on that soon! - -## Getting files from downloads - -This course will involve moving files around on your computer and downloading files. - -If you are new to this - check out these videos. - -If you have a PC: https://youtu.be/we6vwB7DsNU - -If you have a Mac: https://www.youtube.com/watch?v=Ao9e0cDzMrE - -You can find these on the resource page of the website. - -## Basic terms - -R jargon: https://link.springer.com/content/pdf/bbm%3A978-1-4419-1318-0%2F1.pdf - -**Package** - a package in R is a bundle or "package" of code (and or possibly data) that can be loaded together for easy repeated use or for **sharing** with others. - -Packages are analogous to a software application like Microsoft Word on your computer. Your operating system allows you to use it, just like having R installed (and other required packages) allows you to use packages. - -```{r, fig.alt="R hex stickers for packages", out.width = "35%", echo = FALSE, fig.align='center'} -knitr::include_graphics("images/hex.png") -``` - -## Basic terms - -**Function** - a function is a piece of code that allows you to do something in R. You can write your own, use functions that come directly from installing R, or use functions from additional packages. - -You can think of a function as **verb** in R. - -A function might help you add numbers together, create a plot, or organize your data. More on that soon! - -```{r} -sum(1, 20234) -``` - -## Basic terms - -**Argument** - what you pass to a function - -- can be data like the number 1 or 20234 - -```{r} -sum(1, 20234) -``` - -- can be options about how you want the function to work such as `digits` - -```{r} -round(0.627, digits = 2) -round(0.627, digits = 1) -``` - -## Basic terms - -**Object** - an object is something that can be worked with or on in R - can be lots of different things! You can think of objects as **nouns** in R. - -- a matrix of numbers -- a plot -- a function -- data - -... many more - -## Variable and Sample - -- **Variable**: something measured or counted that is a characteristic about a sample - -examples: temperature, length, count, color, category - -- **Sample**: individuals that you have data about - - -examples: people, houses, viruses etc. - -```{r} -head(iris) -``` - -## Columns and Rows - -```{r, fig.alt="R hex stickers for packages", out.width = "50%", echo = FALSE, fig.align='center'} -knitr::include_graphics("https://keydifferences.com/wp-content/uploads/2016/09/rows-vs-column.jpg") -``` - -[[source](https://keydifferences.com/difference-between-rows-and-columns.html)] - -Sample = Row\ -Variable = Column - -Data objects that looks like this is often called a **data frame**. - -Fancier versions from the tidyverse are called **tibbles** (more on that soon!). - -## More on Functions and Packages - -- When you download R, it has a "base" set of functions/packages (**base R**) - - You can install additional packages for your uses from [CRAN](https://cran.r-project.org/) or [GitHub](https://github.com/) - - These additional packages are written by RStudio or R users/developers (like us) - - There are also packages for bioinformatics available at [Bioconductor](https://www.bioconductor.org/) - -```{r, fig.alt="Picture of R package stickers", out.width = "30%", echo = FALSE, fig.align='center'} -knitr::include_graphics("../Intro/images/hex.png") -``` - -## Using Packages - -- Not all packages available on CRAN or GitHub are trustworthy -- Posit makes [many useful packages](https://posit.co/products/open-source/rpackages/) -- How to [trust](https://simplystatistics.org/posts/2015-11-06-how-i-decide-when-to-trust-an-r-package/) an R package -- Many packages have accompanying academic papers published in peer-reviewed journals -- Widely used packages have better documentation (official and in forums) and are more likely free of errors - -## Tidyverse and Base R: Two Dialects - -We will mostly show you how to use tidyverse packages and functions. - -This is a newer set of packages designed for data science that can make your code more **intuitive** as compared to the original older Base R. - -**Tidyverse advantages**:\ -- **consistent structure** - making it easier to learn how to use different packages\ -- particularly good for **wrangling** (manipulating, cleaning, joining) data\ -- more flexible for **visualizing** data - -Packages for the tidyverse are managed by a team of respected data scientists at Posit. - -```{r, fig.alt="Tidyverse hex sticker", out.width = "10%", echo = FALSE, fig.align='center'} -knitr::include_graphics("https://tidyverse.tidyverse.org/logo.png") -``` - -See this [article](https://tidyverse.tidyverse.org/articles/paper.html) for more info. - -## Package Installation - -We will practice this in labs :) - -Differs depending on the source (CRAN, GitHub, etc) - -Must be done **once** for each installation of R (e.g., version 4.2 \>\> 4.3). - -## Installing Packages: Dropdown Menu - -You can install packages from CRAN using the tool menu in RStudio: - -tools \> Install Packages - -```{r, fig.alt="Install packages menu in RStudio", out.width = "20%", echo = FALSE, fig.align='center'} -knitr::include_graphics("images/install_packages1.png") -``` - -Type in the package name to install. - -```{r, fig.alt="The 'readr' package has been typed into the dropdown menu", out.width = "30%", echo = FALSE, fig.align='center'} -knitr::include_graphics("images/install_packages2.png") -``` - -## Installing Packages: Using Code - -We use a function called `install.packages()` for CRAN packages. - -Here is an example where we "install" the `dplyr` package: - -```{r, eval = FALSE} -install.packages("dplyr") -``` - -The package name is enclosed in quotation marks. - -## Loading packages - -After installing packages, you will need to "load" them into memory so that you can use them. - -This must be done **every time** you start R. - -We use a function called `library` to load packages. - -Here is an example where we "load" the `dplyr` package: - -```{r, eval = FALSE} -library(dplyr) -``` - -Quotation marks are optional. - -## Installing + Loading packages - -```{r, fig.alt="Installing must be done once via 'install.packages() while loading must be done every R session via 'library()'.", out.width = "80%", echo = FALSE, fig.align='center'} -knitr::include_graphics("images/install_v_load.png") -``` - -## Installing + Loading packages - -```{r, fig.alt="Installing must be done once via 'install.packages() while loading must be done every R session via 'library()'.", out.width = "80%", echo = FALSE, fig.align='center'} -knitr::include_graphics("../../images/lol/install_packages.jpg") -``` - -# Let's practice! - -## Installing `remotes` and `dasehr` - -Install the `remotes` package. - -```{r, eval=F} -install.packages("remotes") -``` - -
- -Then load the package. - -```{r, eval=F} -library(remotes) -``` - -## Installing `remotes` and `dasehr` - -Next, run the following. - -It will install our custom package, `dasehr` from GitHub. - -```{r, eval=F} -install_github("fhdsl/dasehr") -``` - +[`https://forms.gle/vxp8vxdN2Ck2j7uY6`](https://forms.gle/vxp8vxdN2Ck2j7uY6) # Where to find help ## Useful (+ mostly Free) Resources -Found on our website under the `Resources` tab: https://daseh.org/resources.html +Found on our website under the `Resources` tab: - videos from previous offerings of the class - cheatsheets for each class @@ -500,7 +253,7 @@ Found on our website under the `Resources` tab: https://daseh.org/resources.html Error messages can be scary! -- Check out the FAQ/Help page on the website: https://daseh.org/help.html +- Check out the FAQ/Help page on the website: - Ask questions in Slack! Copy+pasting your error messages is really helpful! **We will also dedicate time today to debug any installation issues** @@ -509,26 +262,28 @@ Error messages can be scary! knitr::include_graphics("images/forrest-gump-running.gif") ``` -## Summary +## Installing R -- R is a powerful data visualization and analysis software language. -- Add-on **packages** like the `tidyverse` can help make R more intuitive. -- **Functions** (like verbs) perform specific tasks in R and are found within packages. -- **Arguments** within functions specify how to perform a function. -- **Objects** (like nouns) are data or variables. -- We will be both installing and loading packages. -- Materials will be updated frequently as we improve it. Please use the **Google Form survey** so you can provide feedback throughout the class! -- Lots of **resources** can be found on the website. *You will have access to the website after the class is over.* +- Install the [latest R version](http://cran.r-project.org/) `r config::get("r_version")` -🏠 [Class Website](https://daseh.org/) +- [Install RStudio](https://www.rstudio.com/products/rstudio/download/) -## Website tour! +- [R Tools Issue](https://daseh.org/help.html#im-getting-an-error-related-to-something-called-rtools) -🏠 [Class Website](https://daseh.org/) +More detailed instructions [on the website](https://daseh.org/docs/module_details/day0.html). -```{r, fig.alt="The End", out.width = "50%", echo = FALSE, fig.align='center'} -knitr::include_graphics(here::here("images/the-end-g23b994289_1280.jpg")) -``` +RStudio is an **integrated development environment** (IDE) that makes it easier to work with R. -Image by Gerd Altmann from Pixabay +More on that soon! + +## Summary + +🏠 [Class Website - https://daseh.org/](https://daseh.org/) - Logistics, resources, and help! + +📝 [Research Survey](https://forms.gle/vxp8vxdN2Ck2j7uY6) +🩺 [Pulse Check](%60r%20config::get(%22google_survey%22)%60) + +## Summary + +Image by Gerd Altmann from Pixabay diff --git a/modules/Manipulating_Data_in_R/lab/Manipulating_Data_in_R_Lab.Rmd b/modules/Manipulating_Data_in_R/lab/Manipulating_Data_in_R_Lab.Rmd index b69d659b..ebec2e5b 100644 --- a/modules/Manipulating_Data_in_R/lab/Manipulating_Data_in_R_Lab.Rmd +++ b/modules/Manipulating_Data_in_R/lab/Manipulating_Data_in_R_Lab.Rmd @@ -44,7 +44,7 @@ Look at the column names using `colnames` - do you notice any patterns? Let's rename the columns "co2" from this type of format: "2011" to this: "CO2_2011" using `rename`. Be sure to do this for all years 2012, 2013, and 2014. Make sure that you end up with the renamed columns in a data frame named `co2` here and in subsequent steps. -Hint: If you run code to rename the columns and store back into a data frame of the same name like `co2` you will not be able to re-run the renaming code without error (the columns are already renamed so it won't be able to find the oldname of the column anymore) +Hint: If you run code to rename the columns and store back into a data frame of the same name like `co2` you will not be able to re-run the renaming code without error (the columns are already renamed so it won't be able to find the old name of the column anymore) ``` # General format diff --git a/modules/RStudio/RStudio.Rmd b/modules/RStudio/RStudio.Rmd index fbe75dcf..688d66dd 100644 --- a/modules/RStudio/RStudio.Rmd +++ b/modules/RStudio/RStudio.Rmd @@ -123,7 +123,7 @@ Super useful "cheat sheet": [LINK](https://raw.githubusercontent.com/rstudio/che knitr::include_graphics("images/rstudio_sheet.png") ``` -## R Markdown files look different form scripts +## R Markdown files look different from scripts It will look like this with text in it, unlike a script. diff --git a/modules/cheatsheets/Day-1.md b/modules/cheatsheets/Day-1.md index 81b7fe48..15afa559 100644 --- a/modules/cheatsheets/Day-1.md +++ b/modules/cheatsheets/Day-1.md @@ -1,35 +1,42 @@ --- -classoption: -- landscape +classoption: landscape +output: + pdf_document: default + html_document: + df_print: paged --- # Day 1 Cheatsheet -## Intro +## Basic R ### Major concepts -- **Package** - a package in R is a bundle or “package” of code (and or possibly data) -that can be loaded together for easy repeated use or for sharing with others. -- **Function** - a function is a particular piece of code that allows you to do -something in R. You can write your own, use functions that come directly from -installing R, or use functions from additional packages. +- **Package** - a package in R is a bundle or “package” of code (and or possibly data) that can be loaded together for easy repeated use or for sharing with others. Like an "expansion pack". +- **Function** - a function is a particular piece of code that allows you to do something in R. You can write your own, use functions that come directly from installing R, or use functions from additional packages. - **Argument** - an option that you specify to a function. -- **Object** - an object is something that can be worked with in R - can be lots of -different things! -- **Variable** something measured or counted that is a characteristic about a -sample. -- **Sample** individuals that you have data about - e.g. people, houses, viruses etc.\ -- **Data frames** A collection of variables and samples in a row/column format. Sample = Row, Variable = Column -- [**Tidyverse**](https://tidyverse.tidyverse.org/articles/paper.html) - This is a newer set of packages designed for data science that can make your -code more intuitive as compared to the original older Base R. - +- **Object** - an object is something that can be worked with in R - can be lots of different things! +- [**Tidyverse**](https://tidyverse.tidyverse.org/articles/paper.html) - This is a newer set of packages designed for data science that can make your code more intuitive as compared to the original older Base R. +- The R console is a full calculator: + - `+`, `-`, `/`, `*` are add, subtract, divide and multiply + - `^` or `**` is power + - parentheses – ( and ) – work with order of operations + - %% finds the remainder +- `#` is the comment symbol; nothing to its right is evaluated. ### Functions |Library/Package|Piece of code|Example of usage|What it does| |---------------|-------------|----------------|-------------| -|Base `R`|[`install.packages()`](https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/install.packages)| `install.packages("remotes")`| Installs packages| -|Base `R`| [`library()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/library)|`library(remotes)`| Loads and attaches additional packages to the R environment.| +| Base `R`| [`<-`](https://stat.ethz.ch/R-manual/R-devel/library/base/html/assignOps.html)| `x <- 1`| Assigns a name `x` to something in the R environment.| +| Base `R`| [`c()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/c)| `x <- c(1, 3)`| Combines values into a vector. | +| Base `R`| [`str()`](https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/str)|`str(x)`| Gets a summary of the object `x` structure.| +| Base `R`| [`class()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/class)|`class(x)`| Returns the type of the values in object `x`.| +| Base `R`| [`length()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/length)|`length(x)`| Returns how long the object `x` is. | +| Base `R`| [`seq()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/seq)|`seq(from = 0, to = 100, by = 5)`| Generate regular sequences. | +| Base `R`| [`rep()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/rep)|`rep(1, times = 10)`| Replicates the values in x. Can take `times` or `length.out` argument.| +| Base `R`| [`sample()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/sample)|`sample(1:12)`| Takes a sample of the specified size from the elements of x using either with or without replacement. `replace = TRUE` samples with replacement. | +| Base `R`| [`install.packages()`](https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/install.packages)| `install.packages("tidyverse")`| Installs packages| +| Base `R`| [`library()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/library)|`library(tidyverse)`| Loads and attaches additional packages to the R environment. Done every time you start R.|
@@ -56,26 +63,4 @@ output.
-## Reproducibility - -### Major concepts - -- **Reproducibility** - A different analyst re-performs the analysis with the same code and the same data and obtains the same -result. -- **Repeatable** - keeping everything the same but repeating the analysis - do we get the same results -- **Reproducible** - using the same data and analysis but in the hands of another researcher - do we get the same results? -- **Replicable** - with new data do we obtain the same inferences? - -### Functions -|Library/Package|Piece of code|Example of usage|What it does| -|---------------|-------------|----------------|-------------| -| Base `R`| [`sessionInfo()`](https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/sessionInfo) |`sessionInfo()`| Returns the R version information, the OS, and the attached packages in the current R session.| - -### More resources -- [The RMarkdown book](https://bookdown.org/yihui/rmarkdown/) -- [Jenny Bryan's organizational strategies](https://www.stat.ubc.ca/~jenny/STAT545A/block19_codeFormattingOrganization.html). -- [Write efficient R code for science](https://www.earthdatascience.org/courses/earth-analytics/automate-science-workflows/write-efficient-code-for-science-r/). -- [Reproducibility in Cancer Informatics course](https://jhudatascience.org/Reproducibility_in_Cancer_Informatics/introduction.html) - - \* This format was adapted from the [cheatsheet format from AlexsLemonade](https://github.com/AlexsLemonade/training-modules/tree/master/module-cheatsheets). diff --git a/modules/cheatsheets/Day-1.pdf b/modules/cheatsheets/Day-1.pdf index 646ffb6d..c65feb57 100644 Binary files a/modules/cheatsheets/Day-1.pdf and b/modules/cheatsheets/Day-1.pdf differ diff --git a/modules/cheatsheets/Day-2.md b/modules/cheatsheets/Day-2.md index 6732b201..1e131a7a 100644 --- a/modules/cheatsheets/Day-2.md +++ b/modules/cheatsheets/Day-2.md @@ -1,33 +1,30 @@ --- -classoption: -- landscape +classoption: landscape +output: pdf_document --- # Day 2 Cheatsheet -## Basic R +## Reproducibility ### Major concepts -- **Package** - a package in R is a bundle or “package” of code (and or possibly data) -that can be loaded together for easy repeated use or for sharing with others. -- The R console is a full calculator: - - `+`, `-`, `/`, `*` are add, subtract, divide and multiply - - `^` or `**` is power - - parentheses – ( and ) – work with order of operations - - %% finds the remainder -- `#` is the comment symbol; nothing to its right is evaluated. - +- **Reproducibility** - A different analyst re-performs the analysis with the same code and the same data and obtains the same +result. +- **Repeatable** - keeping everything the same but repeating the analysis - do we get the same results +- **Reproducible** - using the same data and analysis but in the hands of another researcher - do we get the same results? +- **Replicable** - with new data do we obtain the same inferences? ### Functions |Library/Package|Piece of code|Example of usage|What it does| |---------------|-------------|----------------|-------------| -| Base `R`| [`<-`](https://stat.ethz.ch/R-manual/R-devel/library/base/html/assignOps.html)| `x <- 1`| Assigns a name to something in the R environment.| -| Base `R`| [`c()`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/c)| `x <- c(1, 3)`| Combines values into a vector or list. | -| Base `R`| [`str(x)`](https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/str)|`str(x)`| Gets a summary of the object `x` structure.| -| Base `R`| [`class(x)`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/class)|`class(x)`| Returns the type of the values in object `x`.| -| Base `R`| [`print(x)`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/print)|`print(x)`| Prints out contents of `x`.| -| Base `R`| [`length(x)`](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/length)|`length(x)`| Returns how long the object `x` is. | +| Base `R`| [`sessionInfo()`](https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/sessionInfo) |`sessionInfo()`| Returns the R version information, the OS, and the attached packages in the current R session.| + +### More resources +- [The RMarkdown book](https://bookdown.org/yihui/rmarkdown/) +- [Jenny Bryan's organizational strategies](https://www.stat.ubc.ca/~jenny/STAT545A/block19_codeFormattingOrganization.html). +- [Write efficient R code for science](https://www.earthdatascience.org/courses/earth-analytics/automate-science-workflows/write-efficient-code-for-science-r/). +- [Reproducibility in Cancer Informatics course](https://jhudatascience.org/Reproducibility_in_Cancer_Informatics/introduction.html)
diff --git a/modules/cheatsheets/Day-2.pdf b/modules/cheatsheets/Day-2.pdf index 5fe895fd..74440881 100644 Binary files a/modules/cheatsheets/Day-2.pdf and b/modules/cheatsheets/Day-2.pdf differ