Commit 0a05a969 authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 1.4-5

parent aecec187
2016-05-14 Tony Plate <tplate@acm.org>
* Version 1.4-4
* add imports to NAMESPACE file
2016-04-16 Tony Plate <tplate@acm.org>
* Version 1.4-3
* add ... args to asub() and adrop() generics
2013-08-18 Tony Plate <tplate@acm.org>
* Version 1.4-1
* add use.dnns= arg to abind() to propagate names on dimnames (i.e., names(dimnames(x)))
......
Package: abind
Version: 1.4-3
Date: 2015-03-05
Version: 1.4-5
Date: 2016-06-19
Title: Combine Multidimensional Arrays
Author: Tony Plate <tplate@acm.org> and Richard Heiberger
Maintainer: Tony Plate <tplate@acm.org>
......@@ -10,8 +10,9 @@ Description: Combine multidimensional arrays into a single array.
provides functions 'adrop', 'asub', and 'afill' for manipulating,
extracting and replacing data in arrays.
Depends: R (>= 1.5.0)
Imports: methods, utils
License: LGPL (>= 2)
NeedsCompilation: no
Packaged: 2015-03-13 03:29:01 UTC; tap
Packaged: 2016-07-19 15:24:25 UTC; tap
Repository: CRAN
Date/Publication: 2015-03-13 07:54:43
Date/Publication: 2016-07-21 19:18:05
51746bc6d5286474da3115be1c0318b2 *ChangeLog
29e146fc92ac80a7bd92756dc0620bc2 *DESCRIPTION
6c5fc50b8490a053fc6ce48e122664f9 *NAMESPACE
e3f553d048fcebe175951f24b0350e29 *ChangeLog
f300754a4063ce128232f36d170ffaf3 *DESCRIPTION
52255f1f1ec9c8cdb04a02793c4492bf *NAMESPACE
f29a412f5ba4d85f5f263bf312d886a7 *R/abind.R
8e04ca9e2eaedfd1d2e56f7244b3b115 *R/acorn.R
9aa6111e78914f82786267abf410a89a *R/adrop.R
e2328c75f1851ac339c5a4bb0a7de61b *R/afill.R
b91a43dfa5f33edc454581eee8d489ee *R/asub.R
7cb59f6592569755a5df1f7329b70a52 *R/adrop.R
2b075171c7a377148e3d06156ee93b5b *R/afill.R
2ce1491758ff8746a248ee786452eefb *R/asub.R
d41d8cd98f00b204e9800998ecf8427e *inst/sccversion.txt
d41d8cd98f00b204e9800998ecf8427e *inst/svnversion.txt
fb64a7d309520d1136b99caf9775be3d *man/abind.Rd
24ae5b24bc5b1fb65846a0bf41159d1f *man/acorn.Rd
0d3af220daec9e9b109bdda9917a5d85 *man/adrop.Rd
9bb15ec20f2fdc7bc2ab0370a408367c *man/adrop.Rd
62762ef7274f38c3caccf14190b4d974 *man/afill.Rd
5dbcde0fee5b2aab3f2b44ee1dfe5a9f *man/asub.Rd
4c046ab5e7b2abac859711780b75bc62 *man/asub.Rd
7161ff9ea79f9370c2a4c7aeeeea5659 *tests/abind.R
fcfb1ac8a35237a9a6f5b95e7c0f84e1 *tests/abind.Rout.save
0e6deb6ea58cbae7e1617b67c2641d36 *tests/adrop.R
7513f2bbec5263ea69e1b085b5c71465 *tests/adrop.Rout.save
2e427a53aca2f42cee992325c2272bc1 *tests/afill.R
2971533ac03b1e065474a4975bfd8698 *tests/afill.Rout.save
edad9b05bd9bec901140c7d23147d858 *tests/afill.R
69b81865d8fced27c0e56f1467184b7b *tests/afill.Rout.save
455c0dcd4dd7eef26d5008d5952e9ba8 *tests/asub.R
6bd3795000cb1b1d20d71d656a18ddb6 *tests/asub.Rout.save
891bdde6533b77fd5a037eae38ca5d2a *tests/dnns.R
......
......@@ -3,3 +3,5 @@ S3method(asub, default)
S3method(adrop, default)
S3method("afill<-", default)
S3method(acorn, default)
importFrom("methods", "Quote")
importFrom("utils", "head", "object.size", "tail")
adrop <- function(x, drop=TRUE, named.vector=TRUE, one.d.array=FALSE) UseMethod("adrop", x)
adrop <- function(x, drop=TRUE, named.vector=TRUE, one.d.array=FALSE, ...) UseMethod("adrop")
adrop.default <- function(x, drop=TRUE, named.vector=TRUE, one.d.array=FALSE) {
adrop.default <- function(x, drop=TRUE, named.vector=TRUE, one.d.array=FALSE, ...) {
if (is.null(dim(x)))
stop("require an object with a dim attribute")
if (length(list(...)))
if (length(names(list(...))))
stop('have unrecognized ... arguments for adrop.default: ', paste(names(list(...)), collapse=', '))
else
stop('have unrecognized unnamed ... arguments for adrop.default')
x.dim <- dim(x)
if (is.logical(drop)) {
if (length(drop) != length(x.dim))
......
......@@ -43,7 +43,8 @@
# Now we can work with evaluated dot args.
# Can't do dot.args <- list(...) because that will
# stop with an error for missing args.
dot.args <- mapply(dot.args.uneval, missing.dot.args, FUN=function(arg, m) if (!m) eval(arg) else NULL)
par.frame <- parent.frame()
dot.args <- mapply(dot.args.uneval, missing.dot.args, FUN=function(arg, m) if (!m) eval(arg, par.frame) else NULL)
# construct the numeric indices
idxs <- vector("list", length(x.d))
strip.excess <- FALSE
......
asub <- function(x, idx, dims=seq(len=max(length(dim(x)), 1)), drop=NULL) UseMethod("asub")
asub.default <- function(x, idx, dims=seq(len=max(length(dim(x)), 1)), drop=NULL) {
asub <- function(x, idx, dims=seq(len=max(length(dim(x)), 1)), drop=NULL, ...) UseMethod("asub")
asub.default <- function(x, idx, dims=seq(len=max(length(dim(x)), 1)), drop=NULL, ...) {
# Do arbitrary indexing of x as positions in dims
if (length(dims)>1 && !is.list(idx))
stop("idx must be a list when length dims>1")
if (length(list(...)))
if (length(names(list(...))))
stop('have unrecognized ... arguments for asub.default: ', paste(names(list(...)), collapse=', '))
else
stop('have unrecognized unnamed ... arguments for asub.default')
if (!is.list(idx))
idx <- list(idx)
if (length(idx) != length(dims))
......
......@@ -10,7 +10,7 @@
supplied in the \code{abind} package.
}
\usage{
adrop(x, drop = TRUE, named.vector = TRUE, one.d.array = FALSE)
adrop(x, drop = TRUE, named.vector = TRUE, one.d.array = FALSE, ...)
}
\arguments{
......@@ -28,6 +28,8 @@ adrop(x, drop = TRUE, named.vector = TRUE, one.d.array = FALSE)
length 1, and possibly a \code{dimnames} attribute. If
\code{FALSE}, a one-dimensional result will be a vector object
(named if \code{named.vector==TRUE}).}
\item{...}{There are no additional arguments allowed for
\code{adrop.default} but other methods may use them.}
}
\details{
Dimensions can only be dropped if their extent is one, i.e., dimension
......
......@@ -7,7 +7,7 @@ Subset array-like objects at specified indices. \code{asub()} is a S3 generic,
one method, \code{asub.default}, supplied in the \code{abind} package.
}
\usage{
asub(x, idx, dims = seq(len = max(length(dim(x)), 1)), drop = NULL)
asub(x, idx, dims = seq(len = max(length(dim(x)), 1)), drop = NULL, ...)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
......@@ -15,11 +15,13 @@ asub(x, idx, dims = seq(len = max(length(dim(x)), 1)), drop = NULL)
\item{idx}{ A list of indices (e.g., a list of a mixture of integer,
character, and logical vectors, but can actually be anything). Can
be just a vector in the case that \code{length(dims)==1}.
\code{NULL} entries in the list will be treated as empty indices.}
\code{NULL} entries in the list will be treated as empty indices.}
\item{dims}{ The dimensions on which to index (a numeric or integer
vector). The default is all of the dimensions. }
\item{drop}{ The 'drop' argument to index with (the default is to not
supply a 'drop' argument }
\item{...}{There are no additional arguments allowed for
\code{asub.default} but other methods may use them.}
}
\details{
Constructs and evaluates an expression to do the requested indexing.
......
......@@ -80,3 +80,20 @@ x
# return value is the part of x that is assigned to
(afill(x) <- c(B=1,C=2))
(x[2:3] <- 0)
# test using a variable on the LHS
x <- cbind(X=c(a=1,b=2),Y=3:4)
x
afill(x, 1, ) <- c(Y=5)
x
afill(x, 1, ) <- c(X=6)
x
afill(x, 2, ) <- c(Y=7)
afill(x, 2, ) <- c(X=8)
x
i <- 1
afill(x, i, ) <- c(X=1)
x
i <- 2
afill(x, i, ) <- c(Y=2)
x
......@@ -33,7 +33,7 @@ B 2 4 6
w x y
A 1 3 5
B 2 4 6
>
>
> # now do it with afill()
> x[] <- 0
> afill(x, TRUE, , ) <- matrix(1:6,ncol=3, dimnames=list(c("A","B"),c("w","x","y")))
......@@ -58,9 +58,9 @@ A 1 3 5
B 2 4 6
> table(x==0)
FALSE TRUE
12 12
>
FALSE TRUE
12 12
>
> # 4-d example
> x <- array(0, dim=c(2,3,3,4),dimnames=list(letters[1:2],LETTERS[1:3],letters[24:26],LETTERS[23:26]))
> x[1,c("A","B"),1,c("W","X","Y")] <- 1:6
......@@ -73,7 +73,7 @@ FALSE TRUE
[1] 1 1 2 2 1 1 2 2 1 1 2 2 3 3 4 4 3 3 4 4 3 3 4 4 5 5 6 6 5 5 6 6 5 5 6 6
> c(matrix(1:6, ncol=3)[rep(1:2, each=2),rep(1:3,each=3)])
[1] 1 1 2 2 1 1 2 2 1 1 2 2 3 3 4 4 3 3 4 4 3 3 4 4 5 5 6 6 5 5 6 6 5 5 6 6
>
>
> afill(x, T, , T, ) <- matrix(1:6,ncol=3, dimnames=list(c("A","B"),c("W","X","Y")))
> x[1,c("A","B"),1,c("W","X","Y")]
W X Y
......@@ -101,9 +101,9 @@ A 1 3 5
B 2 4 6
> table(x==0)
FALSE TRUE
36 36
>
FALSE TRUE
36 36
>
> # 2-d example
> x <- array(1:24, dim=c(6,4), dimnames=list(LETTERS[1:6], letters[23:26]))
> x1 <- x
......@@ -140,7 +140,7 @@ F 6 12 18 24
[1] TRUE
> x2 <- x
> afill(x2) <- array(-(1:6),dim=c(3,2), dimnames=list(LETTERS[5:7],letters[24:25]))
Error in `afill<-.default`(`*tmp*`, value = c(-1L, -2L, -3L, -4L, -5L, :
Error in `afill<-.default`(`*tmp*`, value = c(-1L, -2L, -3L, -4L, -5L, :
value has dimnames that are not in 'x' on dim[1]: 'G'
Calls: afill<- -> afill<-.default
> x2 <- x
......@@ -163,17 +163,52 @@ C 3 -2 -5 21
D 4 -3 -6 22
E 5 11 17 23
F 6 12 18 24
>
>
> # 1-d named-vector example
> x <- c(A=0,B=0,C=0,D=0)
> afill(x) <- c(B=1,C=2)
> x
A B C D
0 1 2 0
A B C D
0 1 2 0
> # return value is the part of x that is assigned to
> (afill(x) <- c(B=1,C=2))
B C
1 2
B C
1 2
> (x[2:3] <- 0)
[1] 0
>
>
> # test using a variable on the LHS
> x <- cbind(X=c(a=1,b=2),Y=3:4)
> x
X Y
a 1 3
b 2 4
> afill(x, 1, ) <- c(Y=5)
> x
X Y
a 1 5
b 2 4
> afill(x, 1, ) <- c(X=6)
> x
X Y
a 6 5
b 2 4
> afill(x, 2, ) <- c(Y=7)
> afill(x, 2, ) <- c(X=8)
> x
X Y
a 6 5
b 8 7
> i <- 1
> afill(x, i, ) <- c(X=1)
> x
X Y
a 1 5
b 8 7
> i <- 2
> afill(x, i, ) <- c(Y=2)
> x
X Y
a 1 5
b 8 2
>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment