Fix. Account for the "data_array" property of the "values" attribute of the "dimensions" attribute. Closes #2385#2387
Open
trekonom wants to merge 3 commits intoplotly:masterfrom
Open
Fix. Account for the "data_array" property of the "values" attribute of the "dimensions" attribute. Closes #2385#2387trekonom wants to merge 3 commits intoplotly:masterfrom
trekonom wants to merge 3 commits intoplotly:masterfrom
Conversation
…e data_array propery of the "values" attribute. Closes plotly#2385. * Add tests to check that "values" property has class "AsIs" for "parcoords", "parcats" and "splom" traces. * Add NEWS entry
cpsievert
reviewed
Sep 3, 2024
R/utils.R
Outdated
| proposed[[attr]] <- verify_attr(proposed[[attr]], attrSchema, layoutAttr = layoutAttr) | ||
| # The "dimensions" attribute requires a special treatment as | ||
| # it is an unnamed list and hence will be skipped by `for (attr in names(proposed)) | ||
| if (attr == "dimensions") { |
Collaborator
There was a problem hiding this comment.
Seems there is actually a more general problem here that's beyond just dimensions. Some attributes say role: object, but are actually expecting a list of objects. Here is the schema for both dimensions and transforms:
So, I think this code should be closer to:
if (identical(role, "object") && is.recursive(proposed[[attr]])) {
# Some attributes (e.g., dimensions, transforms) are actually
# a list of objects (even though they, confusingly, have role: object)
# In those cases, we actually want to verify each list element
attr_ <- sub("s$", "", attr)
is_list_attr <- ("items" %in% names(attrSchema)) &&
(attr_ %in% names(attrSchema$items))
if (is_list_attr) {
proposed[[attr]] <- lapply(proposed[[attr]], function(x) {
verify_attr(x, attrSchema$items[[attr_]])
})
} else {
proposed[[attr]] <- verify_attr(proposed[[attr]], attrSchema, layoutAttr = layoutAttr)
}
}
Contributor
Author
There was a problem hiding this comment.
Thx for the review and the suggestions. Just added and comitted.
cpsievert
reviewed
Sep 3, 2024
R/utils.R
Outdated
Comment on lines
556
to
557
| if (attr == "dimensions") { | ||
| proposed[[attr]] <- lapply(proposed[[attr]], \(x) { |
Collaborator
There was a problem hiding this comment.
\(x) was added fairly recently to R, so please use function(x) instead
Contributor
Author
There was a problem hiding this comment.
🙈 Thanks for the reminder. Should have thought of that myself.
cpsievert
reviewed
Sep 3, 2024
Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR proposes a fix to account for the "data_array" property of the "values" attribute of the "dimensions" attribute used in special traces like "parcoords", "parcats" and "splom" traces thereby closing #2385.
Currently, when an attribute has the "data_array" attribute it gets wrapped in
AsIsinsideverify_attr. However, this check gets skipped for thedimensionsattribute as it is an unnamed list. Additionally, the schema specs for thevaluesattribute are somewhat nested.To account for that the PR adds some special treatment for
dimensionsattribute toverify_attrwhich useslapplyto loop over the items of thedimensionslist.With the proposed fix the examples documented in #2385 work fine, e.g. for
"parcats":Created on 2024-08-31 with reprex v2.1.1