fc v0.1.0

0

Monthly downloads

0th

Percentile

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, %>%.

Readme

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.

Functions in fc

Name Description
fc Generalized Function Composition and Partial Function Evaluation
%>% Forward-pipe Operator Using Standard Evaluation
No Results!

Last month downloads

Details

Type Package
Encoding UTF-8
LazyData true
URL https://github.com/swang87/fc
BugReports https://github.com/swang87/fc/issues
License GPL-2
RoxygenNote 6.1.0
NeedsCompilation no
Packaged 2018-08-13 13:49:00 UTC; eastie
Repository CRAN
Date/Publication 2018-08-14 09:40:06 UTC
imports codetools
suggests magrittr , purrr
Contributors Michael Kane

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/fc)](http://www.rdocumentation.org/packages/fc)