Click on the three horizontally stacked lines at the bottom left corner of the slide, then you will see table of contents, and you can jump to the section you want
Hit letter “o” on your keyboard and you will have a panel view of all the slides
First of all, you may have heard of “reproducibility” and “replicability.” While they sometimes are used interchangeably, they mean different things. Here are commonly used definitions of the two terms (Cacioppo et al. 2015).
Definition: Reproducibility
A research study is reproducible if anybody (including the author of the study) can generate exactly the same results by using the same materials (e.g., data) and procedures used in the study.
Definition: Replicability
A research study is replicable if other teams reach the same conclusion by applying the same procedure to the different materials (e.g., data).
This lecture focuses only on reproducibility and do not deal with replicability.
Minimum Requirement
Every single action taken during the entire research process is documented in a way that anybody can follow to implement the same actions (no hidden actions) to produce exactly the same results.
Note that this does not necessarily mean every single action needs to be computer-programmed and automated. Even if you manually delete rows of data on Excel (highly discouraged), this does not make your research non-reproducible as long as this action is recorded and the original data (before deletion of the rows) are provided because anybody can implement this action.
Your project is reproducible if the minimum requirement is satisfied, but is of low-quality if it is too costly/time-consuming to reproduce. A high-quality reproducible project exhibits the following characteristics:
Organized Project Folder:
It maintains a well-structured and organized project folder, making it easy to locate files your are looking for.
Streamlined Automation:
Workflows are automated with well-annotated computer programs, simplifying the replication process and providing clarity in the workflow.
Comprehensive Documentation:
Robust documentation, encompassing data and reproduction guidance, ensures transparency, saving time on data interpretation and replication instructions.
The main beneficiaries of reproducible research include:
Here are the benefits of high-quality reproducible research with their beneficiaries:
You should have a single dedicated folder for a research project. This will avoid
confusions between objects of the same or similar name (accidentally using the one you do not intend to use)
wasting memory by holding objects on the global environment that are completely irrelevant to your working project
We can initiate an RStudio project with a dedicated folder from within RStudio.
At the top right corner of RStudio, navigate through:
Project (None)
-> New Project…
-> New Directory
-> New Project
You will be automatically taken to a new R session inside the newly-created RStudio project.
In this folder you just created, you have a single file named
Here is a recommended folder organization. You should modify/add folders as you see fit.
Recommendation
Use a qmd file instead of an R file whenever you write codes
It is much easier to make comments in a qmd file than an R file
You can better organize your codes with markdown section headers (e.g., #, ##)
R crashed at a certain chunk and had to restart R and then run all the R codes up to the problematic chunk? Use Run All Chunks Above
button (click on the triangle right to the Run
button and select the option, or hit option
+ command
+ P
).
Easily move between sections and subsection using the navigator at the bottom lower corner of the source pane
Recommended Stucture
Note
Dynamically edit the “Objective statement” as its objectives, input, and output are likely to change.
You can write R codes however you would like. But, your code may get more readable to you and others who might read your codes by following a style guideline that is accepted by many R users. There are several popular styles of formatting R codes:
Examples
Here are some examples of the tidyverse
style:
The styler
package can help you follow partially the tidyverse
coding style.
Once the package is installed, you can highlight the lines of codes and hit cmd
+ shift
+ A
for Mac (ctrl
+ shift
+ A
for Windows) to reformat the codes to conform with the tidyverse style.
Alternatively, you can click on Addins
in the middle of the menu at the top, and select style selection
.
Rules 1
Rules 2
Rules 3
Rules 4
Recommendation
Example
Let’s take a look at an example project that is designed to be reproducible. First, Clone this repository. We will then look at how the project is organized and developed.
Code snippets are functions that maps sequence of letters and symbols (short) to other sequence of letters and symbols (more complicated and long)
Syntax
Important
You need a tab before (what you want to print)
Follow Tools \(\rightarrow\) Global Options \(\rightarrow\) Code \(\rightarrow\) Edit Snippets , select R tab, and add snippets.
Suppose you are working on an Quarto document.
Snippets defined in the R (Markdown) tab only works in the R (Markdown) context.
$
is used as a special character to denote where the cursor should jump (by hitting tab
) after completing each section of a snippet.