Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Documentation updates for R CMD check

  • Loading branch information...
commit 31e81022a11c2f70e7927aed0e6ed34703bd4b23 1 parent 4b87dea
@hadley authored
View
2  R/helper-try.r
@@ -6,8 +6,8 @@
# @argument should all error messages be suppressed?
# @value a function
# @seealso \code{\link{try_default}}
-#X \dontrun{
#X f <- function(x) if (x == 1) stop("Error!") else 1
+#X \dontrun{
#X f(1)
#X f(2)
#X }
View
3  R/indexed-array.r
@@ -5,6 +5,7 @@
# @argument list of indices
# @keywords internal
# @alias [[.indexed_array
+# @alias names.indexed_array
# @alias length.indexed_array
indexed_array <- function(env, index) {
if (is.list(env$data) && !is.data.frame(env$data)) { # && !is.array(data)
@@ -31,3 +32,5 @@ length.indexed_array <- function(x) nrow(x$index)
sep = "")
eval(parse(text = call))
}
+
+names.indexed_array <- function(x) rownames(x$index)
View
2  R/indexed-data-frame.r
@@ -8,6 +8,8 @@
# @alias names.indexed
# @alias as.list.indexed
# @alias [[.indexed_df
+# @alias [.indexed
+# @alias print.indexed
indexed_df <- function(env, index) {
structure(
list(env = env, index = index),
View
9 R/indexed.r
@@ -9,7 +9,14 @@ as.list.indexed <- function(x, ...) {
out[[i]] <- x[[i]]
}
- mostattributes(out) <- attributes(x)
class(out) <- c("split", "list")
out
}
+
+print.indexed <- function(x, ...) {
+ print(as.list(x))
+}
+
+"[.indexed" <- function(x, ...) {
+ as.list(x)[...]
+}
View
5 R/split-array.r
@@ -17,6 +17,10 @@
# @value a list of lower-d slices, with attributes that record split details
#X splitter_a(mtcars, 1)
#X splitter_a(mtcars, 2)
+#X
+#X splitter_a(ozone, 2)
+#X splitter_a(ozone, 3)
+#X splitter_a(ozone, 1:2)
splitter_a <- function(data, .margins = 1) {
if (!all(.margins %in% seq_len(dims(data)))) stop("Invalid margin")
@@ -25,7 +29,6 @@ splitter_a <- function(data, .margins = 1) {
indices <- expand.grid(dimensions, KEEP.OUT.ATTRS = FALSE)
names(indices) <- paste("X", 1:ncol(indices), sep="")
-
il <- indexed_array(environment(), indices)
if (is.data.frame(data) & identical(.margins, 1)) {
View
10 R/split-data-frame.r
@@ -12,8 +12,8 @@
# other operations.
#
# @seealso \code{\link{.}} for quoting variables, \code{\link{split}}
-# @parameters data frame
-# @parameters a \link{quoted} list of variables, a formula, or character vector
+# @arguments data frame
+# @arguments a \link{quoted} list of variables, a formula, or character vector
# @value a list of data.frames, with attributes that record split details
#X splitter_d(mtcars, .(cyl))
#X splitter_d(mtcars, .(vs, am))
@@ -48,6 +48,12 @@ splitter_d <- function(data, .variables = NULL, drop = TRUE) {
)
}
+# Generate labels for split data frame
+# Create data frame giving labels for split data frame.
+#
+# @arguments list of variables to split up by
+# @argument whether all possible combinations should be considered, or only those present in the data
+# @keywords internal
split_labels <- function(splits, drop) {
factors <- llply(splits, addNA, ifany = TRUE)
splitv <- addNA(interaction(factors, drop = drop, lex.order = TRUE),
View
7 man/ddply-5k.rd
@@ -30,9 +30,14 @@ length, it will be \code{rbind}ed together and converted to a data frame.
Any other values will result in an error.
}
-\examples{mean_rbi <- function(df) mean(df$rbi, na.rm=TRUE)
+\examples{
+ddply(baseball, .(year), "nrow")
+ddply(baseball, .(lg), c("nrow", "ncol"))
+
+mean_rbi <- function(df) mean(df$rbi, na.rm=TRUE)
rbi <- ddply(baseball, .(year), mean_rbi)
with(rbi, plot(year, V1, type="l"))
+rbi <- ddply(baseball, .(year), "mean_rbi")
mean_rbi <- function(rbi, ...) mean(rbi, na.rm=TRUE)
rbi <- ddply(baseball, .(year), splat(mean_rbi))
View
10 man/failwith-sc.rd
@@ -15,5 +15,13 @@ Modify a function so that it returns a default value when there is an error.
\value{a function}
\details{}
\seealso{\code{\link{try_default}}}
-\examples{}
+\examples{f <- function(x) if (x == 1) stop("Error!") else 1
+\dontrun{
+f(1)
+f(2)
+}
+
+safef <- failwith(NULL, f)
+safef(1)
+safef(2) }
View
21 man/indexed-array-4w.rd
@@ -0,0 +1,21 @@
+\name{indexed_array}
+\alias{indexed_array}
+\alias{[[.indexed_array}
+\alias{names.indexed_array}
+\alias{length.indexed_array}
+\title{An indexed array}
+\author{Hadley Wickham <h.wickham@gmail.com>}
+
+\description{
+Create a indexed array, a space efficient way of indexing into a large array
+}
+\usage{indexed_array(env, index)}
+\arguments{
+\item{env}{environment containing data frame}
+\item{index}{}
+}
+
+\details{}
+
+\examples{}
+
View
16 man/indexed-list-55.rd → man/indexed-df-uf.rd
@@ -1,16 +1,18 @@
-\name{indexed_list}
-\alias{indexed_list}
-\alias{length.indexed_list}
-\alias{names.indexed_list}
-\alias{as.list.indexed_list}
-\alias{[[.indexed_list}
+\name{indexed_df}
+\alias{indexed_df}
+\alias{length.indexed}
+\alias{names.indexed}
+\alias{as.list.indexed}
+\alias{[[.indexed_df}
+\alias{[.indexed}
+\alias{print.indexed}
\title{An indexed list}
\author{Hadley Wickham <h.wickham@gmail.com>}
\description{
Create a indexed list, a space efficient way of indexing into a large data frame
}
-\usage{indexed_list(env, index)}
+\usage{indexed_df(env, index)}
\arguments{
\item{env}{environment containing data frame}
\item{index}{}
View
18 man/split-labels-0o.rd
@@ -0,0 +1,18 @@
+\name{split_labels}
+\alias{split_labels}
+\title{Generate labels for split data frame}
+\author{Hadley Wickham <h.wickham@gmail.com>}
+
+\description{
+Create data frame giving labels for split data frame.
+}
+\usage{split_labels(splits, drop)}
+\arguments{
+\item{splits}{list of variables to split up by}
+\item{drop}{}
+}
+
+\details{}
+
+\examples{}
+
View
6 man/splitter-a-cs.rd
@@ -24,5 +24,9 @@ also includes enough information to recreate the split from attributes on
the list of pieces.}
\examples{splitter_a(mtcars, 1)
-splitter_a(mtcars, 2)}
+splitter_a(mtcars, 2)
+
+splitter_a(ozone, 2)
+splitter_a(ozone, 3)
+splitter_a(ozone, 1:2)}
View
15 man/splitter-d-cs.rd
@@ -8,8 +8,8 @@ Split a data frame into pieces based on variable contained in that data frame
}
\usage{splitter_d(data, .variables = NULL, drop = TRUE)}
\arguments{
-\item{data}{}
-\item{.variables}{}
+\item{data}{data frame}
+\item{.variables}{a \link{quoted} list of variables, a formula, or character vector}
\item{drop}{}
}
\value{a list of data.frames, with attributes that record split details}
@@ -25,5 +25,14 @@ other operations.}
\seealso{\code{\link{.}} for quoting variables, \code{\link{split}}}
\examples{splitter_d(mtcars, .(cyl))
splitter_d(mtcars, .(vs, am))
-splitter_d(mtcars, .(am, vs))}
+splitter_d(mtcars, .(am, vs))
+
+mtcars$cyl2 <- factor(mtcars$cyl, levels = c(2, 4, 6, 8, 10))
+splitter_d(mtcars, .(cyl2), drop = TRUE)
+splitter_d(mtcars, .(cyl2), drop = FALSE)
+
+mtcars$cyl3 <- ifelse(mtcars$vs == 1, NA, mtcars$cyl)
+splitter_d(mtcars, .(cyl3))
+splitter_d(mtcars, .(cyl3, vs))
+splitter_d(mtcars, .(cyl3, vs), drop = FALSE)}
Please sign in to comment.
Something went wrong with that request. Please try again.