From ee8355ec64d16817ffb958047d28ded222ba32f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 12 Nov 2013 11:34:18 +0100 Subject: [PATCH 01/11] enable continuous integration via craigcitro/r-travis --- .Rbuildignore | 3 ++- .travis.yml | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.Rbuildignore b/.Rbuildignore index 924c75f..1d23c76 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,4 @@ ^.*\.Rproj$ ^\.Rproj\.user$ -.gitignore \ No newline at end of file +^\.gitignore$ +^\.travis\.yml$ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b797465 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +# Sample .travis.yml for R projects. +# +# See README.md for instructions, or for more configuration options, +# see the wiki: +# https://github.com/craigcitro/r-travis/wiki + +language: c +script: ./travis-tool.sh run_tests +before_install: + - curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh + - chmod 755 ./travis-tool.sh + - ./travis-tool.sh bootstrap +install: + - ./travis-tool.sh install_deps +notifications: + email: + on_success: change + on_failure: change From 544ba19d04c28706cec08ed5522c84be6ffb8902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 12 Nov 2013 11:46:20 +0100 Subject: [PATCH 02/11] remove duplicate .Rd files --- man/getargs.Rd | 20 -------------------- man/goldenRatioColors.Rd | 31 ------------------------------- man/goldenratiocolors.Rd | 31 ------------------------------- man/holtwinters.Rd | 10 ---------- man/linfinder.Rd | 18 ------------------ man/permutations.Rd | 2 +- man/shadeplot.Rd | 40 ---------------------------------------- man/traintest.Rd | 27 --------------------------- 8 files changed, 1 insertion(+), 178 deletions(-) delete mode 100644 man/getargs.Rd delete mode 100644 man/goldenRatioColors.Rd delete mode 100644 man/goldenratiocolors.Rd delete mode 100644 man/holtwinters.Rd delete mode 100644 man/linfinder.Rd delete mode 100644 man/shadeplot.Rd delete mode 100644 man/traintest.Rd diff --git a/man/getargs.Rd b/man/getargs.Rd deleted file mode 100644 index 7f330e9..0000000 --- a/man/getargs.Rd +++ /dev/null @@ -1,20 +0,0 @@ -\name{getargs} -\alias{getargs} -\title{Get function arguments} -\usage{ - getargs() -} -\description{ - Gets the function arguments nicely. Does not return - arguments that are set by defaults -} -\examples{ -test <- function(x=1, y=2, z=3){getargs()} -} -\author{ - Hong Ooi (from StackOverflow) -} -\references{ - \url{http://stackoverflow.com/a/17257053/1003565} -} - diff --git a/man/goldenRatioColors.Rd b/man/goldenRatioColors.Rd deleted file mode 100644 index 44ceb64..0000000 --- a/man/goldenRatioColors.Rd +++ /dev/null @@ -1,31 +0,0 @@ -\name{goldenratiocolors} -\alias{goldenratiocolors} -\title{Choose n colors using the golden ratio} -\usage{ - goldenratiocolors(n, s = 0.5, v = 1, alpha = 1) -} -\arguments{ - \item{n}{Integer. The number of colors you want} - - \item{s}{Numeric. Saturation - input into hsv} - - \item{v}{Numeric. Value - input into hsv} - - \item{alpha}{Numeric. The alpha blending value that is - input into hsv.} -} -\description{ - This choices n colors for you based on breaking up the - hues according to a sequence generated by the golden - ratio. -} -\examples{ -cols <- goldenratiocolors(5) -plot(1:5, 1:5, col = cols) - -n <- 5 -xs <- seq(1, n) -plot(c(1, n+1), c(0, 1), type = "n") -rect(xs, 0, xs + 1, 1, col = goldenratiocolors(n)) -} - diff --git a/man/goldenratiocolors.Rd b/man/goldenratiocolors.Rd deleted file mode 100644 index 44ceb64..0000000 --- a/man/goldenratiocolors.Rd +++ /dev/null @@ -1,31 +0,0 @@ -\name{goldenratiocolors} -\alias{goldenratiocolors} -\title{Choose n colors using the golden ratio} -\usage{ - goldenratiocolors(n, s = 0.5, v = 1, alpha = 1) -} -\arguments{ - \item{n}{Integer. The number of colors you want} - - \item{s}{Numeric. Saturation - input into hsv} - - \item{v}{Numeric. Value - input into hsv} - - \item{alpha}{Numeric. The alpha blending value that is - input into hsv.} -} -\description{ - This choices n colors for you based on breaking up the - hues according to a sequence generated by the golden - ratio. -} -\examples{ -cols <- goldenratiocolors(5) -plot(1:5, 1:5, col = cols) - -n <- 5 -xs <- seq(1, n) -plot(c(1, n+1), c(0, 1), type = "n") -rect(xs, 0, xs + 1, 1, col = goldenratiocolors(n)) -} - diff --git a/man/holtwinters.Rd b/man/holtwinters.Rd deleted file mode 100644 index c5084a1..0000000 --- a/man/holtwinters.Rd +++ /dev/null @@ -1,10 +0,0 @@ -\name{holtwinters} -\alias{holtwinters} -\title{Holt winters smoothing no seasonality} -\usage{ - holtwinters(y, alpha = 0.5, beta = 0.5) -} -\description{ - Holt winters smoothing with no seasonality -} - diff --git a/man/linfinder.Rd b/man/linfinder.Rd deleted file mode 100644 index ef9deb4..0000000 --- a/man/linfinder.Rd +++ /dev/null @@ -1,18 +0,0 @@ -\name{linfinder} -\alias{linfinder} -\title{Finds linear combinations} -\usage{ - linfinder(mat, prefix = "Column_") -} -\arguments{ - \item{mat}{An input matrix} -} -\description{ - Finds linear combinations of columns that make up - linearly dependent columns -} -\examples{ -mat <- matrix(c(1,1,0,1,0,1,1,0,0,1,1,0,1,1,0,1,0,1,0,1), byrow=TRUE, ncol=5, nrow=4) -linfinder(mat) -} - diff --git a/man/permutations.Rd b/man/permutations.Rd index 775de6f..c4f6294 100644 --- a/man/permutations.Rd +++ b/man/permutations.Rd @@ -18,7 +18,7 @@ } \examples{ permutations(1:3) -permuations(c("a", "b", "c")) +permutations(c("a", "b", "c")) permutations(c("raptors", "are", "horrible")) } diff --git a/man/shadeplot.Rd b/man/shadeplot.Rd deleted file mode 100644 index 2c9d51a..0000000 --- a/man/shadeplot.Rd +++ /dev/null @@ -1,40 +0,0 @@ -\name{shadeplot} -\alias{shadeplot} -\title{Shade a section of a pdf} -\usage{ - shadeplot(func = dnorm, xlim = c(-3, 3), ylim = NULL, - shadelim = c(0, 1), col = "red", xlab = "x", - ylab = expression(paste(f[X](x))), main = "", ...) -} -\arguments{ - \item{func}{The density function to be plotted (dnorm, - dt, df)} - - \item{xlim}{The x-limits for the plotting region} - - \item{ylim}{The y-limits for the plotting region. If - left as NULL then it will automatically use a reasonable - ylimit for the upper bound by figuring out the highest - point in your plotting region} - - \item{shadelim}{A vector containing the upper endpoint - and the lower endpoint of the region you want to shade} - - \item{col}{The color of the shaded region} - - \item{xlab}{Label for the x-axis} - - \item{ylab}{Label for the y-axis} - - \item{main}{Title for the plot} - - \item{\ldots}{Additional parameters to pass onto the - density function. For instance if you wanted to plot a - normal density with a mean of 5 and sd of 2 you would - also pass in mean=5, sd=2 in the parameter list (assuming - you used dnorm as your 'func').} -} -\description{ - Plot a pdf and shade a section of it. -} - diff --git a/man/traintest.Rd b/man/traintest.Rd deleted file mode 100644 index d9f92af..0000000 --- a/man/traintest.Rd +++ /dev/null @@ -1,27 +0,0 @@ -\name{traintest} -\alias{traintest} -\title{Create training/testing sets} -\usage{ - traintest(dat, p.train = 0.7, sort = FALSE) -} -\arguments{ - \item{dat}{A data.frame or matrix that you want to split - into training/testing sets. It is assumed that each row - is a separate observation} - - \item{p.train}{Numeric. A number between 0 and 1 - dictating what percentage of the data will be put in the - training set} - - \item{sort}{Logical. Whether you want the - training/testing sets to be sorted in the same order as - the original data.} -} -\description{ - Split a dataset into training and testing sets based on a - training/testing percentage -} -\examples{ -traintest(mtcars) -} - From c1ca9070ff726704880f5a5763521f2fad89c8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 12 Nov 2013 22:18:04 +0100 Subject: [PATCH 03/11] typo --- NAMESPACE | 2 +- R/goldenRatioColors.R | 2 +- man/{goldenRatioRolors.Rd => goldenRatioColors.Rd} | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename man/{goldenRatioRolors.Rd => goldenRatioColors.Rd} (85%) diff --git a/NAMESPACE b/NAMESPACE index 564450b..f9812ca 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,5 @@ export(getArgs) -export(goldenRatioRolors) +export(goldenRatioColors) export(linFinder) export(permutations) export(shadePlot) diff --git a/R/goldenRatioColors.R b/R/goldenRatioColors.R index f695987..e9198c0 100644 --- a/R/goldenRatioColors.R +++ b/R/goldenRatioColors.R @@ -17,7 +17,7 @@ #' xs <- seq(1, n) #' plot(c(1, n+1), c(0, 1), type = "n") #' rect(xs, 0, xs + 1, 1, col = goldenRatioColors(n)) -goldenRatioRolors <- function(n, s = .5, v = 1, alpha = 1){ +goldenRatioColors <- function(n, s = .5, v = 1, alpha = 1){ GR <- 2/(1 + sqrt(5)) hues <- (seq(0, n-1) * GR) %% 1 cols <- hsv(hues, s, v, alpha) diff --git a/man/goldenRatioRolors.Rd b/man/goldenRatioColors.Rd similarity index 85% rename from man/goldenRatioRolors.Rd rename to man/goldenRatioColors.Rd index c5999da..586f32b 100644 --- a/man/goldenRatioRolors.Rd +++ b/man/goldenRatioColors.Rd @@ -1,8 +1,8 @@ -\name{goldenRatioRolors} -\alias{goldenRatioRolors} +\name{goldenRatioColors} +\alias{goldenRatioColors} \title{Choose n colors using the golden ratio} \usage{ - goldenRatioRolors(n, s = 0.5, v = 1, alpha = 1) + goldenRatioColors(n, s = 0.5, v = 1, alpha = 1) } \arguments{ \item{n}{Integer. The number of colors you want} From cd66f84be7907fb5b041e464c3b358497f50cf5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 12 Nov 2013 22:25:15 +0100 Subject: [PATCH 04/11] typo --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c9df7c8..e96da75 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,7 +3,7 @@ Type: Package Title: Miscellaneous functions provided by Dason Version: 0.1 Date: 2012-10-01 -Author@R: c(person("Dason", "Kurkiewicz", +Authors@R: c(person("Dason", "Kurkiewicz", role = c("aut", "ctb", "cre"), email = "dasonk@iastate.edu")) Author: Dason Kurkiewicz From d78261b3673284eb880c214f9af808d0ac115cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 12 Nov 2013 22:59:43 +0100 Subject: [PATCH 05/11] holtWinters -> holtwinters --- DESCRIPTION | 2 +- R/{holtWinters.R => holtwinters.R} | 2 +- man/{holtWinters.Rd => holtwinters.Rd} | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename R/{holtWinters.R => holtwinters.R} (96%) rename man/{holtWinters.Rd => holtwinters.Rd} (76%) diff --git a/DESCRIPTION b/DESCRIPTION index e96da75..0f5ddee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,7 +22,7 @@ Collate: 'sinkReset.R' 'permutations.R' 'getArgs.R' - 'holtWinters.R' + 'holtwinters.R' 'linFinder.R' 'shadePlot.R' 'trainTest.R' diff --git a/R/holtWinters.R b/R/holtwinters.R similarity index 96% rename from R/holtWinters.R rename to R/holtwinters.R index 6fcf649..f805f32 100644 --- a/R/holtWinters.R +++ b/R/holtwinters.R @@ -5,7 +5,7 @@ #' @param y Vector. The data to smooth. #' @param alpha Numeric. A smoothing parameter #' @param beta Numeric. A smoothing parameter -holtWinters <- function(y, alpha = .5, beta = .5){ +holtwinters <- function(y, alpha = .5, beta = .5){ n <- length(y) yhat <- numeric(n) yhat[1:2] <- NA diff --git a/man/holtWinters.Rd b/man/holtwinters.Rd similarity index 76% rename from man/holtWinters.Rd rename to man/holtwinters.Rd index 0d61762..bf7f1a3 100644 --- a/man/holtWinters.Rd +++ b/man/holtwinters.Rd @@ -1,8 +1,8 @@ -\name{holtWinters} -\alias{holtWinters} +\name{holtwinters} +\alias{holtwinters} \title{Holt winters smoothing no seasonality} \usage{ - holtWinters(y, alpha = 0.5, beta = 0.5) + holtwinters(y, alpha = 0.5, beta = 0.5) } \arguments{ \item{y}{Vector. The data to smooth.} From 02bbbf478fbca51b402c6843de75e9c1cfa9f631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 12 Nov 2013 22:19:48 +0100 Subject: [PATCH 06/11] export --- NAMESPACE | 3 +++ R/holm.R | 1 + R/lsos.R | 1 + R/qvalue.R | 1 + 4 files changed, 6 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index f9812ca..8d6ba6b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,10 @@ export(getArgs) export(goldenRatioColors) +export(holm) export(linFinder) +export(lsos) export(permutations) +export(qvalue) export(shadePlot) export(sinkReset) export(trainTest) diff --git a/R/holm.R b/R/holm.R index b04fd5e..b4f489c 100644 --- a/R/holm.R +++ b/R/holm.R @@ -3,6 +3,7 @@ #' Transform p-values based on Holm's method #' #' @param p Numeric. The p-values to adjust +#' @export #' @examples #' p <- c(.042, .001, .031, .014, .007) #' p.adjust(p, "holm") diff --git a/R/lsos.R b/R/lsos.R index 6ce7a73..2635bf2 100644 --- a/R/lsos.R +++ b/R/lsos.R @@ -11,6 +11,7 @@ #' @param head logical. Use head on the output? #' @param n numeric. Number of objects to display is head is TRUE #' @author Dirk Eddelbuettel, Tony Breyal +#' @export #' @examples #' lsos() #' \dontrun{ diff --git a/R/qvalue.R b/R/qvalue.R index fb13ac8..601d5f5 100644 --- a/R/qvalue.R +++ b/R/qvalue.R @@ -5,6 +5,7 @@ #' @param p Numeric. The p-values to adjust #' @param m Numeric. The estimated number of true nulls #' +#' @export #' @examples #' pval <- rbeta(100, 1, 3) #' qvalue(pval) From 39cb69860cde5fedf0a28a19c7d51d258cc3b2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 12 Nov 2013 22:54:16 +0100 Subject: [PATCH 07/11] support corner case of empty environment --- R/lsos.R | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/R/lsos.R b/R/lsos.R index 2635bf2..a06ca49 100644 --- a/R/lsos.R +++ b/R/lsos.R @@ -24,16 +24,23 @@ lsos <- function (pos = 1, pattern, order.by = "Size", napply <- function(names, fn) sapply(names, function(x) fn(get(x, pos = pos))) names <- ls(pos = pos, pattern = pattern) - obj.class <- napply(names, function(x) as.character(class(x))[1]) - obj.mode <- napply(names, mode) + if (length(names) > 0) { + obj.class <- napply(names, function(x) as.character(class(x))[1]) + obj.mode <- napply(names, mode) + obj.prettysize <- napply(names, function(x) { + capture.output(print(object.size(x), units = "auto")) }) + obj.size <- napply(names, object.size) + obj.dim <- t(napply(names, function(x) as.numeric(dim(x))[1:2])) + vec <- is.na(obj.dim)[, 1] & (obj.type != "function") + obj.dim[vec, 1] <- napply(names, length)[vec] + } else { + obj.class <- character() + obj.mode <- character() + obj.prettysize <- character() + obj.size <- integer() + obj.dim <- data.frame(Rows=integer(), Columns=integer()) + } obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class) - obj.prettysize <- napply(names, function(x) { - capture.output(print(object.size(x), units = "auto")) }) - obj.size <- napply(names, object.size) - obj.dim <- t(napply(names, function(x) - as.numeric(dim(x))[1:2])) - vec <- is.na(obj.dim)[, 1] & (obj.type != "function") - obj.dim[vec, 1] <- napply(names, length)[vec] out <- data.frame(obj.type, obj.size, obj.prettysize, obj.dim) names(out) <- c("Type", "Size", "PrettySize", "Rows", "Columns") if (!missing(order.by)) From 2d9d9ebd2791a2cbe1c99d3687b2b4537fb45b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 12 Nov 2013 22:56:23 +0100 Subject: [PATCH 08/11] typo? --- R/qvalue.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/qvalue.R b/R/qvalue.R index 601d5f5..44ec634 100644 --- a/R/qvalue.R +++ b/R/qvalue.R @@ -16,7 +16,7 @@ qvalue <- function(p, m = length(p)){ # sort the values tmp <- p[id] # Do the adjustment - qval <- tmp*m/(1:n) + qval <- tmp*m/(1:m) # Make sure that if p1 < p2 that q1 <= q2 qval <- rev(cummin(rev(qval))) # We could improvate that by doing the sorting in the opposite From 228f29860070412ff1a6fc5d8e2c98b4d7392592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 13 Nov 2013 11:53:07 +0100 Subject: [PATCH 09/11] bugfix --- R/lsos.R | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/R/lsos.R b/R/lsos.R index a06ca49..48afd93 100644 --- a/R/lsos.R +++ b/R/lsos.R @@ -31,16 +31,17 @@ lsos <- function (pos = 1, pattern, order.by = "Size", capture.output(print(object.size(x), units = "auto")) }) obj.size <- napply(names, object.size) obj.dim <- t(napply(names, function(x) as.numeric(dim(x))[1:2])) + obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class) vec <- is.na(obj.dim)[, 1] & (obj.type != "function") obj.dim[vec, 1] <- napply(names, length)[vec] } else { - obj.class <- character() - obj.mode <- character() - obj.prettysize <- character() - obj.size <- integer() - obj.dim <- data.frame(Rows=integer(), Columns=integer()) + obj.class <- character() + obj.mode <- character() + obj.prettysize <- character() + obj.size <- integer() + obj.dim <- data.frame(Rows=integer(), Columns=integer()) + obj.type <- character() } - obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class) out <- data.frame(obj.type, obj.size, obj.prettysize, obj.dim) names(out) <- c("Type", "Size", "PrettySize", "Rows", "Columns") if (!missing(order.by)) From 788f1c95414dbb88d95b436b5a53ce4f466eb062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 13 Nov 2013 12:03:29 +0100 Subject: [PATCH 10/11] add example for returning non-empty list --- R/lsos.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/lsos.R b/R/lsos.R index 48afd93..4c3b035 100644 --- a/R/lsos.R +++ b/R/lsos.R @@ -14,6 +14,7 @@ #' @export #' @examples #' lsos() +#' lsos(pos = 2, n = 5) #' \dontrun{ #' a <- rnorm(100000) #' b <- matrix(1, 1000, 100) From aaadf444adf1c2d45111ab35cb245e539c8826a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 13 Nov 2013 12:03:47 +0100 Subject: [PATCH 11/11] bugfix: obey implicit value of order.by --- R/lsos.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/lsos.R b/R/lsos.R index 4c3b035..384b0d0 100644 --- a/R/lsos.R +++ b/R/lsos.R @@ -45,7 +45,7 @@ lsos <- function (pos = 1, pattern, order.by = "Size", } out <- data.frame(obj.type, obj.size, obj.prettysize, obj.dim) names(out) <- c("Type", "Size", "PrettySize", "Rows", "Columns") - if (!missing(order.by)) + if (!is.null(order.by) || !is.na(order.by)) out <- out[order(out[[order.by]], decreasing=decreasing), ] if (head) out <- head(out, n)