15:00
Why this class?
Goal: Learn some best practices to make your life in R easier and your research more reproducible
No one and no field is immune from errors in data analysis. Our goal is to make them as unlikely as possible (and report them when we find them!)
Install the {usethis}
package:
install.packages("usethis")
Introduce yourself to git:
usethis::use_git_config(user.name = "Louisa Smith", user.email = "louisahsmith@gmail.com")
When you make changes to your code, they will be associated with this name and email address (this doesn’t really matter for our purposes)
If you just updated R to a new “major” version, you will need to reinstall packages
RStudio tries to help!
Spelling the package or function’s name wrong, or not installing or loading the package
If you are writing a script you will save, and will use several functions from this package
I try to only run library(package)
from a script (not the console) so that there’s a “record” of me loading the package, or else I might accidentally write code that doesn’t work later
Since I don’t need to run this once, I would probably run this from the console (bottom) rather than a script (top)
Running from the console is great for install.packages()
, quick calculations, fiddling with code until you get it right, or scenarios like this – otherwise save your code in a script!
Create a github token:
usethis::create_github_token()
Instead of entering your password every time, this is a secure way to connect to GitHub
Copy the token
Back in R, run this code and paste your token where it says “Enter password”:
gitcreds::gitcreds_set()
You can do this again whenever your token expires or you are using a different device
15:00