Following is a diagram of the steps in initiating your own R/RStudio project.
flowchart LR
create(create\nnew\nRStudio\nproject)
organise(organise\nproject\nfile\nstructure)
code(code/\nmake\nchanges)
commit(commit)
github{use\nGitHub?}
push(push)
collaborate{collaborate?}
add_collaborators(add\ncollaborators)
self_review(self-review\nautomated\nchecks)
create --> organise
organise --> code
code --> commit
commit --> github
github -- YES --> push
github -- NO --> code
push --> collaborate
collaborate -- YES --> add_collaborators
collaborate -- NO --> self_review
A flowchart for initiating an R project
Create a new project in RStudio
Create a New Directory
Select New Project as project type
Specify details for new project
Specify a project name
Best practices for naming a project are:
- Make sure that name is succinct (as short as possible while at the same time descriptive of the project);
- Don’t use spaces for your project name. If you need to separate words, use a hyphen or an underscore;
- Avoid using capital letters.
Specify a directory/location
Select a directory in your local machine where to place the directory of your new project
Decide whether to use git to version this project
Here you can decide whether you want to use git to version your project. Remember that using git doesn’t mean you have to use GitHub. git is software installed in your local machine and it versions what you have on your local machine. You don’t need GitHub or any other similar service to version your code with git in your local machine.
I would recommend that you tick this option for any new project you create so that you can version your work in your local machine even if you don’t want or decide not to use GitHub or any other remote git service.
Do you want to open a new session
This is by default unticked and will open the new project within the existing RStudio session (if any). This means that if you have an existing RStudio session with another project that you are working on, that project will be closed and the new project you are creating will open in the existing RStudio session.
If you need your existing RStudio session and the project within it to remain open alongside the new project you are creating, tick this box/option.
Click on Create New Project
Once you click on Create New Project, you will now see the new project open in RStudio.
You will also see something like below within the file explorer pane of RStudio.
2. Structure/organise your new project appropriately
Project organisation is vital because:
- supports productivity because the different components of the project are placed in directories where they should be;
- enables clarity in communicating project structure;
- facilitates collaboration.
Organising an R project can be user- and project-dependent but there are generally accepted project organising structure that is common to most well-organised projects. Below is an example:
|-- my-project
|-- data
|-- output
|-- figures
|-- R
|-- my-project.Rproj
|-- analysis_workflow.R
|-- README.md
3. Start coding
This will include creating bespoke R functions (as required) and creating an Rscript for the step-by-step processes in your scientific workflow.
Next steps
The next steps will depend on whether you will use git and GitHub for versioning your project and whether or not you will work on your project as a solo scientist or work and collaborate with other scientists.