Conversation
|
|
||
|
|
||
| if (!inherits(data, "QTable") && !is.null(attr(data, "span"))) | ||
| attr(data, "span") <- NULL |
There was a problem hiding this comment.
Add additional check here because it is fairly easy to generate a hardship error with a span attribute if it is not subscripted properly (which usually does occur because NETs are removed by default)
| is.qtable <- inherits(data, "QTable") | ||
| old.span <- attr(data, "span", exact = TRUE) | ||
| new.data <- array(data, dim = c(1, nrow(data), ncol(data)), dimnames = list("", rownames(data), colnames(data))) | ||
| data <- CopyAttributes(new.data, data) | ||
| if (is.qtable) | ||
| class(data) <- c(class(data), "QTable") | ||
| if (!is.null(old.span)) | ||
| attr(data, "span") <- list(rows = old.span$columns, columns = old.span$rows) | ||
|
|
||
| } else if (length(dim(data)) > 2) | ||
| { | ||
| # 2-dimensional table with multiple statistics | ||
| is.qtable <- inherits(data, "QTable") | ||
| old.span <- attr(data, "span", exact = TRUE) | ||
| new.data <- aperm(data, c(2, 1, 3)) | ||
| else | ||
| new.data <- t(data) | ||
| data <- CopyAttributes(new.data, data) | ||
| attr(data, "questions") <- rev(attr(data, "questions")) | ||
| data <- CopyAttributes(new.data, data) | ||
| if (is.qtable) | ||
| class(data) <- c(class(data), "QTable") | ||
| attr(data, "questions") <- rev(attr(data, "questions")) | ||
| if (!is.null(old.span)) | ||
| attr(data, "span") <- list(rows = old.span$columns, columns = old.span$rows) | ||
| } else { | ||
| # Attributes handled by verbs (for QTables) | ||
| data <- t(data) | ||
| if (!inherits(data, "QTable")) | ||
| attr(data, "questions") <- rev(attr(data, "questions")) |
There was a problem hiding this comment.
This operation makes me a bit nervious. In most of this code block if input is a QTable, the data is restructured however the QTable class is retained. So subscripting will still call the QTable subscript? Or is this safe to do here? I fear this will break subscripting?
There was a problem hiding this comment.
I do notice on a second viewing that data <- CopyAttributes(new.data, data) was already there. So the QTable attributes would've been copied. This might be safe to do here? I can't recall where in the workflow this operation occurs. Does this occur after the statistics testing information has been extracted? And also after the subscripting (removal of rows/columns?)
There was a problem hiding this comment.
Yes, I tried this in Displayr with my ad hoc R server. In all 3 cases the output is still an array. The operation is a transpose, so its actually safer than subscripting because it never drops any dimensions.
There was a problem hiding this comment.
I was more concerned with reshaping the data but keeping the attributes. The subscripting relies on attributes heavily and might do the wrong operation on the reshaped data. e.g.
new.data <- array(data, dim = c(1, nrow(data), ncol(data)), dimnames = list("", rownames(data), colnames(data)))
data <- CopyAttributes(new.data, data)
There was a problem hiding this comment.
I'm not entirely sure what your example is trying to show. But CopyAttributes has by default attr.to.not.copy = c("dimnames", "names", "row.names", "dim", "class", "levels")
This PR is a repeat of #61 but the includes some additional fixes for tables with multiple statistics. They are included here instead of verbs because verbs explicitly does not handle 3d-arrays. Also, for the tidy tables work we are currently working on, we are treating the multiple statistics in the 1-d table with multiple stats like any other column, and flattening multiple statistics