Back to Repository Home



Working with Project Files

Using project files within a folder is generally a good idea, because it saves the trouble of including a working directory set function.

Things to avoid within the folder (an example of problematic structure):

:: User/Docs/R/Analysis Scripts/
::
:::: analysis 6.r
:::: analysis 6 v2.r
:::: analysis 6 v2 FINAL.r
:::: analysis 6 v2 FINAL revised.r

This multiple version nonsense can clutter up a folder really quickly. A better approach is to use version control. The best and most common platform for this is GitHub. Allows for very easy sharing and collaborative editing of code files as well. Try http://happygitwithr.com for tutorials on how to connect R to GitHub. Doing so allows R to push and pull files between your GitHub repository and local files.


PROTIP - R Users powerpoint by Chase James is very useful for organizational tips. Much of it is replicated in Kayla’s lab slides for today.

Things to ask yourself when managing files and scripts, etc.:

::: Where am I going to save my R projects?
::: What am I trying to accomplish?

Saving Projects

Once you create the project FOLDER, you want to have a separate folder within it that includes dedicated spaces for:

::: data
::: output
::: figures

It is also useful to have separate files (probably scripts, which can all be aggregated into a single markdown file at the end) within your project folder that handle each of the following three major steps of data analysis:

::: 1 data processing - reading in your data files
::: 2 analysis steps - getting results of your analyses
::: 3 figures - generating any data visualizations

PROTIP - Generally start all scripts by mounting your packages first.


Working within your script files

Start by mounting packages, then running through the process of importing and assembling/cleaning all data files needed for a data run

It is very useful to annotate heavily in R, as in any other programming environment. It allows you to understand what you are doing at each step along the way.

It is also very useful to write data processing steps into functions. It is intimidating at first, but it can greatly expedite your future data runs, and it makes your code very shareable/reproducible because others can just use your function.

For others to re-use your functions, you will need to save and share the .Rdata file that is associated with your project. This file will contain the initial steps that include creating the functions and will mount or install all package dependencies as needed.