- Use R Projects (
.Rprojfiles) to keep track of your work
- Combine your code directly with your results to create great reports using RMarkdown documents
- Use the
here()command to refer to your files and folders in a project
- Before you start working on a longer and more intensive project, use GitHub to keep track of all your changes.
As discussed in our Project Management chapter 3, we click on “Create a Project” and e.g. name it “QEH QM.” This will put an
.RProj file into the folder we selected. This is the basis for all our exercises and Problem Sets going forward.
To open the project, we either double click on it in our file browser, or we open it from RStudio.
One of the greatest assets of R, is that you can use RMarkdown to marry your coding and reporting - no more need to write up your results e.g. in a Word Document while having your code in a separate script.
This book, for example, is also written with RMarkdown. We can create a RMarkdown document very easily, as you can see in Figure 3.2 below.
See the video below for a further introduction.
RStudio comes ready to use RMarkdown files and
A great resource on RMarkdown documents can be found here.
here() function to navigate within your project. The
here() function finds the path to the top-level of my current project to find a file, so it does not matter whether I started out in a sub-folder or not.
The way that the
here() command works, is that you first load the package and then use the
here as a wrapper for each time you are importing a datafile:
Basically, using the
here() command will save you a huge amount of hassle as you are going forward.
If you start with your research project, I highly recommend to start to use GitHub as your Version control. See this great Book on working with GitHub in RStudio.