From skostysh at princeton.edu  Wed Apr 30 21:36:02 2014
From: skostysh at princeton.edu (Scott Kostyshak)
Date: Wed, 30 Apr 2014 15:36:02 -0400
Subject: [Rd] "Name partially matched in data frame"
In-Reply-To: <CAE3=dmcbsbKMa87GVzZ3Gykdo-Cf_f4wHb=SOdmyqr0tL8uxcg@mail.gmail.com>
References: <3781BDEC-E7D2-482A-A7A7-63B61B021754@plessthan.com>
	<CAE3=dmcbsbKMa87GVzZ3Gykdo-Cf_f4wHb=SOdmyqr0tL8uxcg@mail.gmail.com>
Message-ID: <CAE3=dmfrtEKmbiM0DSZ2zx2oVRHRYeAHZt8F1YLHjp5oF73U8w@mail.gmail.com>

On Wed, Apr 30, 2014 at 3:33 PM, Scott Kostyshak <skostysh at princeton.edu> wrote:
> Hi Dennis,
>
> On Wed, Apr 30, 2014 at 3:03 PM, Fisher Dennis <fisher at plessthan.com> wrote:
>> R 3.1.0
>> OS X
>>
>> Colleagues,
>>
>> I recently updated to 3.1.0 and I have encountered
>>         Warning messages: ...  Name partially matched in data frame
>> when I do something like:
>>         DATAFRAME$colname
>> where colname is actually something longer than that (but unambiguous).
>>
>> I have much appreciated the partial matching capabilities because it fits with my workflow.  I often receive updated data months after the initial code is written.  In order to keep track of what I did in the past, I provide lengthy (unambiguous) names for columns, then abbreviate the names as I call them.  This behavior has been termed ?lazy? in various correspondence on this mailing list but it works for me and probably works for others.
>
> Why not store that information elsewhere? e.g. in an attribute?
>
>> I realize that the new message is only a warning but it is a minor nuisance.  Would it be possible to add an
>>         option(partialMatch=TRUE)       ## default is FALSE
>> or something similar to suppress that behavior?  That should keep both camps happy.
>
> There is currently no option to control that behavior and (although I
> do understand your use case) I personally hope one is not implemented.
> The reason is that you might put that option in your .Rprofile and
> when you share your code with me I get errors that columns aren't
> found.

Let me change this to "I would get warnings, which would make me worried."

> You can of course redefine the `$`:
>
>> dataf <- data.frame(longColumn = 5)
>> dataf$long
> [1] 5
> Warning message:
> In `$.data.frame`(dataf, long) : Name partially matched in data frame
>>
>> `$.data.frame` <-
> + function (x, name)
> + {
> +     a <- x[[name]]
> +     if (!is.null(a))
> +         return(a)
> +     a <- x[[name, exact = FALSE]]
> +     return(a)
> + }
>>
>> dataf$long
> [1] 5
>>
>
> I hope you don't do that though.
>
> Another option is to use the more verbose dataf[["long", exact = FALSE]].
>
> Scott
>
>
> --
> Scott Kostyshak
> Economics PhD Candidate
> Princeton University

Scott


--
Scott Kostyshak
Economics PhD Candidate
Princeton University



[Rd] "Name partially matched in data frame"
Scott Kostyshak