Permalink
Browse files

Trim trailing spaces

  • Loading branch information...
1 parent 36e4916 commit ea17d3b0b43eefde0666f1f9fe750d6592833820 @hadley committed Oct 6, 2012
Showing with 543 additions and 543 deletions.
  1. +10 −10 R/data.r
  2. +11 −11 R/dimensions.r
  3. +2 −2 R/helper-arrange.r
  4. +7 −7 R/helper-col-wise.r
  5. +8 −8 R/helper-count.r
  6. +2 −2 R/helper-data-frame.r
  7. +3 −3 R/helper-defaults.r
  8. +8 −8 R/helper-each.r
  9. +3 −3 R/helper-match-df.r
  10. +2 −2 R/helper-mutate.r
  11. +1 −1 R/helper-rename.r
  12. +2 −2 R/helper-splat.r
  13. +5 −5 R/helper-summarise.r
  14. +4 −4 R/helper-take.r
  15. +6 −6 R/helper-try.r
  16. +6 −6 R/helper-vaggregate.r
  17. +3 −3 R/id.r
  18. +10 −10 R/immutable.r
  19. +8 −8 R/indexed-array.r
  20. +3 −3 R/indexed-data-frame.r
  21. +1 −1 R/indexed.r
  22. +24 −24 R/join.r
  23. +1 −1 R/loop-apply.r
  24. +17 −17 R/ply-array.r
  25. +18 −18 R/ply-data-frame.r
  26. +10 −10 R/ply-iterator.r
  27. +16 −16 R/ply-list.r
  28. +29 −29 R/ply-mapply.r
  29. +19 −19 R/ply-null.r
  30. +28 −28 R/ply-replicate.r
  31. +20 −20 R/progress.r
  32. +22 −22 R/quote.r
  33. +17 −17 R/rbind-matrix.r
  34. +23 −23 R/rbind.r
  35. +13 −13 R/simplify-array.r
  36. +7 −7 R/simplify-data-frame.r
  37. +4 −4 R/simplify-vector.r
  38. +15 −15 R/split-array.r
  39. +11 −11 R/split-data-frame.r
  40. +1 −1 R/split-indices.r
  41. +3 −3 R/split.r
  42. +7 −7 R/utils.r
  43. +1 −1 benchmark/bench-llply.r
  44. +1 −1 benchmark/data.r
  45. +4 −4 benchmark/vis.r
  46. +18 −18 inst/tests/test-array.r
  47. +11 −11 inst/tests/test-count.r
  48. +10 −10 inst/tests/test-data-frame.r
  49. +3 −3 inst/tests/test-empty.r
  50. +13 −13 inst/tests/test-join.r
  51. +3 −3 inst/tests/test-list.r
  52. +3 −3 inst/tests/test-mapply.r
  53. +3 −3 inst/tests/test-mutate.r
  54. +1 −1 inst/tests/test-ninteraction.r
  55. +1 −1 inst/tests/test-progress.r
  56. +7 −7 inst/tests/test-quote.r
  57. +8 −8 inst/tests/test-rbind.matrix.r
  58. +18 −18 inst/tests/test-rbind.r
  59. +4 −4 inst/tests/test-rename.r
  60. +2 −2 inst/tests/test-replicate.r
  61. +1 −1 inst/tests/test-simplify-df.r
  62. +1 −1 inst/tests/test-split-data-frame.r
  63. +3 −3 inst/tests/test-split-labels.r
  64. +2 −2 inst/tests/test-summarise.r
  65. +1 −1 man-roxygen/-a.r
  66. +2 −2 man-roxygen/-d.r
  67. +1 −1 man-roxygen/-l.r
  68. +2 −2 man-roxygen/a-.r
  69. +3 −3 man-roxygen/d-.r
  70. +1 −1 man-roxygen/l-.r
  71. +3 −3 man-roxygen/ply.r
  72. +1 −1 tests/dependencies.R
  73. +1 −1 tests/test-all.R
