Some example structures:
project └───data/ └───derived/ └───raw/ └───R/ └───script/ └───graphics/ └───README.md
project/ └───README.md └───input/ └───output/ └───R/ └───graphics/
We’ll use the SocCaribou project as an example throughout the following sections.
README.md file should always be included and stores plenty of information about the project. Installation instructions, TODOs, description or purpose of the project, authors, news, known bugs or limitations, instructions for contributing, link to license, etc.
For example, the SocCaribou README:
## Space-use and social organization in a gregarious ungulate: testing the conspecific attraction and resource dispersion [![DOI](https://zenodo.org/badge/173167283.svg)](https://zenodo.org/badge/latestdoi/173167283) - Authors: - Mélissa Peignier - [Quinn M.R. Webber](https://qwebber.weebly.com/) - [Erin Koen](https://sites.google.com/site/erinlkoen/) - [Michel P. Laforge](https://mammalspatialecology.weebly.com/) - [Alec L. Robitaille](http://robitalec.ca) - [Eric Vander Wal](http://weel.gitlab.io) This repository contains the code accompanying the paper “Space-use and social organization in a gregarious ungulate: testing the conspecific`scripts/` and attraction and resource dispersion”. Scripts are under `R/`. This project uses standard R package reused functions are in `devtools`. This also structure and can therefore be installed with helps declare external package dependencies required for the analysis. Please note that while functions are included here, they are not tested for use in other projects and may not be suitable (at least not in their current version). ## Abstract Animals use a variety of proximate cues to assess habitat quality when resources vary spatiotemporally. Two non-mutually exclusive strategies to assess habitat quality involve either direct assessment of landscape features or observation of social cues from conspecifics as a form of information transfer about forage[...]resources.
R scripts can be organized into
holds analysis scripts, often (ideally) numbered in the order they should
be run in. For example, in the SocCaribou project there’s
2-HomeRangeAnalysis.R. See Jenny Bryan’s
project oriented workflow.
R/ folder is used for functions. Functions help us chunk out
larger project into manageable pieces of code.
targets manual has a great overview of the two approaches.
It doesn’t have to be one or the other - if you have a discrete chunk of code
that needs to be applied multiple times, or might be useful in another project,
etc, just write it as a function and drop it into your
R/ folder. In addition,
R/ folder is recognized if you turn your project into a package or a
research compendium as the standard place and structure for functions.
See the SocCaribou project
that has both an
R/ folder and a
SocCaribou ├── R │ ├── dynamic_network.R │ ├── hr_network.R │ └── step_length.R ├── scripts │ ├── 1-DataCleaning.R │ ├── 2-HomeRangeAnalysis.R │ ├── 3-SiteFidelityAnalysis.R │ ├── 4-SocialNetworkAnalysis.R │ ├── 5-Randomizations.R │ ├── 6-MergeTidyFiles.R │ └── 7-DataAnalysis.R ...
Always start with raw data. Keep raw data raw in a
Then use scripts to prepare and organize your data - never modify it by hand. This way, you can go always go back to the raw data in case anything changes in your preparation steps.
Intermediate and output data can be sorted into
output/ folders and
saved as an
.Rds files using the base R functions:
readRDS(). More details in
Efficient R / Binary file formats. Or if you use
fwrite to read/write CSV files.
If your dates are stored in the ISO standard format, they will be automatically
Keep track of where the raw data comes from, how it was generated, by who, when,
etc using metadata. See the
project. Use this project to write metadata for your data. Talk to Alec about
Other elements include:
- LICENSE file - Choose an open source license
figures/folder for figures and plots
paper/folder for storing the manuscript
man/folder for storing the documentation of your functions
Keep a ChangeLog / News file. Traditionally in the R community, it is stored in a
Always work within RStudio Projects to avoid
setwd() hell. If you share an
RStudio Project (
.RProj) with someone else, they can immediately use it
without changing working directories or paths to files.