-
Notifications
You must be signed in to change notification settings - Fork 3
RS-18683: Keep span attributes and some fixes for multiple stats #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ac6ff2a
3de769f
b348da3
cc196ed
edde0da
a5d4241
4295e67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -505,6 +505,8 @@ PrepareData <- function(chart.type, | |
| ########################################################################### | ||
|
|
||
|
|
||
| if (!inherits(data, "QTable") && !is.null(attr(data, "span"))) | ||
| attr(data, "span") <- NULL | ||
| if (tidy.labels) | ||
| data <- tidyLabels(data, chart.type) | ||
| if (isScatter(chart.type)) # to remove span NETS | ||
|
|
@@ -553,9 +555,10 @@ PrepareData <- function(chart.type, | |
| if (chart.type == "Table" && !is.null(attr(data, "statistic")) && | ||
| (is.null(dim(data)) || length(dim(data)) == 1)) | ||
| { | ||
| tmp <- attr(data, "statistic") | ||
| data <- as.matrix(data) | ||
| attr(data, "statistic") <- tmp | ||
| is.qtable <- inherits(data, "QTable") | ||
| data <- CopyAttributes(as.matrix(data), data) | ||
|
jrwishart marked this conversation as resolved.
|
||
| if (is.qtable) | ||
| class(data) <- c(class(data), "QTable") | ||
| } | ||
|
|
||
| # Modify multi-stat QTables so they are 3 dimensional arrays | ||
|
|
@@ -1076,7 +1079,7 @@ processInputData <- function(x, subset, weights) | |
| # Try to use S3 method to extract data | ||
| x <- ExtractChartData(x) | ||
| n.dim <- length(dim(x)) - isQTableWithMultStatistic(x) | ||
| if (n.dim >= 2) | ||
| if (n.dim > 2) | ||
| x <- FlattenQTable(x) | ||
|
|
||
| if (hasUserSuppliedRownames(x)) | ||
|
|
@@ -1395,12 +1398,36 @@ transformTable <- function(data, | |
| # hide.rows.threshold and row.names.to.remove refer to rows AFTER tranposing | ||
| if (isTRUE(transpose)) | ||
| { | ||
| if (length(dim(data)) > 2) | ||
| if (!is.null(attr(data, "questions")) && length(dim(data)) == 2 && is.null(attr(data, "statistic"))) | ||
| { | ||
| # 1-dimensional table with multiple statistics | ||
| 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") | ||
|
jrwishart marked this conversation as resolved.
|
||
| if (!is.null(old.span)) | ||
| attr(data, "span") <- list(rows = old.span$columns, columns = old.span$rows) | ||
|
jrwishart marked this conversation as resolved.
|
||
|
|
||
| } 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")) | ||
|
Comment on lines
+1404
to
+1429
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This operation makes me a bit nervious. In most of this code block if input is a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do notice on a second viewing that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely sure what your example is trying to show. But CopyAttributes has by default |
||
| } | ||
| } | ||
|
|
||
| # Checking sample sizes (if available) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)