Added example snippets of the presentation.

This commit is contained in:
Hylke C. Donker 2022-02-17 11:50:55 +01:00
commit 635b784fba
4 changed files with 47 additions and 0 deletions

19
Dockerfile Normal file
View File

@ -0,0 +1,19 @@
FROM r-base:4.1.2
# Install several CRAN packages using package manager.
RUN apt update \
&& apt install --assume-yes \
r-cran-dplyr=1.0.7-2 \
r-bioc-deseq2=1.34.0+dfsg-1 \
r-cran-biocmanager=1.30.16+dfsg-3 \
r-cran-devtools=2.4.3-1
# Example how to install specific package using R.
RUN R -e "BiocManager::install('apeglm', dependencies=TRUE, version='3.14')"
# Make a directory in the Docker image and copy scripts to it.
WORKDIR /analysis/
COPY ./example/ /analysis/
# Run unit tests.
CMD R --quiet -e 'testthat::test_dir("test")'

4
example/example.R Normal file
View File

@ -0,0 +1,4 @@
# Example function to be tested.
linear_transformation <- function(x) {
return (2*x + 1)
}

View File

@ -0,0 +1,12 @@
source("../example.R", chdir=TRUE)
library(testthat)
test_that("Real numbers are transformed to odd numbers.", {
expect_equal(linear_transformation(3) %% 2, 1)
expect_equal(linear_transformation(4) %% 2, 1)
})
test_that("Positive numbers remain positive.", {
expect_true(linear_transformation(3) > 0)
expect_true(linear_transformation(10) > 0)
})

12
readme.md Normal file
View File

@ -0,0 +1,12 @@
# Snippets of the `Reproducible and error free scripts` presentation
Use the `Dockerfile` to build the image, which we name `r_example`:
```Bash
docker build -t r_example .
```
As specified in the image's Dockerfile (`CMD` line), by default it will run the unit tests:
```Bash
docker run r_example
```