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 diff --git a/DESCRIPTION b/DESCRIPTION index c9df7c8..0f5ddee 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 @@ -22,7 +22,7 @@ Collate: 'sinkReset.R' 'permutations.R' 'getArgs.R' - 'holtWinters.R' + 'holtwinters.R' 'linFinder.R' 'shadePlot.R' 'trainTest.R' diff --git a/NAMESPACE b/NAMESPACE index 564450b..8d6ba6b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,10 @@ export(getArgs) -export(goldenRatioRolors) +export(goldenRatioColors) +export(holm) export(linFinder) +export(lsos) export(permutations) +export(qvalue) export(shadePlot) export(sinkReset) export(trainTest) 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/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/holtWinters.R b/R/holtwinters.R similarity index 96% rename from R/holtWinters.R rename to R/holtwinters.R index bf5fc2e..e614f36 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/R/lsos.R b/R/lsos.R index 6ce7a73..384b0d0 100644 --- a/R/lsos.R +++ b/R/lsos.R @@ -11,8 +11,10 @@ #' @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() +#' lsos(pos = 2, n = 5) #' \dontrun{ #' a <- rnorm(100000) #' b <- matrix(1, 1000, 100) @@ -23,19 +25,27 @@ 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) - 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] + 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])) + 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.type <- character() + } 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) diff --git a/R/qvalue.R b/R/qvalue.R index fb13ac8..44ec634 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) @@ -15,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 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 index 44ceb64..586f32b 100644 --- a/man/goldenRatioColors.Rd +++ b/man/goldenRatioColors.Rd @@ -1,8 +1,8 @@ -\name{goldenratiocolors} -\alias{goldenratiocolors} +\name{goldenRatioColors} +\alias{goldenRatioColors} \title{Choose n colors using the golden ratio} \usage{ - goldenratiocolors(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} @@ -20,12 +20,12 @@ ratio. } \examples{ -cols <- goldenratiocolors(5) +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)) +rect(xs, 0, xs + 1, 1, col = goldenRatioColors(n)) } diff --git a/man/goldenRatioRolors.Rd b/man/goldenRatioRolors.Rd deleted file mode 100644 index c5999da..0000000 --- a/man/goldenRatioRolors.Rd +++ /dev/null @@ -1,31 +0,0 @@ -\name{goldenRatioRolors} -\alias{goldenRatioRolors} -\title{Choose n colors using the golden ratio} -\usage{ - goldenRatioRolors(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 0d61762..0000000 --- a/man/holtWinters.Rd +++ /dev/null @@ -1,17 +0,0 @@ -\name{holtWinters} -\alias{holtWinters} -\title{Holt winters smoothing no seasonality} -\usage{ - holtWinters(y, alpha = 0.5, beta = 0.5) -} -\arguments{ - \item{y}{Vector. The data to smooth.} - - \item{alpha}{Numeric. A smoothing parameter} - - \item{beta}{Numeric. A smoothing parameter} -} -\description{ - Holt winters smoothing with no seasonality -} - diff --git a/man/holtwinters.Rd b/man/holtwinters.Rd index c5084a1..bf7f1a3 100644 --- a/man/holtwinters.Rd +++ b/man/holtwinters.Rd @@ -4,6 +4,13 @@ \usage{ holtwinters(y, alpha = 0.5, beta = 0.5) } +\arguments{ + \item{y}{Vector. The data to smooth.} + + \item{alpha}{Numeric. A smoothing parameter} + + \item{beta}{Numeric. A smoothing parameter} +} \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) -} -