You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: more lenient check_nondata_cols #3835
The reason I would like it to be more lenient is such that vector-like columns which technically aren't vectors could be accepted, specifically for the virtual S4Vectors::Vector-class (and non-virtual classes containing this). This would open up channels to have Bioconductor work with ggplot2 more naturally, provided some extra infrastructure is implemented at the scale/coordinate level (which could befit a ggplot extention package).
I would propose to change check_nondata_cols to the following:
I don't think the intend was ever to exclude meaningful data columns. This was just to filter out nonsensical things, such as functions.
However, the question is why rlang::is_vector(x) fails. Maybe it requires modification? Could you provide a simple reprex where you create an object of a type that would fail the check but can be reasonably considered as a vector?
I think rlang::is_vector() (and also base::is.vector()) always return FALSE for many bioconductor S4 classes since their internal representation is not as a vector but most relevant data is stored in slots, akin to S3 attributes, that often behave in a parallel way to vectors.
Below is a minimal reprex, keep in mind though that the Bioconductor S4 Vector virtual class actually has methods that make it behave the way vectors behave, while this reprex does not.
Below is a more realistic reprex for two actual bioconductor classes that behave near identical to vectors.
# BiocManager::install("S4Vectors")
suppressPackageStartupMessages(library(S4Vectors))
library(ggplot2)
# Factor is a class wherein levels can be pretty much anythingx<- Factor(levels=complex(real=1:5, imaginary=5:1), index=1:3)
# Rle is a run length encoded Vector that behaves like a vector, # in contrast to base::rley<- Rle(rep(1:5, 5:1))
# They fail the non-data column checkggplot2:::check_nondata_cols(list(x=x, y=y))
#> [1] "x" "y"
The Rle and Factor classes have length(), subsetting, subassignment, concatenation and most of the usual behaviour you'd expect from an vector, it is just the internal representation that is different.
Ok. In this case, if inherits(x, "Vector") captures a large proportion of the data types that might likely have this feature, I think explicitly allowing it is the right strategy. Do you want to prepare a PR? Just make sure you document it so we understand in the future what this check is there for.
Yes, most S4 data classes in Bioconductor I know of probably inherit from Vector in one way or another.
A small complication likely lies in discriminating linear vectors from rectangular 'vectors' (such as S4Vectors::DataFrame), so I'd suppose the check would have to be
Are rectangular vectors a problem? We've talked about allowing data frame columns, and this wouldn't be any different I think. No need to ensure dim is NULL.
I don't necessarily think they are problematic. Just to check: data.frame columns are okay then? Out of curiosity, could you point me to the relevant conversation? (so I might glimpse an example)
Activity
clauswilke commentedon Feb 25, 2020
I don't think the intend was ever to exclude meaningful data columns. This was just to filter out nonsensical things, such as functions.
However, the question is why
rlang::is_vector(x)fails. Maybe it requires modification? Could you provide a simple reprex where you create an object of a type that would fail the check but can be reasonably considered as a vector?teunbrand commentedon Feb 25, 2020
I think
rlang::is_vector()(and alsobase::is.vector()) always returnFALSEfor many bioconductor S4 classes since their internal representation is not as a vector but most relevant data is stored in slots, akin to S3 attributes, that often behave in a parallel way to vectors.Below is a minimal reprex, keep in mind though that the Bioconductor S4
Vectorvirtual class actually has methods that make it behave the way vectors behave, while this reprex does not.Created on 2020-02-25 by the reprex package (v0.3.0)
Below is a more realistic reprex for two actual bioconductor classes that behave near identical to vectors.
Created on 2020-02-25 by the reprex package (v0.3.0)
The
RleandFactorclasses havelength(), subsetting, subassignment, concatenation and most of the usual behaviour you'd expect from an vector, it is just the internal representation that is different.clauswilke commentedon Feb 25, 2020
Ok. In this case, if
inherits(x, "Vector")captures a large proportion of the data types that might likely have this feature, I think explicitly allowing it is the right strategy. Do you want to prepare a PR? Just make sure you document it so we understand in the future what this check is there for.teunbrand commentedon Feb 25, 2020
Yes, most S4 data classes in Bioconductor I know of probably inherit from
Vectorin one way or another.A small complication likely lies in discriminating linear vectors from rectangular 'vectors' (such as
S4Vectors::DataFrame), so I'd suppose the check would have to beI'll go start preparing a PR!
clauswilke commentedon Feb 25, 2020
Are rectangular vectors a problem? We've talked about allowing data frame columns, and this wouldn't be any different I think. No need to ensure
dimisNULL.teunbrand commentedon Feb 25, 2020
I don't necessarily think they are problematic. Just to check: data.frame columns are okay then? Out of curiosity, could you point me to the relevant conversation? (so I might glimpse an example)
clauswilke commentedon Feb 25, 2020
Yes, data frame columns are Ok:
Created on 2020-02-25 by the reprex package (v0.3.0)
All relevant conversations happen on Twitter: https://twitter.com/hadleywickham/status/1009674367624777728?s=20
Let check_nondata_cols allow Vector class (#3835) (#3837)
clauswilke commentedon Mar 8, 2020
Closed via #3837.
Merge pull request #8 from tidyverse/master