[R] Fatal Error R
Matt Shotwell
shotwelm at musc.edu
Wed Nov 17 15:26:34 CET 2010
Please see below.
On Wed, 2010-11-17 at 04:41 -0500, Ted Harding wrote:
> On 17-Nov-10 00:02:39, José Fernando Zea Castro wrote:
> > 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
> >> b$q9
> > [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
>
> 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.
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 ?`[`).
> 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!
Indexing a list using [[ and a string enforce exact matching (by
default). Continuing with the example above:
> b[["q99"]]
[1] 1 2 3
> b[["q"]]
NULL
> 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 ------------------------------
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Matthew S. Shotwell
Graduate Student
Division of Biostatistics and Epidemiology
Medical University of South Carolina
More information about the R-help
mailing list