# Run these lines in the R Console
install.packages("tinytex")
# Run only once if you don't have it
::install_tinytex()
tinytex# Run only once to install LaTeX distribution
# This might take a few minutes. If it fails, consult TinyTeX documentation or ask instructors.
3 Setting Up Your Environment: R and RStudio
3.1 Why R and RStudio?
- R: A powerful, free programming language specifically designed for statistical computing and graphics. Widely used in academia and industry for data analysis, including genomics and breeding.
- RStudio: An excellent, free Integrated Development Environment (IDE) for R. It makes using R much easier with features like code highlighting, plot viewing, package management, and project organization.
3.2 Installation Steps
- Install R: Go to CRAN (the Comprehensive R Archive Network) and download the latest version for your operating system (Windows, macOS, Linux). Follow the installation instructions.
- Install RStudio: Go to the Posit website and download the free RStudio Desktop version for your operating system. Install it after installing R.
- Install RTools: RTools can be installed from the CRAN website. You need to install the version corresponding to the R version you have installed through its installer.
- Install Quarto: Go to Quarto’s website and download and install Quarto for your system. RStudio often bundles Quarto, but installing the latest version is good practice.
- (For PDF Output) Install LaTeX: Open RStudio, go to the Console panel, and type the following commands one by one, pressing Enter after each:
# Installing R Packages for the Course
# We will use several add-on packages in R.
# You only need to install packages *once*.
# --- Run this code chunk in the R Console ---
# List of packages we will likely need:
# Packages in Cran
<- c(
cran_packages "tidyverse", "readxl", "writexl", "readr", "qqman", "vcfR", "QBMS", "adegenet",
"ade4", "ggiraph", "ggpubr", "plotly", "poppr", "reactable",
"rnaturalearth", "scatterpie", "viridis", "tibble",
"ggplot2", "reshape2", "forcats", "dplyr", "sp", "scales", "htmltools",
"ASRgenomics", "statgenGWAS", "gplots", "spdep", "adespatial", "DT", "rrBLUP",
"geodata", "terra"
)
# Bioconductor Packages
<- c("rrBLUP", "LEA", "impute")
bioc_packages
# Github Packages
<- c("snpReady")
git_packages
# Installing Cran Packages
<- rownames(installed.packages())
installed <- setdiff(cran_packages, installed)
missing if (length(missing)) {
message("Installing missing CRAN packages: ", paste(missing, collapse = ", "))
install.packages(missing)
}
# Installing Bioconductor Packages
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}<- rownames(installed.packages())
installed <- setdiff(bioc_packages, installed)
missing if (length(missing)) {
message("Installing missing Bioconductor packages: ", paste(missing, collapse = ", "))
::install(missing)
BiocManager
}
# Installing Github Packages
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
}<- rownames(installed.packages())
installed <- setdiff(git_packages, installed)
missing if (length(missing)) {
message("Installing missing Github packages: ", paste(missing, collapse = ", "))
::install_github("italo-granato/snpReady")
devtools }
3.3 Loading Libraries and Functions
# You can use library() to load any single package
# We will load all libraries using lapply()
invisible(
suppressPackageStartupMessages(
lapply(c(cran_packages, bioc_packages, git_packages), library,
character.only = TRUE)
) )
3.4 Quick RStudio Tour
(We will cover this live, but key windows include: Console, Script Editor/Notebook, Environment/History, Files/Plots/Packages/Help/Viewer/Projects). Familiarize yourself with these panes. More in depth information on any of the functions we use can be found by searching for the function in the Help panel.