Introduction
Research compendium
R package
Shiny App
Why not sharing your code?
Why not sharing your code?
Share your code to reproduce your pipeline
Why not sharing your code?
Share your code to access data
Why not sharing your code?
Share your code to add new data
GitHub and co are cloud-based git repository hosting services
Perfect solutions to host projects (code) tracked by git
Services
Main platforms
GitHub account: https://github.com/ahasverus/
GitHub organization: https://github.com/frbcesab/
The goal of a research compendium is to provide a standard and easily recognisable way for organizing the digital materials of a project to enable others to inspect, reproduce, and extend the research.
Marwick B, Boettiger C & Mullen L (2018)1
Three generic principles
Files organized according to the conventions of the community
Clear separation of data, method, and output
Specify the computational environment that was used
A research compendium should be self-contained
Strong flexibility in the structure of a compendium
Small compendium
.
├─ .git/
├─ .gitignore
│
├─ project.Rproj
│
├─ data/ 🔒
│
├─ code/
│ └─ script.R
│
├─ outputs/
│
├─ LICENSE
└─ README.md
Strong flexibility in the structure of a compendium
Small compendium
.
├─ .git/
├─ .gitignore
│
├─ project.Rproj
│
├─ data/ 🔒
│
├─ code/
│ └─ script.R
│
├─ outputs/
│
├─ LICENSE
└─ README.md
Medium compendium
.
├─ .git/
├─ .gitignore
│
├─ project.Rproj
│
├─ data/
│ ├─ raw-data/ 🔒
│ └─ derived-data/
│
├─ R/
│ ├─ function-x.R
│ └─ function-y.R
│
├─ analyses/
│ ├─ script-1.R
│ └─ script-n.R
│
├─ outputs/
│
├─ make.R
│
├─ DESCRIPTION
├─ LICENSE
└─ README.md
Strong flexibility in the structure of a compendium
Small compendium
.
├─ .git/
├─ .gitignore
│
├─ project.Rproj
│
├─ data/ 🔒
│
├─ code/
│ └─ script.R
│
├─ outputs/
│
├─ LICENSE
└─ README.md
Medium compendium
.
├─ .git/
├─ .gitignore
│
├─ project.Rproj
│
├─ data/
│ ├─ raw-data/ 🔒
│ └─ derived-data/
│
├─ R/
│ ├─ function-x.R
│ └─ function-y.R
│
├─ analyses/
│ ├─ script-1.R
│ └─ script-n.R
│
├─ outputs/
│
├─ make.R
│
├─ DESCRIPTION
├─ LICENSE
└─ README.md
Large compendium
.
├─ .git/
├─ .gitignore
├─ .github/
│ └─ workflows/
│ ├─ workflow-1.yaml
│ └─ workflow-n.yaml
│
├─ project.Rproj
│
├─ .renv/
├─ renv.lock
│
├─ dockerfile
├─ .dockerignore
│
├─ data/
│ ├─ raw-data/ 🔒
│ └─ derived-data/
│
├─ R/
│ ├─ function-x.R
│ └─ function-y.R
│
├─ analyses/
│ ├─ script-x.R
│ └─ script-n.R
│
├─ outputs/
│
├─ figures/
│
├─ paper/
│ ├─ references.bib
│ ├─ style.csl
│ └─ paper.Rmd
│
├─ make.R
│
├─ DESCRIPTION
├─ CITATION.cff
├─ CODE_OF_CONDUCT.md
├─ CONTRIBUTING.md
├─ LICENSE
└─ README.md
README
pleaseA README
is a text file that introduces and explains your project
README
README
(project, data, etc.)README
pleaseREADME
pleaseREADME
pleaseA good README
should answer the following questions1:
README
pleaseA good README
should answer the following questions1:
Main sections (for a research compendium)
In the fundamental unit of shareable code is the package. A package bundles together
code
,data
,documentation
, andtests
, and is easy to share with others.
Hadley Wickham - R packages (1st ed.)
An package:
well-documented functions
reproducible
useful
for you and for othersA package contains two main components:
DESCRIPTION
file with package metadataR/
with documented functions.
├─ R/
│ └─ fun.R
│
└─ DESCRIPTION
A package contains two main components:
DESCRIPTION
file with package metadataR/
with documented functions.
├─ R/
│ └─ fun.R
│
└─ DESCRIPTION
devtools::document()
.
├─ R/
│ └─ fun.R
│
├─ man/
│ └─ fun.Rd
│
├─ NAMESPACE
│
└─ DESCRIPTION
The function devtools::document()
automatically generates a folder man/
(function documentation) and the NAMESPACE
file.
A function is a block of code organized together to perform a specific task and only runs when it is called. It can have parameters and can return a result.
Automate common and repetitive tasks
Advantages1
function()
function()
Defining a function
#' @field value
.Rd
files (in man/
) and NAMESPACE
Get started w/ roxygen2
: here
#' Compute the arithmetic mean
#'
#' This function computes the arithmetic mean of a numeric variable.
#'
#' @param x a `numeric` vector
#'
#' @return A `numeric` value representing the arithmetic mean of `x`.
#'
#' @export
#'
#' @examples
#' x <- 1:10
#' arithmetic_mean(x)
arithmetic_mean <- function(x) {
sum(x) / length(x)
}
#' @field value
.Rd
files (in man/
) and NAMESPACE
Get started w/ roxygen2
: here
#' Compute the arithmetic mean
#'
#' This function computes the arithmetic mean of a numeric variable.
#'
#' @param x a `numeric` vector
#'
#' @return A `numeric` value representing the arithmetic mean of `x`.
#'
#' @export
#'
#' @examples
#' x <- 1:10
#' arithmetic_mean(x)
arithmetic_mean <- function(x) {
sum(x) / length(x)
}
Then, run devtools::document()
to automatically generate .Rd
files in man/
and the NAMESPACE
file
DESCRIPTION
fileMain component of an package, the DESCRIPTION
file describes package metadata.
Package: nameofthepackage
Type: Package
Title: The Title of the Package
Authors@R: c(
person(given = "John",
family = "Doe",
role = c("aut", "cre", "cph"),
email = "john.doe@domain.com",
comment = c(ORCID = "9999-9999-9999-9999")))
Description: A paragraph providing a full description of
the package.
License: GPL (>= 2)
External packages required by the package will be listed in this file.
Database hosted on
Zenodo
Data paper published in
Scientific Data
Package hosted on GitHub
(coming soon on the CRAN)
Software paper submitted at
Methods in Ecology and Evolution
shiny
packageShiny is an package that makes it easy to build interactive web applications (apps) straight from .
Source: Mastering Shiny
Features
Provides a curated set of user interface (UI) functions that generate the HTML, CSS, and JavaScript needed for common tasks.
No knowledge of HTML, CSS, or JavaScript required
Introduces a new style of programming called reactive programming which automatically tracks the dependencies of pieces of code.
Automatically update output if input changes
shiny
packageAvailable at: https://github.com/rstudio/shiny/
A Shiny app is contained in a single script called app.R
and has three components:
ui
(user interface) objectserver()
functionshinyApp()
functionA Shiny app is contained in a single script called app.R
and has three components:
ui
(user interface) objectserver()
functionshinyApp()
functionMore information here
More information here
## User interface ----
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30
)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
## Server logic ----
server <- function(input, output) {
output$distPlot <- renderPlot({
# Generate bins based on input$bins
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# Draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white',
xlab = 'Waiting time to next eruption (in mins)',
main = 'Histogram of waiting times')
})
}
RStudio IDE: New Project > New Directory > Shiny Application