-
Notifications
You must be signed in to change notification settings - Fork 6
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
Incorrect subsetting with operator %in%
#99
Comments
%in%
%in%
Hmpf. That is a tough one. I do rely on base R's I wasn't aware we had dug ourselves a "potential problem" here. Oh well. |
Yes, note to self: "next time don't base an S4 type on an S3 type". I'm going to try to see what R is actually doing differently when a package imports another package in the DESCRIPTION file compared to when the user does it in the interpreter. |
It looks like any function that > methods("%in%")
[1] %in%.nanotime
see '?methods' for accessing help and source code
Warning message:
In .S3methods(generic.function, class, envir) :
function '%in%' appears not to be S3 generic; found functions that look like S3 methods
if (!exists("%in%.default")){
"%in%" <- function(x, table) UseMethod("%in%")
"%in%.default" <- function(x, table) base::"%in%"(x, table)
} If we put this in the
This warning also happens for |
Oh, that is gnarly. I had on occassion been bitten by |
Just thinking out loud here: would de-emphasizing |
We probably want to keep 1:10 %in% c(3, 5, 7)
[1] FALSE FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE FALSE Then it's semantically intuitive and correct as it is related to the notion of set: |
The > library(nanotime)
Loading required package: bit64
Loading required package: bit
Attaching package: ‘bit’
The following object is masked from ‘package:base’:
xor
Attaching package bit64
package:bit64 (c) 2011-2017 Jens Oehlschlaegel
creators: integer64 runif64 seq :
coercion: as.integer64 as.vector as.logical as.integer as.double as.character as.bitstring
logical operator: ! & | xor != == < <= >= >
arithmetic operator: + - * / %/% %% ^
math: sign abs sqrt log log2 log10
math: floor ceiling trunc round
querying: is.integer64 is.vector [is.atomic} [length] format print str
values: is.na is.nan is.finite is.infinite
aggregation: any all min max range sum prod
cumulation: diff cummin cummax cumsum cumprod
access: length<- [ [<- [[ [[<-
combine: c rep cbind rbind as.data.frame
WARNING don't use as subscripts
WARNING semantics differ from integer
for more help type ?bit64
Attaching package: ‘bit64’
The following objects are masked from ‘package:base’:
:, %in%, is.double, match, order, rank
> If we do the definition of |
Yes, still "bad" (I'd prefer no warning) but not as bad as the above. Have you seen what the tidyverse folks are doing with package PS: https://cran.r-project.org/package=generics and https://github.com/r-lib/generics |
Just looked at > library(generics)
Attaching package: ‘generics’
The following objects are masked from ‘package:nanotime’:
intersect, setdiff, union
The following objects are masked from ‘package:base’:
as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
setequal, union
> Another alternative would be to sever the tie with |
Rock, meet hard place. Just thinking out aloud: operators of the |
Don't know, in my mind it feels a little worse to define a new operator than to get a warning on package load, because the warning is not dangerous, but a new operator makes |
But int64 <-> double conversion are lossy (as casts). Or are you thinking "long term" and fully divorcing bit64? That seems to shoulder ... a lot of load! |
I am still troubled by
I truly dislike what happened with |
Yes, when defining an S3 method for a function implemented in "%in%" <- function(x, table) UseMethod("%in%") This tells R to use the S3 dispatch system instead of a straight call to the original function (hence the masking warning). The second step is to declare a default that will call the "%in%.default" <- function(x, table) base::"%in%"(x, table) So the first declaration tells R to dispatch on the type, so if it finds I don't think it's a major problem; in the S3 world this is simply unavoidable (and that's why we see so many packages display these masking warnings). For the |
Fixed in #100 |
Looks like some interference with
bit64
. We've seen that previously and have always been able to get around it by defining and exporting S3 methods. For some reason it does not work with%in%
. It passes the unit tests because it works when the package is test loaded, but it doesn't work straight out of the box.So this does not work:
But this works:
I have tried to fix this, but for the moment I haven't been successful with whatever type of export I've used in
NAMESPACE
. Will have to dig into this a bit more.The text was updated successfully, but these errors were encountered: