<div dir="ltr">Thanks Arun, the examples you give are probably interesting in their own right, but your post doesn't address advantages/disadvantages of either current or proposed syntaxes and simply points out the (obvious) fact that current (and other, similar in some ways to current) behavior is possible to implement in R.</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Apr 27, 2013 at 10:49 AM, Arunkumar Srinivasan <span dir="ltr"><<a href="mailto:aragorn168b@gmail.com" target="_blank">aragorn168b@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="h5">Hello, <br>I thought I'd also chip-in my thoughts to eddi's feature request. <br>
Short answer: I don't think this feature is necessary. I basically agree with mnel's reply. <br>Long answer: My argument goes along these lines (in addition to the S3/S4 methods mnel mentions). If you for example type `[.data.frame` in your R-session, you'd see this snippet:<br>
<br> if (is.matrix(i)) <br> return(as.matrix(x)[i])<br><br>That is, if you do: <br><br> df <- data.frame(x=1:5, y=1:5, z=1:5)<br> mm <- matrix(1:12, ncol=3)<br> df[mm] # gives<br> <a href="tel:%5B1%5D%201%202%203%204%205%201%202%203%204%205%201" value="+12345123451" target="_blank">[1] 1 2 3 4 5 1 2 3 4 5 1</a> 2<br>
<br> df <- data.frame(x=1:2, y=1:2, z=1:2)<br> df[mm] # gives<br> [1] 1 2 1 2 1 2 NA NA NA NA NA NA<br><br>Here, the indexing is a matrix. It's obvious. Now, should this behaviour be changed because people would be confused that subsetting a data.frame resulted in a vector? Or because it's not user friendly? Even better, try out `df[mm, ]`. If `i` is a matrix, this is what the code does. I am not convinced this is "bad" design. Functions take arguments of different types ALL the time and they return outputs *depending on the type of input*. This is why I am not sold on the point of "bad design". It's essential to know the type of objects `i` can take and *understand* it. <br>
<br>If a function is designed that takes several types of objects for `i` and their behaviour is documented, and the documented behaviour is consistent, then I can't accept there's a problem. <br><br>I agree there are people who don't read the manual and "try" things out. But they are going to have problems with every other function in R. <br>
<br>For example, "unstack" is a function for which same input type gives different output type. That is, it provides a data.frame if the columns are equal after unstaking and list if they are not. That is, compare the outputs of:<br>
<br> df <- data.frame(x=rep(1:3, each=3), y=1:9)<br> unstack(df, y ~ x)<br><br>with<br><br> df <- data.frame(x=c(rep(1:3, each=3), 3), y=1:10)<br> unstack(df, y ~ x)<br><br>But if people don't read the documentation, they wouldn't know this difference until they land up on errors. Now, making it user-friendly would mean that it "always" returns a list. <br>
<br>Now, is this "bad" design because it gives two object types for same input? Does it require a change? I personally don't think so.<br><br>To sum up, what eddi points out as "not being user-friendly" (or arguably "bad design") is everywhere inside R if you look closely. My view is that it's very clear that there should be some effort in understanding a function before using it. Not all functions are plain simple. Some functions have exceptions and some packages have a steep learning curve.<br>
<br>Best,<br>Arun.<br><br><br></div></div><div class="im">On Sat, Apr 27, 2013 at 12:00 PM, <<a href="mailto:datatable-help-request@lists.r-forge.r-project.org" target="_blank">datatable-help-request@lists.r-forge.r-project.org</a>> wrote:<br>
><br>> Send datatable-help mailing list submissions to<br></div>
> <a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a><div class="im"><br>><br>> To subscribe or unsubscribe via the World Wide Web, visit<br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
><br>> or, via email, send a message with subject or body 'help' to<br></div>> <a href="mailto:datatable-help-request@lists.r-forge.r-project.org" target="_blank">datatable-help-request@lists.r-forge.r-project.org</a><div class="im">
<br>
><br>> You can reach the person managing the list at<br></div>> <a href="mailto:datatable-help-owner@lists.r-forge.r-project.org" target="_blank">datatable-help-owner@lists.r-forge.r-project.org</a><div class="im">
<br>><br>> When replying, please edit your Subject line so it is more specific<br>
> than "Re: Contents of datatable-help digest..."<br>><br>><br>> Today's Topics:<br>><br>> 1. Re: changing data.table by-without-by syntax to require a<br>> "by" (Frank Erickson)<br>
> 2. Re: variable column names (Sam Steingold)<br>> 3. Re: variable column names (Matthew Dowle)<br>> 4. Re: changing data.table by-without-by syntax to require a<br>> "by" (Matthew Dowle)<br>
> 5. Re: variable column names (Victor Kryukov)<br>><br>><br>> ----------------------------------------------------------------------<br>><br>> Message: 1<br>> Date: Fri, 26 Apr 2013 15:34:39 -0500<br>
</div>
> From: Frank Erickson <<a href="mailto:FErickson@psu.edu" target="_blank">FErickson@psu.edu</a>><br>> To: "data.table source forge"<br>> <<a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a>><div class="im">
<br>
> Subject: Re: [datatable-help] changing data.table by-without-by syntax<br>> to require a "by"<br>> Message-ID:<br></div>> <CAJd-hdkv1oiSjfA625oBxmXwr5YuVUzz==<a href="mailto:3GLaWJTakAtzMJVw@mail.gmail.com" target="_blank">3GLaWJTakAtzMJVw@mail.gmail.com</a>><div class="im">
<br>
> Content-Type: text/plain; charset="iso-8859-1"<br>><br>> I disagree with the criticism of data.table's complexity (in the OP).<br>> There's nothing wrong with overloading the syntax (that is what CS people<br>
> call it, right?). As long as Matthew's in control of it, it's likely to<br>> have some internal consistency (which, of course, he could explain).<br>> However, I like the suggestion to add options (defaulting to something<br>
> globally adjustable) to disable some of the overloading. Along similar<br>> lines (I think), I find unique.data.table very unintuitive. I can see how<br>> it could be useful, but strongly prefer base::unique for my current<br>
> applications.<br>><br>> Anyway, I have nothing particular to say about the piece of syntax you all<br>> are currently discussing. I just registered with this list to chime in<br>> here, instead of further cluttering SO (where eddi answered one of my<br>
> questions yesterday). These emails sure are wide; must be like 1500px!<br>> Interesting to try out this ancient mailing-list form of communication.<br>> Please let me know if I should be using "Reply All" or actually quoting<br>
> that massive thread (as everyone else seems to be doing with each post).<br>><br>> Frank<br>> -------------- next part --------------<br>> An HTML attachment was scrubbed...<br>> URL: <<a href="http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20130426/eb6556ae/attachment-0001.html" target="_blank">http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20130426/eb6556ae/attachment-0001.html</a>><br>
><br>> ------------------------------<br>><br>> Message: 2<br>> Date: Fri, 26 Apr 2013 18:02:31 -0400<br></div>> From: Sam Steingold <<a href="mailto:sds@gnu.org" target="_blank">sds@gnu.org</a>><br>
> To: <a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a><div class="im"><br>
> Subject: Re: [datatable-help] variable column names<br></div>> Message-ID: <<a href="mailto:87wqrpj6h4.fsf@gnu.org" target="_blank">87wqrpj6h4.fsf@gnu.org</a>><br>> Content-Type: text/plain<br>><br>> > * Sam Steingold <fqf@tah.bet> [2013-04-26 13:05:39 -0400]:<br>
> ><br>> >> * Matthew Dowle <zqbjyr@zqbjyr.cyhf.pbz> [2013-04-26 17:45:53 +0100]:<div class="im"><br>> >><br>> >> S.O. is probably better for this kind of question then.<br>> >> But if you don't get an answer there, then come back to datatable-help.<br>
> ><br>> > <a href="http://stackoverflow.com/questions/16241687/summarize-a-data-table-across-multiple-columns" target="_blank">http://stackoverflow.com/questions/16241687/summarize-a-data-table-across-multiple-columns</a><br>
><br>> downvoted, unlikely to be answered.<br>><br>> --<br>> Sam Steingold (<a href="http://sds.podval.org/" target="_blank">http://sds.podval.org/</a>) on Ubuntu 12.10 (quantal) X 11.0.11300000<br>> <a href="http://www.childpsy.net/" target="_blank">http://www.childpsy.net/</a> <a href="http://iris.org.il" target="_blank">http://iris.org.il</a> <a href="http://think-israel.org" target="_blank">http://think-israel.org</a><br>
> <a href="http://americancensorship.org" target="_blank">http://americancensorship.org</a> <a href="http://pmw.org.il" target="_blank">http://pmw.org.il</a> <a href="http://mideasttruth.com" target="_blank">http://mideasttruth.com</a><br>
> We have preferences. You have biases. They have prejudices.<br>
><br>><br>><br>> ------------------------------<br>><br>> Message: 3<br>> Date: Fri, 26 Apr 2013 23:47:55 +0100<br></div>> From: Matthew Dowle <<a href="mailto:mdowle@mdowle.plus.com" target="_blank">mdowle@mdowle.plus.com</a>><br>
> To: <<a href="mailto:sds@gnu.org" target="_blank">sds@gnu.org</a>><br>> Cc: <a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a><div class="im">
<br>> Subject: Re: [datatable-help] variable column names<br></div>
> Message-ID: <<a href="mailto:30d6ae8f1a0d6974ebbd54da0d86f3b2@imap.plus.net" target="_blank">30d6ae8f1a0d6974ebbd54da0d86f3b2@imap.plus.net</a>><div class="im"><br>> Content-Type: text/plain; charset=UTF-8; format=flowed<br>
><br>> On <a href="tel:26.04.2013%2023" value="+12604201323" target="_blank">26.04.2013 23</a>:02, Sam Steingold wrote:<br></div>
> >> * Sam Steingold <fqf@tah.bet> [2013-04-26 13:05:39 -0400]:<br>> >><br>> >>> * Matthew Dowle <zqbjyr@zqbjyr.cyhf.pbz> [2013-04-26 17:45:53<div class="im"><br>> >>> +0100]:<br>
> >>><br>
> >>> S.O. is probably better for this kind of question then.<br>> >>> But if you don't get an answer there, then come back to<br>> >>> datatable-help.<br>> >><br>> >><br>
> >> <a href="http://stackoverflow.com/questions/16241687/summarize-a-data-table-across-multiple-columns" target="_blank">http://stackoverflow.com/questions/16241687/summarize-a-data-table-across-multiple-columns</a><br>
> ><br>
> > downvoted, unlikely to be answered.<br>><br>> I've read it through.<br>><br>> Perhaps sleep on it, don't look for 24hrs and look again as if you were<br>> trying to answer it yourself. Are there any small changes you can make<br>
> to make it easier to answer? It wasn't me that downvoted but I suspect<br>> it's been done to encourage you to improve the question. Downvotes can<br>> (and often are) reversed. I've had many more downvotes than you once,<br>
> but then I improved it and it went to +10.<br>><br>> And, it's Friday and we've all had a long week!<br>><br>> Matthew<br>><br>><br>><br>><br>> ------------------------------<br>><br>
> Message: 4<br>> Date: Sat, 27 Apr 2013 00:35:17 +0100<br></div>> From: Matthew Dowle <<a href="mailto:mdowle@mdowle.plus.com" target="_blank">mdowle@mdowle.plus.com</a>><br>> To: Frank Erickson <<a href="mailto:FErickson@psu.edu" target="_blank">FErickson@psu.edu</a>><br>
> Cc: "data.table source forge"<br>> <<a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a>><div class="im"><br>> Subject: Re: [datatable-help] changing data.table by-without-by syntax<br>
> to require a "by"<br></div>> Message-ID: <<a href="mailto:be967ecd9c927ade15c15eb9985d919e@imap.plus.net" target="_blank">be967ecd9c927ade15c15eb9985d919e@imap.plus.net</a>><div><div class="h5">
<br>> Content-Type: text/plain; charset="utf-8"<br>
><br>><br>><br>> Thanks for your comments Frank.<br>><br>> Ha, yes it's ancient but still has<br>> a place. Yes "reply all": Back To: sender (if it's to someone in<br>> particular) and cc the list. But on general topics where lots of people<br>
> are on the thread, just To: datatable-help alone is fine. Personally I<br>> prefer "top posting". Like I'm doing now. I only scroll down if I need<br>> to. I didn't notice the history was building up. If you comment inline<br>
> later, then say "scroll down for comments inline" or something at the<br>> top. Note that Nabble collapses the history for you so threads are much<br>> easier to read there. Or I tend to read via RSS (gmane) in Outlook, so<br>
> it feels like an email inbox which turns bold on new posts. You only<br>> need to subscribe to post (spam control). Most people turn off mail<br>> delivery pretty quickly I imagine (or setup an auto rule to move into a<br>
> folder, but then you might as well subscribe to RSS I guess).<br>><br>> S.O. is<br>> quite strict: must be clear questions with a clear answer, only one of<br>> which can be accepted. No opinion, voting, discussing or notices (enter<br>
> mailing lists). Chat room is good but for quick chat when people are in<br>> the room at the same time. Many companies (sensibly) block chat access,<br>> though. Mailing lists allows all timezones a chance at a slower pace.<br>
> Anonymity is just as acceptable and as easy in both places.<br>><br>> Matthew<br>><br>><br>> On <a href="tel:26.04.2013%2021" value="+12604201321" target="_blank">26.04.2013 21</a>:34, Frank Erickson wrote:<br>
><br>> > I disagree with the<br>> criticism of data.table's complexity (in the OP). There's nothing wrong<br>
> with overloading the syntax (that is what CS people call it, right?). As<br>> long as Matthew's in control of it, it's likely to have some internal<br>> consistency (which, of course, he could explain). However, I like the<br>
> suggestion to add options (defaulting to something globally adjustable)<br>> to disable some of the overloading. Along similar lines (I think), I<br>> find unique.data.table very unintuitive. I can see how it could be<br>
> useful, but strongly prefer base::unique for my current applications.<br>> ><br>> Anyway, I have nothing particular to say about the piece of syntax you<br>> all are currently discussing. I just registered with this list to chime<br>
> in here, instead of further cluttering SO (where eddi answered one of my<br>> questions yesterday). These emails sure are wide; must be like 1500px!<br>> Interesting to try out this ancient mailing-list form of communication.<br>
> Please let me know if I should be using "Reply All" or actually quoting<br>> that massive thread (as everyone else seems to be doing with each post).<br>><br>> > Frank<br>><br>><br>> -------------- next part --------------<br>
> An HTML attachment was scrubbed...<br>> URL: <<a href="http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20130427/260f3119/attachment-0001.html" target="_blank">http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20130427/260f3119/attachment-0001.html</a>><br>
><br>> ------------------------------<br>><br>> Message: 5<br>> Date: Fri, 26 Apr 2013 16:42:04 -0700<br></div></div>> From: Victor Kryukov <<a href="mailto:victor.kryukov@gmail.com" target="_blank">victor.kryukov@gmail.com</a>><br>
> To: Matthew Dowle <<a href="mailto:mdowle@mdowle.plus.com" target="_blank">mdowle@mdowle.plus.com</a>><br>> Cc: <a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a>, <a href="mailto:sds@gnu.org" target="_blank">sds@gnu.org</a><div class="im">
<br>
> Subject: Re: [datatable-help] variable column names<br>> Message-ID:<br></div>> <CANJmMqTz5+6djLEwpZxsub6LB=3L37=JB3xt5AhG1XgWG=<a href="mailto:nJgw@mail.gmail.com" target="_blank">nJgw@mail.gmail.com</a>><br>
> Content-Type: text/plain; charset=ISO-8859-1<div class="im"><br>
><br>> On Fri, Apr 26, 2013 at 3:47 PM, Matthew Dowle <<a href="mailto:mdowle@mdowle.plus.com" target="_blank">mdowle@mdowle.plus.com</a>> wrote:<br>> > On <a href="tel:26.04.2013%2023" value="+12604201323" target="_blank">26.04.2013 23</a>:02, Sam Steingold wrote:<br>
> >>> <a href="http://stackoverflow.com/questions/16241687/summarize-a-data-table-across-multiple-columns" target="_blank">http://stackoverflow.com/questions/16241687/summarize-a-data-table-across-multiple-columns</a><br>
> >><br>> >> downvoted, unlikely to be answered.<br>> ><br>> > I've read it through.<br>> ><br>> > Perhaps sleep on it, don't look for 24hrs and look again as if you were<br>
> > trying to answer it yourself. Are there any small changes you can make to<br>> > make it easier to answer? It wasn't me that downvoted but I suspect it's<br>> > been done to encourage you to improve the question. Downvotes can (and often<br>
> > are) reversed. I've had many more downvotes than you once, but then I<br>> > improved it and it went to +10.<br>> ><br>> > And, it's Friday and we've all had a long week!<br>><br>
> Beautiful advice, Matthew!<br>><br>> Sam - I've provided my answer (and even used Reduce since you seem to<br>> be coming from Lisp land), but I also think some of the down<br>> votes/comments have their merit.<br>
><br>><br>> ------------------------------<br>><br>> _______________________________________________<br>> datatable-help mailing list<br></div>> <a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a><div class="im">
<br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>><br>> End of datatable-help Digest, Vol 38, Issue 26<br>
> **********************************************<br><br></div></div>
<br>_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br></blockquote></div><br></div>