Creating new projects
Starting from scratch
EPI 590R final project
Your goal will be to create an analysis that
- I can reproduce on my own computer
- Is easy to rerun (including tables, figures, and regression output) if I tell you, for example, to remove the 12th row of your dataset
We’ll start this in class!
New projects
We cloned our first project from GitHub; now we are going to start a new project from scratch
- File > New Project > New Directory > New Project
- If you ever want to convert an existing folder that holds an analysis into an R project, you can choose “Existing Directory”
- You’ll also see other options besides “New Project” – an R package, a Shiny app, etc.
- These will get you set up with some initial files for these types of projects
- You can also make a template of your own!
File > New Project > New Directory > New Project
You can also get here from the project dropdown in the upper-right corner of RStudio.
New projects
- Choose a name for your new project and where to store it on your computer
- Check “Create a git repository”
- This gets you all set to connect to GitHub and creates a
.gitignore file
- You can leave “Use renv with this project” unchecked
{renv} records the exact package versions a project uses. Worth knowing about, but we won’t use it in this class.
Initial Git commit
- Stage and commit the files. Notice “Push” is greyed out – we haven’t connected to a remote yet.
![]()
Creating a new repo on GitHub
Open up your web browser to GitHub and make a new repository
Repository options
- Choose a name (preferably matching your R project). You don’t need to click anything else.
![]()
You can make it private if you wish (private repos have fewer features unless you have GitHub Pro, free for students via the student developer pack).
Connect the local to the remote
- You created your local repo with RStudio in a directory you chose
- Now you need to connect it to the remote repo on GitHub
- Copy the code from the second section: “push an existing repository from the command line” in the terminal within RStudio.
Connect the local to the remote
- Run the three lines of code one at a time, then refresh your GitHub page!
If you a) haven’t yet committed or b) don’t run the lines one at a time, you’ll get an error. Just try again.
.gitignore
You likely don’t want to push everything to GitHub, even if you have a private repository
- Be especially careful about data and passwords
- You also can’t push very large files (>100 mb)
A .gitignore is a special text file that tells Git not to track certain files
- RStudio starts you off with a few entries, including
.Rhistory since no one needs to see everything you’ve run in R!
This is what RStudio gives you
.gitignore
.Rproj.user
.Rhistory
.RData
.Ruserdata
Each line is a pattern. Anything matching it stays on your computer and never goes to GitHub.
Adding to it
Add a line for anything that shouldn’t be shared – data, passwords, API keys:
.gitignore
.Rproj.user
.Rhistory
.RData
.Ruserdata
secrets.txt
data/raw/
*.csv
.gitignore exercises
- Create a new file called
secrets.txt and write your deepest, darkest secret in it (e.g., I am scared of spiders)
- Uh oh – it shows up in the Git pane!
- Open
.gitignore from the file pane, add secrets.txt, and save
Keep your eye on the Git pane.
What happened?
![]()
secrets.txt disappears from the Git pane – git is now ignoring it, so you can’t commit it by accident.
Starting the final project
- Set up your folders how you’d like in your repo (you can always change this)
- Find some data, download it, and store it in your repo
- Commit and push to GitHub!
For your final project, your data must be something that can be stored online and accessed by me (we’ll talk more about this later)
Some fun options for data are:
Exercises
Get started making a new project and GitHub repo for your final project, editing the .gitignore file, and finding some fun data
You can always change anything you want later, and even delete the whole thing and start fresh!