/cabinets

:package: for custom file structure templates accessible in R sessions outside the ones they were created in.

Primary LanguageROtherNOASSERTION

cabinets

CRAN status Lifecycle: stable Codecov test coverage R build status

Reproducibility can be tedious, cabinets makes it easier! cabinets creates project specific file structure templates that can be referenced at the start of any R session. These templates can then be used to initiate future projects with the option for them to be initiatied with a git repository. cabinets works by writing project specific file templates to the .Rprofile file of the default working directory. Doing so allows the templates to be accessed in new R sessions without having to redefine them.

cabinets has two main functions: create_cabinet() and new_cabinet_proj(). create_cabinet() constructs an R6 object of class FileCabinet which is then written to a .Rprofile file. At the start of fresh R sessions, the .Rprofile file loads the previously created cabinets for further use. new_cabinet_proj() can then be used to create future projects based on a cabinet template. Projects have the option of being created with an RStudio project and a git repository.

Users will be prompted for explicit permission to write to .Rprofile on first use. Permission to write can be revoked at any time by setting the permission option in the .Rprofile file to FALSE. Due to these explicit permission requirements, cabinets will only work in interactive R sessions.

Installation

You can install the released version of cabinets from CRAN with:

install.packages("cabinets")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("nt-williams/cabinets@dev")

Motivation

Different organizations, research groups, projects, etc. have different standard directories. One organization might have the standard file structure:

├── data
│   ├── derived
│   └── source
├── code
├── reports
├── documents
└── log

While another uses a structure like this:

├── Code
│   ├── ReportsCode
│   └── AnalysisCode
├── Notes
└── Log

cabinets makes it easy to define these templates once and then call them for use whenever starting new projects in R.

Example

A cabinet has three components: a name, a location, and a file structure. The location defines where new directories will be created from a cabinet template. The file structure defines, well, the structure of this directory. We use a list to define the structure, where the name of each list index is a unique relative path within the new directory. Using the first project file structure described above, lets create a new cabinet.

loc <- "~/Desktop"

file_str <- list(
    'data' = NULL, 
    'code' = NULL, 
    'data/derived' = NULL, 
    'data/source' = NULL, 
    'reports' = NULL, 
    'documents' = NULL, 
    'log' = NULL
)

create_cabinet(name = "contract", 
               directory = loc, 
               structure = file_str)
               
#> ✓ Checking for permissions
#> ✓ Checking for .Rprofile
#> ✓ Checking cabinet name
#> ✓ Cabinet .contract created
#> ● Restart R for changes to take effect
#> ● Cabinet can be called with .contract

The cabinet is now created and doesn’t have to be redefined in future R sessions. To examine the cabinet we just call it.

.contract

#> Cabinet name: contract
#> Cabinet path: ~/Desktop
#> Cabinet structure: 
#> ├── data
#> │   ├── derived
#> │   └── source
#> ├── code
#> ├── reports
#> ├── documents
#> └── log

new_cabinet_proj() is then used to create a new directory from a cabinet template.

new_cabinet_proj(cabinet = .contract, 
                 project_name = "project", 
                 git = TRUE, 
                 git_ignore = "data", 
                 renv = TRUE)

Similar implementations

Similar implementations exist elsewhere. cabinets is unique for giving the user the ability to design their own project templates. These are all great packages, use what’s best for you!

Contributing

Please note that the cabinets project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.