Skip to content

Commit

Permalink
Merge pull request #612 from jhudsl/several-updates
Browse files Browse the repository at this point in the history
Clarify RStudio lab
  • Loading branch information
avahoffman authored Jul 12, 2024
2 parents 43aee9e + 9b9f2db commit 052ebea
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions modules/RStudio/lab/RStudio_Lab_Key.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@ Now we will install some packages! Note it may take ~5-10 minutes to run all the

### 0.1

First copy and paste the following code into the console (the lower left panel/pane) - **but do not copy the backticks**: <br>
`install.packages("remotes")`<br>
First copy and paste the following code into the console (the lower left panel/pane):
install.packages("remotes")

This code will install a package from CRAN called "remotes". <br>
You may be asked a question in the console when you do this. If so, answer by typing Yes into the console.

### 0.2

Next copy and paste the following code again into the console (the lower left panel/pane), **again do not copy the backticks**: <br>
`library(remotes)` <br>
Next copy and paste the following code again into the console (the lower left panel/pane):
library(remotes)

This code loads the remotes package into memory- in other words we can use the functions within the package.<br>
You may be asked a question in the console when you do this. If so, answer by typing Yes into the console.

### 0.3

Now install a package that the instructors made that is not on CRAN but on GitHub, by copy and pasting the code into the console. We still don't want to copy the backticks.<br>
`install_github("jhudsl/jhur")`<br>
Now install a package that the instructors made that is not on CRAN but on GitHub, by copy and pasting the code into the console:

install_github("jhudsl/jhur")

You may be asked a question in the console when you do this. If so, answer by typing Yes into the console.

### 0.4

The gray area below is a code chunk that will set up our packages and data (this will not show up in the rendered report when we press knit). You can also run the code within the editor area by pressing the green play button. Don't worry right now about what the code is doing, we will cover this later. We just want you to get used to RStudio and RMarkdowns.

Expand Down Expand Up @@ -62,10 +67,8 @@ The console is useful for installing packages like we just did, this is because

## Plotting some data

Here is code that will make a plot of the average daily ridership in Baltimore City for the Charm City Circulator: https://www.charmcitycirculator.com/ (again don't worry about the actually code much for now).


Here we plot a few days. You can embed an R code chunk like this: Try pressing the green play button to see what happens. Make sure you have run the previous code chunk first by pressing the green play button in that chunk.
Here is code that will make a plot of some data.
You can embed an R code chunk like this: Try pressing the green play button to see what happens. Make sure you have run the previous code chunk first by pressing the green play button in that chunk.

```{r plot_circ, out.width = "100%"}
# keep only some days
Expand Down Expand Up @@ -110,23 +113,23 @@ When code is in an RMarkdown file chunk, it is saved to a file. When it is in th

The console is useful for installing packages like we just did, this is because we only need to do it once, so we don't usually need to save the code.


## Exercise

Here are a few changes that will show you how to change small things in `R` code and the output it makes. After each change, hit the **Knit** button again.

Here is another code chunk for our exercises.

```{r}
x <- c(1, 2, 3)
```

### 1.1

Go through the code for the plot above and change the colors in `palette` to something other than what they originally were. See http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf for a large list of colors. For example, you could replace blue with red.

### 1.2

Add a new R chunk below the bonus instructions.You can use the insert chunk button or copy paste an existing code chunk. Include a lowercase x inside the chunk as the code. Thus it should look like the chunk above but without `<- c(1,2,3)`. Make sure you press the knit button after this to see what the new chunk looks like.
Add a new R chunk below the following chunk. You can use the insert chunk button or copy paste an existing code chunk. Include a lowercase x inside the chunk as the code. Make sure you press the knit button after this to see what the new chunk looks like.


```{r}
x <- c(1, 2, 3)
```


# Practice on Your Own!
Expand All @@ -139,8 +142,6 @@ Update the options of the R chunk you just made (with the lowercase x in it) so

Create another R Markdown Document from RStudio dropdowns: File → New File → R Markdown.



```{r echo=FALSE, label = '2response'}
```{r echo=FALSE, label = 'P.2response'}
x
```

0 comments on commit 052ebea

Please sign in to comment.