Skip to content

Reconsider dcdim default behaviour #17

@psolymos

Description

@psolymos

Array works fine:

r$> ## array
    x <- dcdim(array(1:6, c(2, 3, 1)))

r$> x1 <- dclone(x, 1)

r$> x2 <- dclone(x, 2)

r$> x
, , 1

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

attr(,"drop")
[1] TRUE
attr(,"class")
[1] "dcdim" "array"

r$> x1
, , 1

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

attr(,"drop")
[1] TRUE
attr(,"class")
[1] "dcdim" "array"

r$> x2
, , clone.1

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

, , clone.2

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

attr(,"n.clones")
[1] 2
attr(,"n.clones")attr(,"method")
[1] "dim"
attr(,"n.clones")attr(,"method")attr(,"drop")
[1] TRUE

r$> stopifnot(all(dim(x1) == dim(x)))

r$> stopifnot(all(dim(x2) == dim(x)*c(1,1,2)))

Should the matrix case add a 3rd dim when k=1?

r$> ## matrix
    x <- dcdim(matrix(1:6, 2, 3))

r$> x1 <- dclone(x, 1)

r$> x2 <- dclone(x, 2)

r$> x
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
attr(,"drop")
[1] TRUE
attr(,"class")
[1] "dcdim"  "matrix" "array" 

r$> x1
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
attr(,"drop")
[1] TRUE
attr(,"class")
[1] "dcdim"  "matrix" "array" 

r$> x2
, , clone.1

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

, , clone.2

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

attr(,"n.clones")
[1] 2
attr(,"n.clones")attr(,"method")
[1] "dim"
attr(,"n.clones")attr(,"method")attr(,"drop")
[1] TRUE

r$> stopifnot(all(dim(x1) == dim(x)))

r$> stopifnot(all(dim(x2) == dim(x)*c(1,2)))
Error: all(dim(x2) == dim(x) * c(1, 2)) is not TRUE
In addition: Warning message:
In dim(x2) == dim(x) * c(1, 2) :
  longer object length is not a multiple of shorter object length

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions