14  Analysis Setup

14.1 Installing R

If you have already installed R, ensure is is updated to at least version 4.1 or the packages will not work!

If you have not installed R before, go here and click the link for your specific operating system. If you use Mac OS, make sure you get the R version for your particular type of Mac. If you have a Mac using Apple’s silicon (eg M1), choose the ‘arm64’ version. If not, choose the other version.

Note

If you don’t know what kind of processor you have, you can click on the ‘Apple’ button in the top left corner of your screen, then click ‘About This Mac’. The ‘Processor’ heading will tell you if it is Intel or Apple silicon.

14.2 Installing RStudio

Go here to download the package. Run the downloaded file to install.

14.3 Installing Packages

  1. Open RStudio
  2. Find the tab that says ‘Console’ and click on it. Alternatively, press Control + 2 (not command + 2)
  3. Type the following: install.packages("mypackage"). Replace mypackage with what you want to install, but keep the double quotes. Press enter.
  4. Wait a bit for the package to install, and say yes to any prompts. Your package is now installed!

14.4 Installing GitHub Packages

  1. First, follow the “Installing Packages” instructions to install the devtools package
  2. Then type the following into the console: devtools::install_github("user/package"), where user is the GitHub user and package is the repository name.

14.5 Tools for compiling packages

Many times you’ll need to be able to compile packages on your machine, since they don’t come precompiled. To do that, you’ll need some additional tools. Follow the instructions for your operating system here

14.6 Packages these analyses use

If you want to get all package installing out of the way in one go, run the following:

install.packages("devtools")

# This package is for qPCR activities, like analyzing library prep
# quantification results, or ddCT qPCR results.
devtools::install_github("KaiAragaki/amplify")

# This package ALSO automatically installs two other packages of note
# because it relies on them (among others, but only two are important).
# They are:

# This package helps you tidy microwell data, as well as plot it. Most of
# the plots of plates in this book are made using this package.
# devtools::install_github("KaiAragaki/gp")

# This package helps you turn weirdly formatted data that comes off our
# machines into data that is much easier to work with in R.
# devtools::install_github("KaiAragaki/mop")


# Additionally, you'll want to install this one:

# This package contains a lot of odds and ends that can't yet be parted out
# into their own package, or are hyper-GBCI-specific
devtools::install_github("McConkeyLab/bladdr")

14.7 Getting R to talk to SharePoint

There are certain functions in the packages above that pull files from SharePoint. In order to connect to SharePoint, you need to set an Environmental Variable. This is actually quite simple. Running the below code will open up a file:

usethis::edit_r_profile()

Paste the following into that file, then save it:

Sys.setenv(
  CLIMICROSOFT365_AADAPPID = "04b07795-8ddb-461a-bbee-02f9e1bf7b46"
)

Reload RStudio and you should be good to go.1 Once you run a function like bladdr::get_gbci_file, you’ll need to authenticate like you would normally when logging into SharePoint on the web to make sure that you’re a person who should be allowed to see these files.


  1. This is not a password - it is a publicly available, default app ID. However, you generally should not share your environmental variables, since this is a fairly secure way for you to supply passwords to scripts without actually writing down your password, since code often is made publicly available. However, not all environmental variables are passwords - they’re just one way of storing them↩︎