Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R and rstudio basic #15

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

R and rstudio basic #15

wants to merge 23 commits into from

Conversation

cathy-y
Copy link

@cathy-y cathy-y commented Oct 10, 2020

Resolving issues for Introduction to R and RStudio basic tutorial

@cathy-y cathy-y self-assigned this Oct 10, 2020
Copy link
Contributor

@r-karimi r-karimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job Cathy! Just a few notes that might not even be suggestions for you but rather questions for Stephan and the rest of the team. Well done!

inst/tutorials/r_and_rstudio_basic/r_and_rstudio_basic.Rmd Outdated Show resolved Hide resolved
inst/tutorials/r_and_rstudio_basic/r_and_rstudio_basic.Rmd Outdated Show resolved Hide resolved
inst/tutorials/r_and_rstudio_basic/r_and_rstudio_basic.Rmd Outdated Show resolved Hide resolved

## Working with data

### Data description
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be in a "child document?"

I couldn't figure out how to do this on my tutorial though...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. Look at the Slack#educe, Gil talks about how he set up the child document.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I just replace all of the text here with his code? Not super sure what exactly the user is supposed to see here.

inst/tutorials/r_and_rstudio_basic/r_and_rstudio_basic.Rmd Outdated Show resolved Hide resolved
inst/tutorials/r_and_rstudio_basic/r_and_rstudio_basic.Rmd Outdated Show resolved Hide resolved

## Working with data

### Data description
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I just replace all of the text here with his code? Not super sure what exactly the user is supposed to see here.

inst/tutorials/r_and_rstudio_basic/r_and_rstudio_basic.Rmd Outdated Show resolved Hide resolved
inst/tutorials/r_and_rstudio_basic/r_and_rstudio_basic.Rmd Outdated Show resolved Hide resolved
Comment on lines 27 to 38
## Learning objectives

By the end of this tutorial you should be able to:

- Identify the different components of RStudio.
- Declare variables in R.
- Recognize and use functions.
- Install and load R packages.
- Load and subset tabular data using tidyverse.
- Use the `help` function in R console to troubleshoot given a new function.
The last bullet point can be more descriptive saying, "Use the `help` function in R console to troubleshoot and *identify mandatory parameters* given a new function."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Learning objectives
By the end of this tutorial you should be able to:
- Identify the different components of RStudio.
- Declare variables in R.
- Recognize and use functions.
- Install and load R packages.
- Load and subset tabular data using tidyverse.
- Use the `help` function in R console to troubleshoot given a new function.
The last bullet point can be more descriptive saying, "Use the `help` function in R console to troubleshoot and *identify mandatory parameters* given a new function."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer learning objectives with each section

inst/tutorials/r_and_rstudio_basic/r_and_rstudio_basic.Rmd Outdated Show resolved Hide resolved
inst/tutorials/r_and_rstudio_basic/r_and_rstudio_basic.Rmd Outdated Show resolved Hide resolved
Copy link
Contributor

@r-karimi r-karimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work this week, Cathy! Your tutorial is taking shape nicely :)

@@ -7,7 +7,7 @@ output:
progressive: true
allow_skip: true
runtime: shiny_prerendered
description: This tutorial covers the basics of R and RStudio. You will learn about the different panes and features of RStudio that make coding in R easier, as well as basic skills of the R language itself, such as creating functions and loading packages.
description: Welcome to R! If you want to analyze and visualize data reproducibly, you've come to the right place. This tutorial covers the basics of R and RStudio. RStudio is a free program used for coding in R. After learning about its features and functionality, we will dive into R language basics, where you will create functions and load packages.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, much better description.

You can also change the sizes of the panes by dragging the dividers or clicking on the expand and compress icons at the top right corner of each pane.

