MyNixOS website logo
Description

Standard Evaluation-Based Multivariate Function Composition.

Provides a streamlined, standard evaluation-based approach to multivariate function composition. Allows for chaining commands via a forward-pipe operator, %>%.

fc


travis

This is an R package that provides a streamlined, standard evaluation-based approach to function composition. Using fc, a sequence of functions can be composed together such that returned objects from composed functions are used as intermediate values directly passed to the next function.

Installation

To install this package in R, you can install it via the devtools package:

devtools::install_github("swang87/fc")

Usage

The package can then be loaded using:

library(fc)

The workhorse of the package is the fc() function. Its first argument is either a named function or an anonymous function; subsequent arguments must be named arguments of this function.

Getting Started

We can create a new function that uses partial function valuation to display the first 50 rows of a dataset with:

head50 <- fc(head, n=50)

The return function has a single argument x, inherited from the head() function. The function head50() consists of:

function (x)
{
  head(x, n = 50)
}

In order to perform function composition, multiple fc() calls could be used in a nested manner:

summary50 <- fc(summary, object=fc(head, n = 50)(object))

The pipe-forward operator %>% is also supported for defining a pipeline functions to be run from left-to-right. Note differences in usage compared to magrittr and other packages in the Tidyverse.

summary50 <- fc(head, n=50) %>% summary

In particular, the pipe-forward operator supported by fc cannot accept a data object on its lefthand side. If one wishes to run the composed function on a data object without intermediate storage of the function itself, the following syntax is permissible:

(fc(head, n=50) %>% summary)(x)

Examples

Example 1

log_sqrt_fc_pipe <- fc(log, x=x) %>% fc(sqrt, x=x)

This function takes the square root of the log of an input argument x.

Example 2

get_sepal2_pipe <- fc(function(x, cols) {x[sample(1:nrow(x)), cols]},
                        cols = grep("Sepal", colnames(x))) %>%
                        fc(head, n = 10) %>% summary

More Information

More details can be found in our working paper.

Metadata

Version

0.1.0

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