Last updated: 2019-04-09

Checks: 5 1

Knit directory: rrresearch/

This reproducible R Markdown analysis was created with workflowr (version 1.2.0). The Report tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.

The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20190216) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:

Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    assets/.DS_Store
    Ignored:    assets/img/.DS_Store
    Ignored:    data/.DS_Store
    Ignored:    data/metadata/
    Ignored:    demos/demo-rmd-0_files/
    Ignored:    demos/demo-rmd-1_files/
    Ignored:    demos/demo-rmd_files/

Untracked files:
    Untracked:  analysis/05_literate-prog.Rmd
    Untracked:  analysis/10_pkg_functions.Rmd
    Untracked:  analysis/assets/
    Untracked:  analysis/outro.Rmd
    Untracked:  data/birds.csv
    Untracked:  data/raw/
    Untracked:  data/stocks.csv
    Untracked:  data/trees.csv
    Untracked:  data/vst_mappingandtagging.csv
    Untracked:  data/vst_perplotperyear.csv
    Untracked:  docs/figure/
    Untracked:  figure/
    Untracked:  project_man.Rmd
    Untracked:  rmd/
    Untracked:  slides/

Unstaged changes:
    Modified:   analysis/index.Rmd

Staged changes:
    Modified:   analysis/_site.yml

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.

There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.

[1] "Hello, world!"


create test file

To create a new test file (and the testing framework if required), use function usethis::use_test(). It’s good practice to name the test files after the .R files containing the functions being tested.

This just created the following folders and files

├── testthat
│   └── test-hello.R
└── testthat.R

1 directory, 2 files

When the tests are run (either through running devtools::test(), clicking on More > Test Package in the Build panel or Cmd/Ctrl + Shift + T), the code in each test script in directory testthat is run.

It also added testthat to the suggested packages in the DESCRIPTION file.


That’s because you don’t need test that to run the functions in mypackage, but you do if you want to run the tests.


Let’s load the library so we can explore the testthat testing framework

If the test doesn’t pass it throws an error

Error: Test failed: 'multiplication works'
* 2 * 2 not equal to 5.
1/1 mismatches
[1] 4 - 5 == -1

write tests

We’ll write tests to ensure that when our function is given a certain set of arguments as input, it generates output that we know to be correct

Let’s create something to test against.

The first thing to note, looking at the say() documentation is that it takes an argument type which allows us to specify the output we want. It defaults message which means the output of the function is returned as a message.

We can therefore use testthat::expect_message()

Colors cannot be applied in this environment :( Try using a terminal or RStudio.
"\n\n ----- \nHello world from Anna! \n ------ \n    \\   \n     \\\n   __\n   / \\\n   | |\n   @ @\n  || ||\n  || ||\n  |\\_/|\n  \\___/ GB\n"

R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.3

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] testthat_2.0.1

loaded via a namespace (and not attached):
 [1] rmsfact_0.0.3     workflowr_1.2.0   Rcpp_1.0.1       
 [4] crayon_1.3.4      digest_0.6.18     rprojroot_1.3-2  
 [7] R6_2.4.0          backports_1.1.3   git2r_0.24.0.9001
[10] magrittr_1.5      evaluate_0.13     rlang_0.3.1      
[13] stringi_1.3.1     fs_1.2.7          cowsay_0.7.0     
[16] fortunes_1.5-4    rmarkdown_1.12    tools_3.5.2      
[19] stringr_1.4.0     glue_1.3.1        xfun_0.5         
[22] yaml_2.2.0        compiler_3.5.2    htmltools_0.3.6  
[25] knitr_1.22