Skip to content

Commit

Permalink
Merge pull request #24 from robertzk/is_pre_stagerunner
Browse files Browse the repository at this point in the history
is_pre_stagerunner helper
  • Loading branch information
robertzk committed Mar 7, 2015
2 parents c1f72ac + 1377904 commit c48550e
Show file tree
Hide file tree
Showing 46 changed files with 116 additions and 46 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Description: Stage Runner is an R package that helps with parametrizing
and executing linear sequences of actions, common in the various
stages of data analysis: data import, munging, modeling, export,
and visualization.
Version: 0.4.0
Version: 0.4.1
Author: Robert Krzyzanowski <technoguyrob@gmail.com>
Maintainer: Robert Krzyzanowski <technoguyrob@gmail.com>
Authors@R: c(person("Robert", "Krzyzanowski",
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generated by roxygen2 (4.1.0.9000): do not edit by hand
# Generated by roxygen2 (4.1.0): do not edit by hand

export(is.stageRunner)
export(is.stagerunner)
export(is_pre_stagerunner)
export(stageRunner)
import(testthat)
import(testthatsomemore)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Version 0.4.1

* Added an `is_pre_stagerunner` helper function that returns TRUE or FALSE
according as an object can be transformed into a stageRunner.

# Version 0.4.0

* Integration with the [objectdiff package](http://github.com/robertzk/objectdiff).
Expand Down
32 changes: 32 additions & 0 deletions R/is_pre_stagerunner.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Whether or not an object can be transformed into a stageRunner.
#'
#' @param x ANY. An R object for which it will be determined whether or not
#' it admits a conversion to a stageRunner.
#' @return TRUE or FALSE according to whether the object can be transformed
#' to a stageRunner. In general, only a function or list of functions
#' can be turned into a stageRunner.
#' @export
#' @examples
#' stopifnot(is_pre_stagerunner(function(e) { e$x <- 1 }))
#' stopifnot(is_pre_stagerunner(list(function(e) { e$x <- 1 }, function(e) { e$y <- 2 })))
#' stopifnot(is_pre_stagerunner(
#' list(a = function(e) { e$x <- 1 },
#' list(b = function(e) { e$y <- 2 }, c = function(e) { e$z <- 3 }))))
#'
#' stopifnot(!is_pre_stagerunner(NULL))
#' stopifnot(!is_pre_stagerunner(5))
#' stopifnot(!is_pre_stagerunner(iris))
is_pre_stagerunner <- function(x) {
if (is.function(x) || is.stagerunner(x)) { return(TRUE) }
if (!is.recursive(x)) { return(FALSE) }

for (i in seq_along(x)) {
if (!(is.function(x[[i]]) || is.stagerunner(x[[i]]) || is.null(x[[i]]) ||
(is.recursive(x[[i]]) && Recall(x[[i]])))) {
return(FALSE)
}
}

TRUE
}

8 changes: 4 additions & 4 deletions R/stage_runner.r
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ stageRunner__initialize <- function(context, .stages, remember = FALSE,
warning("stageRunners with zero stages may cause problems.", .call = FALSE)
}

legal_types <- function(x) is.function(x) || all(vapply(x,
function(s) is.function(s) || is.stagerunner(s) || is.null(s) ||
(is.list(s) && legal_types(s)), logical(1)))
stopifnot(legal_types(.stages))
if (!is_pre_stagerunner(.stages)) {
stop("Can only turn a function or list of functions into a stageRunner", call. = FALSE)
}

if (is.function(.stages)) .stages <- list(.stages)
stages <<- .stages

Expand Down
2 changes: 1 addition & 1 deletion inst/tests/test-stage_runner.r
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ test_that("it correctly references a numeric stage within a character stage", {

test_that("it throws an error when an invalid stage gets passed", {
expect_that(stageRunner$new(new.env(), list(1)),
throws_error('legal_types.*not TRUE'))
throws_error('Can only turn a function'))
})

test_that("it correctly parses a nested list of functions into nested stagerunners", {
Expand Down
2 changes: 1 addition & 1 deletion man/OOP_type_independent_method.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/utils.r
\name{OOP_type_independent_method}
\alias{OOP_type_independent_method}
Expand Down
2 changes: 1 addition & 1 deletion man/boolean_fill.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/boolean_fill.r
\name{boolean_fill}
\alias{boolean_fill}
Expand Down
2 changes: 1 addition & 1 deletion man/compare_stage_keys.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/compare_stage_keys.r
\name{compare_stage_keys}
\alias{compare_stage_keys}
Expand Down
2 changes: 1 addition & 1 deletion man/copy_env.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/copy_env.r
\name{copy_env}
\alias{copy_env}
Expand Down
2 changes: 1 addition & 1 deletion man/is.stagerunner.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{is.stagerunner}
\alias{is.stagerunner}
Expand Down
32 changes: 32 additions & 0 deletions man/is_pre_stagerunner.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/is_pre_stagerunner.R
\name{is_pre_stagerunner}
\alias{is_pre_stagerunner}
\title{Whether or not an object can be transformed into a stageRunner.}
\usage{
is_pre_stagerunner(x)
}
\arguments{
\item{x}{ANY. An R object for which it will be determined whether or not
it admits a conversion to a stageRunner.}
}
\value{
TRUE or FALSE according to whether the object can be transformed
to a stageRunner. In general, only a function or list of functions
can be turned into a stageRunner.
}
\description{
Whether or not an object can be transformed into a stageRunner.
}
\examples{
stopifnot(is_pre_stagerunner(function(e) { e$x <- 1 }))
stopifnot(is_pre_stagerunner(list(function(e) { e$x <- 1 }, function(e) { e$y <- 2 })))
stopifnot(is_pre_stagerunner(
list(a = function(e) { e$x <- 1 },
list(b = function(e) { e$y <- 2 }, c = function(e) { e$z <- 3 }))))

stopifnot(!is_pre_stagerunner(NULL))
stopifnot(!is_pre_stagerunner(5))
stopifnot(!is_pre_stagerunner(iris))
}

2 changes: 1 addition & 1 deletion man/nested_names.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/nested_names.r
\name{nested_names}
\alias{nested_names}
Expand Down
2 changes: 1 addition & 1 deletion man/normalize_stage_keys.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/normalize_stage_keys.r
\name{normalize_stage_keys}
\alias{normalize_stage_keys}
Expand Down
2 changes: 1 addition & 1 deletion man/show_message.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/show_message.r
\name{show_message}
\alias{show_message}
Expand Down
2 changes: 1 addition & 1 deletion man/special_and_lists.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/special_and_lists.r
\name{special_and_lists}
\alias{special_and_lists}
Expand Down
2 changes: 1 addition & 1 deletion man/special_or_lists.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/special_or_lists.r
\name{special_or_lists}
\alias{special_or_lists}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner}
\alias{stageRunner}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunnerNode.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\docType{class}
\name{stageRunnerNode}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__.before_env.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__.before_env}
\alias{stageRunner__.before_env}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__.clear_cache.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__.clear_cache}
\alias{stageRunner__.clear_cache}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__.mark_finished.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__.mark_finished}
\alias{stageRunner__.mark_finished}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__.root.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__.root}
\alias{stageRunner__.root}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__.set_parents.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__.set_parents}
\alias{stageRunner__.set_parents}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__.set_prefixes.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/objectdiff.R
\name{stageRunner__.set_prefixes}
\alias{stageRunner__.set_prefixes}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__append.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__append}
\alias{stageRunner__append}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__around.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__around}
\alias{stageRunner__around}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__coalesce.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__coalesce}
\alias{stageRunner__coalesce}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__has_key.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__has_key}
\alias{stageRunner__has_key}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__initialize.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__initialize}
\alias{stageRunner__initialize}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__next_stage.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__next_stage}
\alias{stageRunner__next_stage}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__overlay.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__overlay}
\alias{stageRunner__overlay}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__run.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__run}
\alias{stageRunner__run}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__show.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__show}
\alias{stageRunner__show}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__stage_names.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__stage_names}
\alias{stageRunner__stage_names}
Expand Down
2 changes: 1 addition & 1 deletion man/stageRunner__transform.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/stage_runner.r
\name{stageRunner__transform}
\alias{stageRunner__transform}
Expand Down
2 changes: 1 addition & 1 deletion man/treeSkeleton.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/tree_skeleton.r
\docType{class}
\name{treeSkeleton}
Expand Down
2 changes: 1 addition & 1 deletion man/treeSkeleton__.parent_index.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/tree_skeleton.r
\name{treeSkeleton__.parent_index}
\alias{treeSkeleton__.parent_index}
Expand Down
2 changes: 1 addition & 1 deletion man/treeSkeleton__children.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/tree_skeleton.r
\name{treeSkeleton__children}
\alias{treeSkeleton__children}
Expand Down
2 changes: 1 addition & 1 deletion man/treeSkeleton__find.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/tree_skeleton.r
\name{treeSkeleton__find}
\alias{treeSkeleton__find}
Expand Down
2 changes: 1 addition & 1 deletion man/treeSkeleton__first_leaf.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/tree_skeleton.r
\name{treeSkeleton__first_leaf}
\alias{treeSkeleton__first_leaf}
Expand Down
2 changes: 1 addition & 1 deletion man/treeSkeleton__initialize.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/tree_skeleton.r
\name{treeSkeleton__initialize}
\alias{treeSkeleton__initialize}
Expand Down
2 changes: 1 addition & 1 deletion man/treeSkeleton__last_leaf.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/tree_skeleton.r
\name{treeSkeleton__last_leaf}
\alias{treeSkeleton__last_leaf}
Expand Down
2 changes: 1 addition & 1 deletion man/treeSkeleton__parent.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/tree_skeleton.r
\name{treeSkeleton__parent}
\alias{treeSkeleton__parent}
Expand Down
2 changes: 1 addition & 1 deletion man/treeSkeleton__root.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/tree_skeleton.r
\name{treeSkeleton__root}
\alias{treeSkeleton__root}
Expand Down
2 changes: 1 addition & 1 deletion man/treeSkeleton__successor.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/tree_skeleton.r
\name{treeSkeleton__successor}
\alias{treeSkeleton__successor}
Expand Down

0 comments on commit c48550e

Please sign in to comment.