README.md

collateral: Reproducible, comfortable and fast processing with R

Package-License

Current version: 0.1.2 (28 November 2017)

Introduction

collateral provides you with functions you might miss in R, such as

Please see the Features / Examples section for more information.

However, this package is a proof of concept and please use it, at the moment, for testing purposes only. More detailed information will be provided soon.

Installation

Up to now, collateral is not available on CRAN because it needs some more tests for errors to provide a high level of stability. However, you might install (or update) the latest version:

Features / Examples

Compute serially or parallely and show progress

Compute Pi by a Monte Carlo experiment serially and parallely.

You can observe:

library(collateral)

comp_pi <- function(n) {
  x <- runif(n)
  y <- runif(n)
  inside <- sum(sqrt(x^2 + y^2) < 1)
  PI <- (inside / n) * 4
  return(PI)
}

set.seed(1234)
v1 <- psapply(rep(10000000, 20), comp_pi,
              progress = TRUE,
              time = TRUE,
              eta = TRUE)

set.seed(1234)
v2 <- psapply(rep(10000000, 20), comp_pi,
              threads = 3,
              progress = "batch",
              title = "Multiple threads",
              time = TRUE)

identical(v1, v2)
abs(pi - mean(v1))

Record and resume progress

With p*apply(), you can pause (stop) any loop and resume it later.

You can observe:

library(collateral)

somefun <- function(n) {
  if (n == 40 && errorflag) {
    stop("ERROR")
  }
  Sys.sleep(0.1)
  return(n)
}

# first run
set.seed(1234)
errorflag <- TRUE
v1 <- psapply(1:100, somefun,
              resume = TRUE,
              progress = TRUE,
              time = TRUE,
              eta = TRUE)

# second run
set.seed(1234)
errorflag <- FALSE
v <- psapply(1:100, somefun,
             resume = TRUE,
             progress = TRUE,
             time = TRUE,
             eta = TRUE)

identical(v, 1:100)

Memorize outputs

Speed up your computations by means of memorizing the output of the function by its inputs per iteration.

CAUTION: ONLY SET THIS OPTION IF YOUR FUNCTION DOES NOT DEPAND ON RANDOM NUMBERS!

You can observe:

library(collateral)

sleepy_sqrt <- function(n) {
  Sys.sleep(0.1)
  return(sqrt(n))
}

set.seed(1234)
x <- ceiling(runif(100) * 10)
head(x)

# without cache
v1 <- psapply(x, sleepy_sqrt,
              progress = TRUE,
              time = TRUE)
identical(v1, sqrt(x))

# with cache
v2 <- psapply(x, sleepy_sqrt,
              memo = TRUE,
              progress = TRUE,
              time = TRUE)
identical(v2, sqrt(x))

Documentation

Work in progress ... Please have a look at:

library(collateral)
?collateral
?plapply

Author

Fabian Raters.

License

MIT, 2016-2017.



ratmaster/collateral documentation built on May 24, 2019, 6:19 p.m.