-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GIT: Merge pull request #38 from AngusMcLure/power_out
Fixes #36
- Loading branch information
Showing
11 changed files
with
541 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,40 @@ | ||
#' Methods for pool_strat obejcts | ||
#' Constructor for pool_strat objects | ||
#' | ||
#' @param x An object of class `pool_strat` (typically produced by one of the | ||
#' built-in functions for generating them such as `pool_max_size()` and | ||
#' `pool_taget_number()` | ||
#' @param ... Ignored | ||
#' @param strat function that takes an integer number of units and returns the | ||
#' number and size of pools to split the units across | ||
#' @param call call used to generate the pool_strat function. Used for format | ||
#' and as.character method (pretty printing) | ||
#' @param description text description of pool strategy to be used in print | ||
#' function | ||
#' @rdname pool_strat_methods | ||
#' @export | ||
|
||
pool_strat <- function(strat, call, description){ | ||
if(!inherits(strat, 'function')) {stop('strat must be a function')} | ||
ps <- strat | ||
attr(ps, 'call') <- call | ||
attr(ps, 'description') <- description | ||
class(ps) <- c('pool_strat', 'function') | ||
return(ps) | ||
} | ||
|
||
#' @export | ||
format.pool_strat <- function(x,...){ | ||
return(format(attr(x,'call'),...)) | ||
} | ||
|
||
#' @export | ||
as.character.pool_strat <- function(x,...){ | ||
return(format(attr(x,'call'),...)) | ||
} | ||
|
||
#' @export | ||
print.pool_strat <- function(x,...){ | ||
if(is.null(attr(x, 'description'))){ | ||
print.function(x) | ||
}else{ | ||
print(paste0('A pooling strategy that ', attr(x, 'description'))) | ||
cat(paste0('A pooling strategy that ', attr(x, 'description'))) | ||
} | ||
} | ||
invisible(x) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.