Skip to content

Variable Wildcard Value

3 messages · Patrick Burns, Romain Francois, Wacek Kusnierczyk

#
I would be truly amazed if the answer were "yes".

I find this the most fascinating question on R-help
for a long time, maybe ever.  Can you tell us what
you have in mind and what your ultimate purpose is?

Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of "The R Inferno" and "A Guide for the Unwilling S User")
Francis Smart wrote:
#
Hi,

Since you insist, here is something that I think matches the 
specifications :

wildcard <- function( ) structure( NULL, class = "wildcard" )
Ops.wildcard <- function (e1, e2){
    if (nargs() == 1L)
        return( e1 )
    result <- switch(.Generic,
        `<` = , `>` = , `==` = ,
        `<=` = , `>=` = TRUE, `!=` = FALSE)
    result
}
is.na.wildcard <- function( x ) FALSE


 > w == 1
[1] TRUE
 > w == "peanut butter"
[1] TRUE
 > is.na( w )
[1] FALSE
 > "peanut butter" == w
[1] TRUE
 > w == w
[1] TRUE
 > w != w
[1] FALSE

# Is negation of a wildcard also a wildcard, or should it be a bizarro 
wildcard ?
 > (!w) == 2
[1] TRUE


Not really sure how this could be useful though, and would also be 
interested in Francis end game.

Romain
Patrick Burns wrote:

  
    
#
Patrick Burns wrote:
this seems a request for a 'match all' value, somewhat the inverse of NA
(~'match nothing').  i could think of this being useful when you want to
check for duplicates, and want to mark that some entries (e.g., the
unknown ones) are irrelevant for the comparison (i.e., they should match
everything):

    identical(c(1, NA), c(1, 2))
    # FALSE

    identical(c(1, NA), c(1, NA))
    # TRUE
    # confusing!

    # hypothetical
    identical(c(1, *), c(1, 2))
    # TRUE
    identical(c(1, *), c(1, NA))
    # TRUE

not sure about the last one, though, since the original post demanded
that is.na(*) == FALSE

i don't claim this would be useful in practice, just speculating.

vQ