Skip to content

Fatal Error R

5 messages · José Fernando Zea Castro, David Winsemius, Kenneth Cabrera +2 more

#
Hello.

First, I'm thankful about your wonderful project.

However, I have serious worries about the reliability of R. I found
the next bug which I consider important because in my job everytime We
work with datanames like next. Please see below:


 b=data.frame(matrix(1:9,ncol=3))
 names(b)=c("q99","r88","s77")

 >b
  q99 r88 s77
1   1   4   7
2   2   5   8
3   3   6   9
[1] 1 2 3


Please note that the variable q9 does not exist in the dataframe, but
you can see  that R
show q9 (as q99).

Thank in advanced


Cordially
Jos? Fernando Zea Castro
Statistician Universidad Nacional Colombiana
#
On Nov 16, 2010, at 7:02 PM, Jos? Fernando Zea Castro wrote:

            
Not only that but:
 > b$q
[1] 1 2 3
Read the section in ?Extract on "Character indices". The $ operator is  
weird in other ways as well. Better to use [[ ]] therefore.

  
    
#
As long as the names are unique, there is not a problem to shorten them.


El mi?, 17-11-2010 a las 01:02 +0100, Jos? Fernando Zea Castro escribi?:
#
On 17-Nov-10 00:02:39, Jos? Fernando Zea Castro wrote:
. but you can see  that R show q9 (as q99).
What you see here is a case of "partial matching": You ask for
'b$q9', and R sees that 'q9' matches the beginning of 'q99'
and nothing else. Therefore it responds with the value of 'b$q99',
since there is no ambiguity.

You would have got the same result if you had asked for

  b$q

since there is no component name in b which matches 'q' except 'q99'.

If there had been two components which matched 'q9', say both
b$q99 and b$q98, then you would have got a NULL result, since
there is not a unique match.

However, if you also have b$q9 and b$q99 in b, then R would find that
b$q9 was an *exact* (not partial) match, and would return that one.

Normally, this should not cause problems. However, if you have
written code which must take special action if a name is not
present in a list, then there could be problems.

For example, if b might (depending on what has happened) contain
b$q9 only, or b$q99 only, or *both* b$q9 and b$q99, and you want
to execute special actions if a name is not present in b, then
in the case where b contained only b$q99 and you asked for b$q9,
you would get the wrong result because of partial matching.

This is one of those cases, in my opinion, where R's documentation
drops you into a flat landscape, in the middle of nowhere, in a
thick mist. What is needed is to be able to set an option such
that R will *only* respond with exact matches, e.g. something
like options(partial.match=FALSE). I have spent about 20 minutes
trying to locate the possible existence of such an option, or a
similar way of suppressing partial matching. No success!

The closest I could get was the set of options, settable using
options(... = ...):

     'warnPartialMatchArgs': logical.  If true, warns if partial
          matching is used in argument matching.

     'warnPartialMatchAttr': logical.  If true, warns if partial
          matching is used in extracting attributes via 'attr'.

     'warnPartialMatchDollar': logical.  If true, warns if partial
          matching is used for extraction by '$'.

which concerns only the issue of warnings in such cases, and has
nothing to do with suppressing partial matching.

Maybe others know better!

Best wishes,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 17-Nov-10                                       Time: 09:41:03
------------------------------ XFMail ------------------------------
#
Please see below.
On Wed, 2010-11-17 at 04:41 -0500, Ted Harding wrote:
This does happen sometimes, but partial matching in indexing operations
is documented in the R Language Definition manual section 3.4.1, and
well documented in the help page (?Extract or ?`$` or ?`[`).
Indexing a list using [[ and a string enforce exact matching (by
default). Continuing with the example above:
[1] 1 2 3
NULL