Abstract

Assertive check functions for defensive R programming.

Introduction

goalie is an attempt to incorporate elements of multiple assertive check packages into a single package with as few dependencies as possible. All assertive checks are written in the most basic R code possible, without reliance on compilation (e.g. C++/Rcpp). It is still a work in progress, and feature requests are welcome.

R exports the stopifnot() function as a simple assert engine that supports multiple boolean returns (TRUE/FALSE) in a single call, separated by commas. This is a nice, flexible system for defensive programming. However, stopifnot() does not currently support custom error messages, and can be confusing to debug.

Similar to the approach used in the assertthat package, goalie exports the assert() function, which is designed to be a drop-in replacement for stopifnot() with improved error message support. validate() is a variation on assert() that is intended to be used within S4 class validity checks, which is useful for Bioconductor packages.

Additionally, goalie exports a number of assertive check functions that are intended to harden bioinformatics-oriented functions in R. These check functions return logical with an additional "goalie" S3 class definition, which enables us to define custom print methods that display additional useful information about the cause of the error (see cause() and print() for details). This approach draws heavily from the assertive package.

The goalie source code incorporates elements from these excellent assert check packages:

The assert check engine

Todo

Checking function inputs

Todo

Creating new assert checks

Todo

S4 class validity checks

Todo

R session information

utils::sessionInfo()
## R version 3.6.1 (2019-07-05)
## Platform: x86_64-redhat-linux-gnu (64-bit)
## Running under: Red Hat Enterprise Linux
## 
## Matrix products: default
## BLAS/LAPACK: /usr/lib64/libopenblas-r0.3.3.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] BiocStyle_2.12.0
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.1         knitr_1.23         xml2_1.2.0.9000   
##  [4] magrittr_1.5       roxygen2_6.1.1     MASS_7.3-51.4     
##  [7] R6_2.4.0           rlang_0.4.0        stringr_1.4.0     
## [10] tools_3.6.1        xfun_0.8           htmltools_0.3.6   
## [13] commonmark_1.7     yaml_2.2.0         digest_0.6.20     
## [16] assertthat_0.2.1   rprojroot_1.3-2    bookdown_0.12     
## [19] pkgdown_1.3.0.9100 crayon_1.3.4       BiocManager_1.30.4
## [22] fs_1.3.1           memoise_1.1.0      evaluate_0.14     
## [25] rmarkdown_1.14     stringi_1.4.3      compiler_3.6.1    
## [28] desc_1.2.0         backports_1.1.4