Conversation
Co-authored-by: Ryan Karimi <66281159+r-karimi@users.noreply.github.com> Co-authored-by: ymkng <37229946+ymkng@users.noreply.github.com> Co-authored-by: Pranav Sampara <56938339+psampara@users.noreply.github.com> Co-authored-by: Cathy <59323254+cathy-y@users.noreply.github.com> Co-authored-by: Avery Noonan <averynoonan@gmail.com>
r-karimi
left a comment
There was a problem hiding this comment.
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!
|
|
||
| ## Working with data | ||
|
|
||
| ### Data description |
There was a problem hiding this comment.
Does this need to be in a "child document?"
I couldn't figure out how to do this on my tutorial though...
There was a problem hiding this comment.
Yes, exactly. Look at the Slack#educe, Gil talks about how he set up the child document.
There was a problem hiding this comment.
Do I just replace all of the text here with his code? Not super sure what exactly the user is supposed to see here.
|
|
||
| ## Working with data | ||
|
|
||
| ### Data description |
There was a problem hiding this comment.
Do I just replace all of the text here with his code? Not super sure what exactly the user is supposed to see here.
| ## 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." | ||
|
|
There was a problem hiding this comment.
| ## 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." | |
There was a problem hiding this comment.
I personally prefer learning objectives with each section
Co-authored-by: Ryan Karimi <66281159+r-karimi@users.noreply.github.com>
Co-authored-by: Ryan Karimi <66281159+r-karimi@users.noreply.github.com>
r-karimi
left a comment
There was a problem hiding this comment.
Great work this week, Cathy! Your tutorial is taking shape nicely :)
| 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. |
There was a problem hiding this comment.
Nice, much better description.
| To change the look of RStudio, you can go to Tools → Global Options → Appearance and select colours, font size, etc. If you plan on working for longer periods of time, we suggest choosing a dark background colour which is less hard on your computer battery and your eyes. | ||
| 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} |
There was a problem hiding this comment.
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!
| ```{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) | ||
| ) |
There was a problem hiding this comment.
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.
|
|
||
| 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. |
There was a problem hiding this comment.
| 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. |
| # Operate on "product" to get 8 as the value for "difference" | ||
| difference <- product - 7 | ||
|
|
||
|
|
There was a problem hiding this comment.
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.
| ### 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) | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Yup, good to delete this. It's covered in wrangling-basic.
…nning of the tutorial, and changed t() function to paste()
r-karimi
left a comment
There was a problem hiding this comment.
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!
| Working with Data: | ||
|
|
||
| - Load data into R | ||
| - Save loaded data in the environment |
There was a problem hiding this comment.
This section is redundant with wrangling-basic, just FYI.
| 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 | ||
|
|
There was a problem hiding this comment.
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: | ||
|
|
||
| {width=100%} |
|
|
||
| When trying to run a command, you see this error: | ||
|
|
||
| {width=100%} |
There was a problem hiding this comment.
So where in the repo did you place your image?
r-karimi
left a comment
There was a problem hiding this comment.
Great job Cathy! Very minor edits and suggestions from me this week.
| 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)) |
There was a problem hiding this comment.
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.
| ```{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") | ||
| ), |
There was a problem hiding this comment.
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?
Co-authored-by: Ryan Karimi <66281159+r-karimi@users.noreply.github.com>
…n greater depth, gave examples of common errors for loading and installing packages
Can only link to sections, not subsections
|
|
||
| {width=100%} | ||
|
|
||
| Notice that the window has three "panes": |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
Resolving issues for Introduction to R and RStudio basic tutorial