MyNixOS website logo
Description

Define and Enforce Contracts for Dataframes as Function Parameters.

A dataframe validation framework for package builders who use dataframes as function parameters. It performs checks on column names, coerces data-types, and checks grouping to make sure user inputs conform to a specification provided by the package author. It provides a mechanism for package authors to automatically document supported dataframe inputs and selectively dispatch to functions depending on the format of a dataframe much like S3 does for classes. It also contains some developer tools to make working with and documenting dataframe specifications easier. It helps package developers to improve their documentation and simplifies parameter validation where dataframes are used as function parameters.

interfacer

R-CMD-check DOI interfacer statusbadge

interfacer is primarily aimed at R package developers. It provides a framework for specifying the structure of dataframes as parameters for user functions and checking that user supplied dataframes conform to expectations. Missing columns or incorrectly typed columns can be identified and useful error messages returned. Specifying structure is part of the function definition and can be automatically included in roxygen2 documentation.

Installation

You can install the released version of interfacer from CRAN with:

install.packages("interfacer")

Most likely though you will be including this in another package via a DESCRIPTION file:

...
Imports: 
    tidyverse,
    interfacer
Suggests: 
    knitr,
    rmarkdown
...

This development versions of the package are hosted in the Bristol Vaccine Centre r-universe. Installation from there is as follows:

options(repos = c(
  "bristol-vaccine-centre" = 'https://bristol-vaccine-centre.r-universe.dev/',
  CRAN = 'https://cloud.r-project.org'))

# Download and install interfacer in R
install.packages("interfacer")

Or via a DESCRIPTION file:

...
Imports: 
    tidyverse,
    interfacer
Remotes: github::bristol-vaccine-centre/interfacer
Suggests: 
    knitr,
    rmarkdown
...

You can also install the development version of interfacer from GitHub with:

# install.packages("devtools")
devtools::install_github("bristol-vaccine-centre/interfacer")

Example

interfacer is used within a function definition in a package to constrain the input of a function to be a particular shape. The @iparam annotation will generate documentation which explains the expected dataframe format.

#' An example function
#'
#' @iparam mydata a test dataframe input parameter
#' @param another an example other input parameter  
#' @param ... not used
#'
#' @return ... something not yet defined ...
#' @export
example_fn = function(
  
  # this parameter will be a dataframe with id and test columns
  # id will be a unique integer, and test a logical value
  mydata = interfacer::iface(
    id = integer + group_unique ~ "an integer ID",
    test = logical + default(FALSE) ~ "the test result"
  ),
  
  another = "value",
  ...
  
) {
  
  # this line enforces the `iface` rules for the dataframe, coercing columns
  # if possible and throwing helpful errors if not.
  mydata = interfacer::ivalidate(mydata, ...)
  
  # rest of function body can use `mydata` in the certain knowledge that
  # id is a unique integer and test is a logical value...
}

When calling this function, column name, data type and grouping structure checks are made on the input and informative errors thrown if the input is incorrectly specified.

interfacer also includes tools to help developers adopt iface specifications by generating them from example data, and for documenting dataframes bundled in a package.

Metadata

Version

0.2.3

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows