Re: [Rd] How x[, 'colname1'] is implemented?

From: Peng Yu <pengyu.ut_at_gmail.com>
Date: Fri, 01 Jan 2010 15:40:59 -0600

On Fri, Jan 1, 2010 at 6:52 AM, Barry Rowlingson <b.rowlingson_at_lancaster.ac.uk> wrote:
> On Thu, Dec 31, 2009 at 11:27 PM, Peng Yu <pengyu.ut_at_gmail.com> wrote:
>> I don't see where describes the implementation of '[]'.
>>
>> For example, if x is a matrix or a data.frame, how the lookup of
>> 'colname1' is x[, 'colname1'] executed. Does R perform a lookup in the
>> a hash of the colnames? Is the reference O(1) or O(n), where n is the
>> second dim of x?
>
>  Where have you looked? I doubt this kind of implementation detail is
> in the .Rd documentation since a regular user doesn't care for it.

I'm not complaining that it is not documented.

>  As Obi-wan Kenobi may have said in Star Wars: "Use the source, Luke!":
>
>  Line 450 of subscript.c of the source code of R 2.10 is the
> stringSubscript function. It has this comment:
>
> /* The original code (pre 2.0.0) used a ns x nx loop that was too
>  * slow.  So now we hash.  Hashing is expensive on memory (up to 32nx
>  * bytes) so it is only worth doing if ns * nx is large.  If nx is
>  * large, then it will be too slow unless ns is very small.
>  */

Could you explain what ns and nx represent?

> The definition of "large" and "small" here appears to be such that:
>
> 457: Rboolean usehashing = in && ( ((ns > 1000 && nx) || (nx > 1000 &&
> ns)) || (ns * nx > 15*nx + ns) );



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 01 Jan 2010 - 21:46:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 02 Jan 2010 - 13:50:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive