Skip to content

Commit

Permalink
Documentation updates for R CMD check
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Apr 11, 2009
1 parent 4b87dea commit 31e8102
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 18 deletions.
2 changes: 1 addition & 1 deletion R/helper-try.r
Expand Up @@ -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 }
Expand Down
3 changes: 3 additions & 0 deletions R/indexed-array.r
Expand Up @@ -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)
Expand All @@ -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)
2 changes: 2 additions & 0 deletions R/indexed-data-frame.r
Expand Up @@ -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),
Expand Down
9 changes: 8 additions & 1 deletion R/indexed.r
Expand Up @@ -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)[...]
}
5 changes: 4 additions & 1 deletion R/split-array.r
Expand Up @@ -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")

Expand All @@ -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)) {
Expand Down
10 changes: 8 additions & 2 deletions R/split-data-frame.r
Expand Up @@ -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))
Expand Down Expand Up @@ -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),
Expand Down
7 changes: 6 additions & 1 deletion man/ddply-5k.rd
Expand Up @@ -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))
Expand Down
10 changes: 9 additions & 1 deletion man/failwith-sc.rd
Expand Up @@ -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) }

21 changes: 21 additions & 0 deletions 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{}

16 changes: 9 additions & 7 deletions 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}{}
Expand Down
18 changes: 18 additions & 0 deletions 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{}

6 changes: 5 additions & 1 deletion man/splitter-a-cs.rd
Expand Up @@ -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)}

15 changes: 12 additions & 3 deletions man/splitter-d-cs.rd
Expand Up @@ -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}
Expand All @@ -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)}

0 comments on commit 31e8102

Please sign in to comment.