View
@@ -17,27 +17,27 @@
#' @examples
#' value <- ozone[1, 1, ]
#' time <- 1:72
-#' month.abbr <- c("Jan", "Feb", "Mar", "Apr", "May",
+#' month.abbr <- c("Jan", "Feb", "Mar", "Apr", "May",
#' "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
#' month <- factor(rep(month.abbr, length = 72), levels = month.abbr)
#' year <- rep(1:6, each = 12)
#' deseasf <- function(value) lm(value ~ month - 1)
-#'
+#'
#' models <- alply(ozone, 1:2, deseasf)
#' coefs <- laply(models, coef)
#' dimnames(coefs)[[3]] <- month.abbr
#' names(dimnames(coefs))[3] <- "month"
-#'
+#'
#' deseas <- laply(models, resid)
#' dimnames(deseas)[[3]] <- 1:72
#' names(dimnames(deseas))[3] <- "time"
-#'
+#'
#' dim(coefs)
#' dim(deseas)
NULL
#' Yearly batting records for all major league baseball players
-#'
+#'
#' This data frame contains batting statistics for a subset of players
#' collected from \url{http://www.baseball-databank.org/}. There are a total
#' of 21,699 records, covering 1,228 players from 1871 to 2007. Only players
@@ -57,7 +57,7 @@ NULL
#' \item h, hits, times reached base because of a batted, fair ball without
#' error by the defense
#' \item X2b, hits on which the batter reached second base safely
-#' \item X3b, hits on which the batter reached third base safely
+#' \item X3b, hits on which the batter reached third base safely
#' \item hr, number of home runs
#' \item rbi, runs batted in
#' \item sb, stolen bases
@@ -79,17 +79,17 @@ NULL
#' @examples
#' baberuth <- subset(baseball, id == "ruthba01")
#' baberuth$cyear <- baberuth$year - min(baberuth$year) + 1
-#'
+#'
#' calculate_cyear <- function(df) {
-#' mutate(df,
+#' mutate(df,
#' cyear = year - min(year),
#' cpercent = cyear / (max(year) - min(year))
#' )
#' }
-#'
+#'
#' baseball <- ddply(baseball, .(id), calculate_cyear)
#' baseball <- subset(baseball, ab >= 25)
-#'
+#'
#' model <- function(df) {
#' lm(rbi / ab ~ cyear, data=df)
#' }
View
@@ -1,49 +1,49 @@
#' Number of dimensions.
#'
#' Number of dimensions of an array or vector
-#'
+#'
#' @param x array
#' @keywords internal
dims <- function(x) length(amv_dim(x))
#' Dimensions.
#'
#' Consistent dimensions for vectors, matrices and arrays.
-#'
+#'
#' @param x array, matrix or vector
-#' @keywords internal
+#' @keywords internal
amv_dim <- function(x) if (is.vector(x)) length(x) else dim(x)
#' Dimension names.
#'
#' Consistent dimnames for vectors, matrices and arrays.
-#'
+#'
#' Unlike \code{\link{dimnames}} no part of the output will ever be
#' null. If a component of dimnames is omitted, \code{amv_dimnames}
#' will return an integer sequence of the appropriate length.
-#'
+#'
#' @param x array, matrix or vector
-#' @keywords internal
+#' @keywords internal
#' @export
amv_dimnames <- function(x) {
d <- if (is.vector(x)) list(names(x)) else dimnames(x)
-
+
if (is.null(d)) d <- rep(list(NULL), dims(x))
null_names <- which(unlist(llply(d, is.null)))
d[null_names] <- llply(null_names, function(i) seq.int(amv_dim(x)[i]))
-
+
# if (is.null(names(d))) names(d) <- paste("X", 1:length(d), sep="")
d
}
#' Reduce dimensions.
#'
#' Remove extraneous dimensions
-#'
+#'
#' @param x array
-#' @keywords internal
+#' @keywords internal
reduce_dim <- function(x) {
- do.call("[", c(list(x), lapply(dim(x), function(x) if (x==1) 1 else TRUE), drop=TRUE))
+ do.call("[", c(list(x), lapply(dim(x), function(x) if (x==1) 1 else TRUE), drop=TRUE))
}
View
@@ -1,7 +1,7 @@
#' Order a data frame by its colums.
#'
#' This function completes the subsetting, transforming and ordering triad
-#' with a function that works in a similar way to \code{\link{subset}} and
+#' with a function that works in a similar way to \code{\link{subset}} and
#' \code{\link{transform}} but for reordering a data frame by its columns.
#' This saves a lot of typing!
#'
@@ -25,7 +25,7 @@
arrange <- function(df, ...) {
ord <- eval(substitute(order(...)), df, parent.frame())
if(length(ord) != nrow(df)) {
- stop("Length of ordering vectors don't match data frame size",
+ stop("Length of ordering vectors don't match data frame size",
call. = FALSE)
}
unrowname(df[ord, , drop = FALSE])
View
@@ -5,7 +5,7 @@
#'
#' \code{catcolwise} and \code{numcolwise} provide version that only operate
#' on discrete and numeric variables respectively.
-#'
+#'
#' @param .fun function
#' @param .cols either a function that tests columns for inclusion, or a
#' quoted object giving which columns to process
@@ -15,16 +15,16 @@
#' # Count number of missing values
#' nmissing <- function(x) sum(is.na(x))
#'
-#' # Apply to every column in a data frame
+#' # Apply to every column in a data frame
#' colwise(nmissing)(baseball)
-#' # This syntax looks a little different. It is shorthand for the
+#' # This syntax looks a little different. It is shorthand for the
#' # the following:
#' f <- colwise(nmissing)
#' f(baseball)
#'
#' # This is particularly useful in conjunction with d*ply
#' ddply(baseball, .(year), colwise(nmissing))
-#'
+#'
#' # To operate only on specified columns, supply them as the second
#' # argument. Many different forms are accepted.
#' ddply(baseball, .(year), colwise(nmissing, .(sb, cs, so)))
@@ -37,7 +37,7 @@
#' ddply(baseball, .(year), colwise(nmissing, is.numeric))
#' ddply(baseball, .(year), colwise(nmissing, is.discrete))
#'
-#' # These last two cases are particularly common, so some shortcuts are
+#' # These last two cases are particularly common, so some shortcuts are
#' # provided:
#' ddply(baseball, .(year), numcolwise(nmissing))
#' ddply(baseball, .(year), catcolwise(nmissing))
@@ -48,13 +48,13 @@ colwise <- function(.fun, .cols = true) {
} else {
filter <- function(df) Filter(.cols, df)
}
-
+
function(df, ...) {
stopifnot(is.data.frame(df))
df <- strip_splits(df)
filtered <- filter(df)
if (length(filtered) == 0) return(data.frame())
-
+
df <- quickdf(lapply(filtered, .fun, ...))
names(df) <- names(filtered)
df
View
@@ -23,7 +23,7 @@
#' @export
#' @examples
#' # Count of each value of "id" in the first 100 cases
-#' count(baseball[1:100,], vars = "id")
+#' count(baseball[1:100,], vars = "id")
#' # Count of ids, weighted by their "g" loading
#' count(baseball[1:100,], vars = "id", wt_var = "g")
#' count(baseball, "id", "ab")
@@ -39,35 +39,35 @@ count <- function(df, vars = NULL, wt_var = NULL) {
if (is.vector(df)) {
df <- data.frame(x = df)
}
-
+
if (!is.null(vars)) {
vars <- as.quoted(vars)
df2 <- quickdf(eval.quoted(vars, df))
} else {
df2 <- df
}
-
+
id <- ninteraction(df2, drop = TRUE)
u_id <- !duplicated(id)
labels <- df2[u_id, , drop = FALSE]
labels <- labels[order(id[u_id]), , drop = FALSE]
-
+
if (is.null(wt_var) && "freq" %in% names(df)) {
message("Using freq as weighting variable")
wt_var <- "freq"
}
-
+
if (!is.null(wt_var)) {
wt_var <- as.quoted(wt_var)
if (length(wt_var) > 1) {
stop("wt_var must be a single variable", call. = FALSE)
}
-
+
wt <- eval.quoted(wt_var, df)[[1]]
freq <- vaggregate(wt, id, sum, .default = 0)
} else {
- freq <- tabulate(id, attr(id, "n"))
+ freq <- tabulate(id, attr(id, "n"))
}
-
+
unrowname(data.frame(labels, freq))
}
@@ -2,10 +2,10 @@
#'
#' Create a new function that returns the existing function wrapped in a
#' data.frame
-#'
+#'
#' This is useful when calling \code{*dply} functions with a function that
#' returns a vector, and you want the output in rows, rather than columns
-#'
+#'
#' @keywords manip
#' @param x function to make return a data frame
#' @param row.names necessary to match the generic, but not used
View
@@ -1,11 +1,11 @@
#' Set defaults.
#'
#' Convient method for combining a list of values with their defaults.
-#'
+#'
#' @param x list of values
#' @param y defaults
-#' @keywords manip
+#' @keywords manip
#' @export
defaults <- function(x, y) {
c(x, y[setdiff(names(y), names(x))])
-}
+}
View
@@ -3,7 +3,7 @@
#' Combine multiple functions into a single function returning a named vector
#' of outputs.
#' Note: you cannot supply additional parameters for the summary functions
-#'
+#'
#' @param ... functions to combine. each function should produce a single
#' number as output
#' @keywords manip
@@ -27,12 +27,12 @@ each <- function(...) {
fs <- list(...)
if (length(fs[[1]]) > 1) {
fs <- fs[[1]]
-
+
# Jump through hoops to work out names
snames <- as.list(match.call()[2])[[1]]
fnames <- unlist(lapply(as.list(snames)[-1], deparse))
}
-
+
# Find function names and replace with function objects
char <- laply(fs, is.character)
fnames[char] <- fs[char]
@@ -41,14 +41,14 @@ each <- function(...) {
unames <- names(fs)
if (is.null(unames)) unames <- fnames
unames[unames == ""] <- fnames[unames == ""]
-
+
n <- length(fs)
proto <- NULL
result <- NULL
-
+
if (n == 1) {
# If there is only one function, things are simple. We just
- # need to name the output, if appropriate.
+ # need to name the output, if appropriate.
function(x, ...) {
res <- fs[[1]](x, ...)
if (length(res) == 1) names(res) <- unames
@@ -65,9 +65,9 @@ each <- function(...) {
for(i in 1:n) result[[i]] <- fs[[i]](x, ...)
proto <<- list_to_vector(result)
} else {
- for(i in 1:n) proto[[i]] <- fs[[i]](x, ...)
+ for(i in 1:n) proto[[i]] <- fs[[i]](x, ...)
}
proto
- }
+ }
}
}
View
@@ -9,7 +9,7 @@
#' to both data frames.
#' @return a data frame
#' @seealso \code{\link{join}} to combine the columns from both x and y
-#' and \code{\link{match}} for the base function selecting matching items
+#' and \code{\link{match}} for the base function selecting matching items
#' @export
#' @examples
#' # count the occurrences of each id in the baseball dataframe, then get the subset with a freq >25
@@ -19,7 +19,7 @@
#' # 30 ansonca01 27
#' # 48 baineha01 27
#' # ...
-#' # Select only rows from these longterm players from the baseball dataframe
+#' # Select only rows from these longterm players from the baseball dataframe
#' # (match would default to match on shared column names, but here was explicitly set "id")
#' bb_longterm <- match_df(baseball, longterm, on="id")
#' bb_longterm[1:5,]
@@ -28,7 +28,7 @@ match_df <- function(x, y, on = NULL) {
on <- intersect(names(x), names(y))
message("Matching on: ", paste(on, collapse = ", "))
}
-
+
keys <- join.keys(x, y, on)
x[keys$x %in% keys$y, ]
}
View
@@ -20,15 +20,15 @@
#' mutate(airquality, new = -Ozone, Temp = (Temp - 32) / 1.8)
#'
#' # Things transform can't do
-#' mutate(airquality, Temp = (Temp - 32) / 1.8, OzT = Ozone / Temp)
+#' mutate(airquality, Temp = (Temp - 32) / 1.8, OzT = Ozone / Temp)
#'
#' # mutate is rather faster than transform
#' system.time(transform(baseball, avg_ab = ab / g))
#' system.time(mutate(baseball, avg_ab = ab / g))
mutate <- function(.data, ...) {
cols <- as.list(substitute(list(...))[-1])
cols <- cols[names(cols) != ""] # Silently drop unnamed columns
-
+
for(col in names(cols)) {
.data[[col]] <- eval(cols[[col]], .data, parent.frame())
}
View
@@ -5,7 +5,7 @@
#' old names as names.
#' @param warn_missing print a message if any of the old names are
#' not actually present in \code{x}.
-#' Note: x is not altered: To save the result, you need to copy the returned
+#' Note: x is not altered: To save the result, you need to copy the returned
#' data into a variable.
#' @export
#' @importFrom stats setNames
View
@@ -2,10 +2,10 @@
#'
#' Wraps a function in do.call, so instead of taking multiple arguments, it
#' takes a single named list which will be interpreted as its arguments.
-#'
+#'
#' This is useful when you want to pass a function a row of data frame or
#' array, and don't want to manually pull it apart in your function.
-#'
+#'
#' @param flat function to splat
#' @return a function
#' @export
Oops, something went wrong. Retry.

0 comments on commit ea17d3b

Please sign in to comment.