Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Mar 30, 2009
1 parent 070d37e commit 9d99cfc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion R/indexed-list.r
Expand Up @@ -18,7 +18,7 @@ indexed_list <- function(env, index) {
length.indexed_list <- function(x) length(x$index) length.indexed_list <- function(x) length(x$index)


"[[.indexed_list" <- function(x, i) { "[[.indexed_list" <- function(x, i) {
x$env$data[x$index[[i]], ] x$env$data[x$index[[i]], , drop = FALSE]
} }


names.indexed_list <- function(x) names(x$index) names.indexed_list <- function(x) names(x$index)
Expand Down
3 changes: 2 additions & 1 deletion R/ply-list.r
Expand Up @@ -40,7 +40,8 @@ llply <- function(.data, .fun = NULL, ..., .progress = "none") {
result <- vector("list", n) result <- vector("list", n)


for(i in seq_len(n)) { for(i in seq_len(n)) {
res <- .fun(pieces[[i]], ...) piece <- pieces[[i]]
res <- .fun(piece, ...)
if (!is.null(res)) result[[i]] <- res if (!is.null(res)) result[[i]] <- res
progress$step() progress$step()
} }
Expand Down
8 changes: 5 additions & 3 deletions R/simplify.r
Expand Up @@ -54,10 +54,12 @@ list_to_array <- function(res, labels = NULL, .drop = FALSE) {
if (all(atomic)) { if (all(atomic)) {
# Atomics need to be same size # Atomics need to be same size
dlength <- unique.default(llply(res, dims)) dlength <- unique.default(llply(res, dims))
if (length(dlength) != 1) stop("Results must have the same number of dimensions.") if (length(dlength) != 1)
stop("Results must have the same number of dimensions.")


dims <- unique(do.call("rbind", llply(res, amv_dim))) dims <- unique(do.call("rbind", llply(res, amv_dim)))
if (nrow(dims) != 1) stop("Results must have the same dimensions.") if (nrow(dims) != 1)
stop("Results must have the same dimensions.")


res_dim <- amv_dim(res[[1]]) res_dim <- amv_dim(res[[1]])
res_labels <- amv_dimnames(res[[1]]) res_labels <- amv_dimnames(res[[1]])
Expand Down Expand Up @@ -85,7 +87,7 @@ list_to_array <- function(res, labels = NULL, .drop = FALSE) {
} }


index <- cbind( index <- cbind(
labels[rep(seq_len(nrow(labels)), each = nrow(res_index)), , drop = FALSE], labels[rep(seq_len(nrow(labels)), each = nrow(res_index)), ,drop = FALSE],
res_index[rep(seq_len(nrow(res_index)), nrow(labels)), , drop = FALSE] res_index[rep(seq_len(nrow(res_index)), nrow(labels)), , drop = FALSE]
) )


Expand Down

0 comments on commit 9d99cfc

Please sign in to comment.