I am looking for a way to check if a given instance of R6
class is present in a vector of R6
class instances.
library(R6)
# define a class
Person <- R6Class("Person", list(
name = NULL,
initialize = function(name) self$name <- name
))
# create two instances of a class
Jack <- Person$new(name = "Jack")
Jill <- Person$new(name = "Jill")
I naively used %in%
to check this, and it seems to have worked:
# yes
c(Jack) %in% c(Jack, Jill)
#> [1] TRUE
But it actually returns TRUE
no matter the instance:
# also yes
c(Jack) %in% c(Jill)
#> [1] TRUE
So I had two questions:
- What is
%in%
actually matching that it always returnsTRUE
? - How can I correctly check if an instance of
R6
class is present in a vector of class instances?