[R] The "Sets" package and element equality test
David Meyer
meyerd at technikum-wien.at
Sun Oct 9 00:17:40 CEST 2011
> By going through the code, I came to a similar conclusion also: it
> seems the match.2.list function must be modified in the following way
> to make it work:
>
> match.2.list <- function(l1,l2){
> if (class(l1)=="element"){
> l1 <- l1[[1]]
> l2 <- l2[[1]]
> }
> length(l1)==length(l2)
> }
>
> because depending whether it is called from the constructor or from
> the %e% function, the assumptions about the input types are not the same.
No, this is not not the problem, it's really the hashing code which
makes this fail. If you turn hashing off, then the original match.2.list
function will work as expected:
> sets_options("hash", FALSE)
> match.2.list <- function(l1,l2){
+ length(l1)==length(l2)
+ }
> s <- set(list(1,2),list(3,4))
> lset <- cset(s,matchfun = matchfun(match.2.list))
> lset
{<<list(2)>>}
> list(1,8) %e% lset
[1] TRUE
>
> And also, if instead of working with "standard" objects, I want to
> work with S4 / refClass objects, I cannot build cset objects, because
> I have to go first with the set construction which prompts an error:
Currently, S4 objects are not supported at all as set elements. I will
have a look on this.
Best
David
>
> Error in as.vector(x, "character") :
> cannot coerce type 'environment' to vector of type 'character'
>
>
> So far, I don't know how to work around this latter issue.
>
> Thanks again for the package and your help.
>
> Regards
>
> Johnny
>
>
>
>
> On Sat, Oct 8, 2011 at 2:40 PM, David Meyer <meyerd at technikum-wien.at
> <mailto:meyerd at technikum-wien.at>> wrote:
>
> Dear Johnny,
>
> this is a bug in the hashing-code of sets. Use:
>
>
> sets_options("hash", FALSE)
> lset <- cset(s, matchfun = matchfun(match.2.list))
>
> which will work.
>
> Thanks for pointing this out!
>
> David
>
> ----------------
>
> Hi,
>
> I tried to use the sets package yesterday, which seems to be a
> very powerful
> package: thanks to the developers. I wanted to define sets of
> lists where 2
> lists are considered equal if they have the same length.
> So, I implemented:
>
> match.2.list <- function(l1,l2){
> length(l1)==length(l2)
> }
>
> and then defined my cset as:
>
> s <- set(list(1,2),list(3,4))
> lset <- cset(s,matchfun(match.2.list))
>
> so if I now do:
> y <- list(3,4)
> y %e% lset
>
> I get the correct answer, which is TRUE.
>
> But if I do:
> x <- list(1,8)
> x %e% lset
>
> I now get FALSE, even though x is a list of length 2, and should
> thus match
> any of the 2 lists in lset.
>
> I must be doing something wrong; I checked with the doc, but I don't
> understand.
>
> --
> Priv.-Doz. Dr. David Meyer
> Institut für Wirtschaftsinformatik
>
> Fachhochschule Technikum Wien
> Höchstädtplatz 5, 1200 Wien
> T: +43 1 333 40 77-394 <tel:%2B43%201%20333%2040%2077-394>
> F: +43 1 333 40 77-99 394 <tel:%2B43%201%20333%2040%2077-99%20394>
> E: david.meyer at technikum-wien.at
> <mailto:david.meyer at technikum-wien.at>
> I: www.technikum-wien.at <http://www.technikum-wien.at>
>
>
--
Priv.-Doz. Dr. David Meyer
Institut für Wirtschaftsinformatik
Fachhochschule Technikum Wien
Höchstädtplatz 5, 1200 Wien
T: +43 1 333 40 77-394
F: +43 1 333 40 77-99 394
E: david.meyer at technikum-wien.at
I: www.technikum-wien.at
More information about the R-help
mailing list