This R-project contains all the material and the scripts used to conduct the analysis.
To guarantee the reproducibility of the results, the whole analysis is structured within an R-project
named name.Rproj
that is possible to download from this repository add repository link.
The R-packagedrake
is used to manage the analysis workflow and to enhance the readability and transparency of the analysis. To know more about drake
consider the official Git-hub page or the user manual. Summarizing, using drake
the code of the analysis is organized into different scripts. The user defines the plan of the analysis where each step in the analysis is defined trough functions. Functions can be appropriately defined to obtain desired targets (i.e., R-output with results of interests) and they are declared in another script. Subsequently, drake
manages the whole analysis recognizing the dependency structure of the different targets. When any change is made to the code drake
evaluates the analysis and updates the results. Using functions to define each step of the analysis allows to avoid "coping and paste" in the code, it makes debugging easier, and it facilitates the reading of the code.
Moreover, the R-package renv
is used to manage the dependencies of the R-packages used in the analysis. The renv
package allows to create an isolated, portable, and reproducible environment where the analyses are run. To know more about renv
consider the official documentation.
Finally, git version control was used to track the changes during the analysis.
The R-project name.Rproj
is organized into different folders. In the folder Data/
, the raw datasets are stored.
In the folder R/
, the R-scripts used in the analysis are stored. Using the drake
package the analysis is organized into different R-scripts files:
- Settings.R contains the setting for the R sessions, including R-packages used.
- Plan.R contains the plan of the analysis. Where each target (i.e., R-output with results of interests) is defined through functions.
- Function.R contains the main functions used in \texttt{Plan.R} to obtain the targets of interest.
- Auxiliary_functions.R contains other functions used in the analysis.
- Analysis.R is the script used to run the whole analysis.
In the folder Documents/
, it is possible to find the Report of the analysis.
In order to run the analysis follow these steps:
- Make sure you have already the
renv
R-package installed in your library. If not, run the command in R or R-studioinstall.packages("renv")
- Open the R-project
name
by double-clicking the filename.Rproj
you can find in the main directory. A new R-studio session should open and a similar message should appear in the console ifrenv
was correctly installed:
* Project '~ <your_path>/name' loaded. [renv <version_number>]
- Run the line
renv::restore()
,renv
will ask the permission to install the R-packages used in the analysis, typey
and return to confirm. - Open the file R/Analysis.R and run each line of the sections "Load", "Check", and "Make".
- Now you can access the targets with the results using the functions
drake::loadd(<name_target>)
anddrake::readd(<name_target>)
.