[Rd] if does not covert raw to logical (PR#13630)

maechler at stat.math.ethz.ch maechler at stat.math.ethz.ch
Mon Mar 30 18:55:29 CEST 2009


Thank you, Wacek,
for

>>>>> Wacek Kusnierczyk <waku at idi.ntnu.no>
>>>>>     on Sun, 29 Mar 2009 22:40:11 +0200 (CEST) writes:

    > Full_Name: Wacek Kusnierczyk
    > Version: 2.8.0 and 2.10.0 r48242
    > OS: Ubuntu 8.04 Linux 32 bit
    > Submission from: (NULL) (80.202.30.36)


    > The following raises an error:

    > if (as.raw(1)) 1
    > # error: unimplemented type 'raw' in 'asLogical'

    > However, ?'if' says:

    > " 
    > Arguments:

    > cond: A length-one logical vector that is not 'NA'. Conditions of
    > length greater than one are accepted with a warning, but only
    > the first element is used.  Other types are coerced to
    > logical if possible, ignoring any class. 
    > "

    > and the help page does not mention raw type arguments to 'if' at all. 

    > The error above is in clear contradiction to the documentation.  This might be a
    > flaw in the documentation, but the following succeeds:

    > ifelse(raw(1), 1, 0)
    > # 1

    > which suggests that the error above is a bug (i.e., the implementation fails to
    > convert raw to logical).

    > The same problem involves 'while':

    > while(as.raw(1)) break
    > # error: unimplemented type 'raw' in 'asLogical'

indeed, it was pretty straightforward hard to implement the missing case in
asLogical(.) and I will commit my patch to the sources tomorrow
{being busy otherwise for the rest of today}.

Note that  the  raw data type has been a newish addition to R a
while ago though,  and if you find further cases where
such raw objects do not "work" as documented,
we'd gladly accept further such reports.

Regards,
Martin Maechler, ETH Zurich



More information about the R-devel mailing list