Build-up well-conceived R-projects without a time lag.
Using R and RStudio facilitates the process of initializing R-projects to structure your work. However it is advisable to standardize your workflow in order to write well organized code that can be passed on to others and try to include standards of reproducibility. The R-package framework gives you the opportunity to initialize a well-conceived project structure with only one line of R-code:
framework::project_framework("path/2/your/new/project")
Almost every researcher/statistician (...) has its own workflow. At least there are many different demands people prefer to work with. Anyhow the setup plays a very important role when working on projects. Therefore the directory structure of framework projects are fully customizable from the start. All you have to do is to pass different arguments when invoking the function 'project_framework'. It is even possible to copy a local template of a makefile by using this function.
However per default the following directory structure will be implemented:
md
etc. within a subdirectory) * This directory further includes additional files and subdirectories: e.g. an
Rproj-file, packrat-repo, git-repo, git-ignore, a hidden cache-directory, a
backup-directory, a how-to-manual, a README.md and a current session info.
** These directories should be treated as read only because they will be deleted
and rebuilt every time you source the file make.R
The functional principle of framework-projects is inspired by the software GNU Make
.
Basically a project consists of several processing steps. Ideally these steps
are written separately into different files (which will hereinafter be referred
to as 'source-files'). An additional makefile
(or in the case of a
framework-project a make-like file make.R
) contains all information and
instructions to process and combine the source-files. In other words: By calling the make-like file make.R
the whole framework-project will be processed. Additionally you will always be able to keep track of your processing steps by reading the file make.R
. If your source-files as well as the order of your processing steps do not change it is not necessary to process
them. Therefore a framework-project makes use of a cache-directory per default
(nonetheless optionally for each source-file). Thanks to this feature the
processing speed of a framework-project is very fast. Furthermore the output of
a framework-project is always up-to-date and you will be able to detect and
locate bugs at an early stage.
Although the package includes addins for RStudio you can use ANY Text-Editor. It is even straightforward to work on your project from the command line (using Text-Editors like nano or vim and process your whole project by running RScript make.R
). If your Text-Editor supports custom keybindings for shell scripts (e.g. the GNOME text editor 'Gedit') you can write a simple shell script (see command above) and process your whole project with a simple shortcut. If you are using RStudio you simply need to specify a custom keybinding for the addin Execute source('make.R')
.
Writing a book is similar to writing an R-project.
First of all you will specify a title and make up a concept to work on:
framework::project_framework("path/2/your/new/project")
Afterwards you don´t want to loose time and start writing your "chapters" (alias source-files). To create a link you should specify the chapters in your table of contents:
Add the path of your source-files to the file make.R
.
At some point you want to print the book and see if you forgot something to mention:
source("make.R")
Because you can not write an entire book without interruption you should comment the stage of your work in a README and make sure to backup your files: Frequently edit the file README.md and add comments to your code continuously.
Sometimes you want to store several versions of your book while keeping track of all changes: use git to commit snapshots of your project.
Someday you want to pass on your work to colleagues and/or reviewers: use packrat to ensure applicability of your project.
framework
R
(>= 3.2) devtools
(for installation via github)RStudio
(testet under 0.99.878) devtools::install_github("sachserf/framework")
framework::project_framework("path/2/your/new/project")
projectname.Rproj
with RStudio (optionally).R
or .Rmd
) template_html(path/to/the/new/file)
make.R
path/to/the/new/file.*
to the object project_docs
make.R
*** There are several ways to source the makefile:
open the R-console and type source("make.R")
(Or use the Addin insert source make R
)
open the file make.R
and hit the source
-button (upper-right corner of the source-pane in RStudio)
Use a keybinding for the Addin source make R
to source the file make.R
automatically (To enable this feature you will need to specify a custom keybinding within RStudio: Tools --> Modify Keyboard Shortcuts...)
Start a terminal in your project directory and use the command RScript make.R
make.R
framework
see the help pages (?function_name
: eg ?framework::write_dataframe
)Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.