Hello and welcome to the Complete Guide to R for Bioinformatics! In this cookbook, we will be discussing type of graphs that are useful for representing genomic data in RStudio. We will be guiding you throughout the coding processes and explaining what the lines of code do, such that you will be able to create representations of your data regardless of experience with R.
In this chapter of the cookbook, we will be discussing fundamental concepts of RStudio to prepare you for more complex code later in this resource. The FIRST priority when building a code is installing and/or loading code functions caled “libraries”. You might be thinking, “What are libraries?” Well, libraries are collections of coded functions and arguments that are combined together. In many cases, these packages can be installed to perform new processes that RStudio is not inherently capable of. In other cases, it may take a more complex process through base R and make the process easier or less intensive. The way we install libraries is using a function called install.packages("") which is an inherent process in R. You might notice the two quotation marks that were located inside the parentheses. This is how we write names in R and we specify the packages that we want to install between the quotation marks, in this case.
To run a line you create, you can pres the command (for Mac) or control (for Windows) buttons and press enter (Windows) or return (Mac) at the same time. You can also click the “Run” button located in the top right of the main window of RStudio. These processes have the same result, which is to run the code you write line-by-line. This is a useful technique to learn, as it allows you to see where the error is occuring in your code. This makes it easier to try and debugg any errors, warnings, etc. that may come up when creating code.
After you run install.packages(""), you wil also have to load the package. This is because the computer only installed the software you specified but the program has not been signaled to run. To enable the package we installed, we use the library() function. Notice how this time, there is no quotation marks in between the parentheses. This is because what we want the computer to search for is something installed in the Studio. This wil be important for later in this resource when we create functions, graphs, and objects. For now, though, it is important to know that you need to insert the name of the package you want to load in between the parentheses and run the code. After you complete these steps, you should have an R script file similar to the chunk below:
install.packages("tidyverse")
library(tidyverse)
If you have