```{r quiz: R Tour, echo=FALSE}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful here--users can re-arrange the panes in the Rstudio options. I can imagine someone might not have this configuration...I certainly don't!

Comment on lines 91 to 96
```{r quiz: R Projects, echo=FALSE}
question("What is not a benefit of using RStudio projects?",
answer("All of your files and outputs are linked to the project directory"),
answer("R automatically looks for files in the project directory so you don't have to specify a full file path"),
answer("When you reopen a project, your code is saved so all you need to do is rerun it", correct=TRUE)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how useful it is having quizzes for this kind of content. What do you think, Cathy and Stephan? Though I can appreciate how it might be useful in getting someone to learn about RStudio projects, I might just give a few use cases, link to the docs, and leave it at that.

@@ -115,11 +133,33 @@ total <- total - 1

total
```
Now it's your turn! Declare a variable "product" and set its value to 3 * 5. Next, operating on "product", declare a variable called "difference", whose final value is 8.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Now it's your turn! Declare a variable "product" and set its value to 3 * 5. Next, operating on "product", declare a variable called "difference", whose final value is 8.
Now it's your turn! Declare a variable "product" and set its value to the product of the numbers 3 and 5. Next, using the variable "product", declare a variable called "difference", whose final value is 8.



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! I might also give a few use cases for functions. Python has those neat recursive functions (not sure if those exist in R), but you could also talk about taking some raw data doing some long processing all in one shot, if you have the processing function already written. This could open the door to the whole API style of programming, though that might be beyond the scope of this tutorial.

Comment on lines 243 to 281
### Data exploration

Let's explore the data that we've imported into R.

Using different functions, we can look at the dimensions of our data, number of rows, and number of columns:
```{r}
#number of rows followed by number of columns
dim(OTU_metadata_table)

#number of rows
nrow(OTU_metadata_table)

#number of columns
ncol(OTU_metadata_table)
```

We can list the column names using `colnames()`:
```{r}
colnames(OTU_metadata_table)
```

We can select to work with only specific columns/variables from our table using the `select()` function:
```{r}
restricted_columns <- select(OTU_metadata_table, Depth, OTU0001, OTU0002,
OTU0004)
```

We can filter for specific rows based on a column value using the `filter()` function. Here we restrict for rows where the value for `Depth` is smaller than 135.

```{r}
above_135_depth <- filter(OTU_metadata_table, Depth < 135)
```

We can also only choose to work with specific rows based on their position in our data table using the `slice()` function.

```{r}
first_five_rows <- slice(OTU_metadata_table, 1:5)
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, good to delete this. It's covered in wrangling-basic.

Copy link
Contributor

@r-karimi r-karimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, good job Cathy! Feel free to let me know when you think this workshop is done and I'll go ahead and work through the full thing and give some feedback on the organization and flow. Changes in your commits look good this week--keep it up!

Comment on lines 66 to 69
Working with Data:

- Load data into R
- Save loaded data in the environment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is redundant with wrangling-basic, just FYI.

Comment on lines 38 to 65
RStudio Projects:

- List the benefits of using RStudio Projects
- Create a new RStudio Project
- Open or switch to an existing RStudio Project

R Scripts:

- Create an R script file
- List the benefits of using R scripts
- Annotate R scripts with comments

Variables in R:

- Declare variables
- Perform operations to change the value of variables

Functions in R:

- Explain what functions and arguments are
- Use R to understand how any given function works
- Identify required and optional arguments for functions

R Packages:

- Understand what R packages are and how they are used
- Install and load packages

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is a much clearer way of conveying the learning goals.


When you start RStudio, you will see something like the following window appear:

![](/images/rstudio.png){width=100%}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This image shows up


When trying to run a command, you see this error:

![](/images/objecterror.png){width=100%}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This image does not show

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So where in the repo did you place your image?

Copy link
Contributor

@r-karimi r-karimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job Cathy! Very minor edits and suggestions from me this week.

Comment on lines 96 to 99
question("Where can you go to try to locate 'object'?",
answer("The console"),
answer("Lower right pane", correct=TRUE),
answer("Upper right pane"))
answer("Lower right pane"),
answer("Upper right pane", correct=TRUE))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a neat idea. I like this style of questioning--introducing students to the types of common errors they might encounter is prudent. Well done.

Comment on lines 140 to 146
```{r Scripts, echo=FALSE}
quiz(
question("How do R scripts make your work reproducible?",
answer("Trick question: they work just like Excel and don't make work reproducible"),
answer("They keep a record of all actions done to get from raw data to final results", correct=TRUE),
answer("You can use them to test different operations on your data")
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth introducing the set.seed() function for reproducible random simulations? Might be out of the scope of this tutorial but it's also a pretty straightforward function. What do you think @cathy-y and @stephan-koenig?

inst/tutorials/r_and_rstudio_basic/r_and_rstudio_basic.Rmd Outdated Show resolved Hide resolved
Base automatically changed from master to main January 19, 2021 20:11

![](/images/rstudio.png){width=100%}

Notice that the window has three "panes":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are four panes and an option in, tools > global options > pane layout to customize the panels. Would it be useful to include here?

example_transposed
```
### The most helpful function of all: the 'help' function
You can get information about a specific function by running the command `?<function>` or `help(<function>)` (replace `<function>` by the name of the function you are interested in). This command opens the help page, where you can find all information about a function's purpose and its arguments. For beginners, it is useful to concentrate on the "Examples" and "Arguments" section to understand the typical usage of the function better.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also type the function into the search box of the help window in the files plots packages help pane. That way it is never part of the Rscript.

We can filter for specific rows based on a column value using the `filter()` function. Here we restrict for rows where the value for `Depth` is smaller than 135.

```{r}
above_135_depth <- filter(OTU_metadata_table, Depth < 135)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter function created conflict, worked only as dplyr : : filter(). This issue has been reviewed before for select(), could use either example to demonstrate the notation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants