From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Charles C. Berry" Subject: Re: Adding `sort' in R makes the output fail Date: Thu, 23 Oct 2014 13:04:44 -0700 Message-ID: References: <86bnp2g8dn.fsf@example.com> <86y4s6wri1.fsf@example.com> Mime-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhOdO-00044i-VE for emacs-orgmode@gnu.org; Thu, 23 Oct 2014 16:05:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XhOdF-0000X4-MW for emacs-orgmode@gnu.org; Thu, 23 Oct 2014 16:05:22 -0400 Received: from plane.gmane.org ([80.91.229.3]:49948) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhOdF-0000Wt-Ca for emacs-orgmode@gnu.org; Thu, 23 Oct 2014 16:05:13 -0400 Received: from public by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XhOdE-00062R-1e for emacs-orgmode@gnu.org; Thu, 23 Oct 2014 22:05:12 +0200 In-Reply-To: <86y4s6wri1.fsf@example.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Sebastien Vauban Cc: public-emacs-orgmode-mXXj517/zsQ@plane.gmane.org On Thu, 23 Oct 2014, Sebastien Vauban wrote: > "Charles C. Berry" wrote: >> On Thu, 23 Oct 2014, Sebastien Vauban wrote: >>> >>> The following code does return a corrupted answer, while it's supposed >>> to return a sorted dataframe. >> >> Not so. See below. > > So, that's RStudio that's wrong, in some way? > Hmmm. Not exactly wrong. There are a few wrinkles: org-babel-R-write-object-command specifies a call to 'write.table(object)', where `object' is what is to be printed. `write.table' coerces whatever it is trying to print to a `data.frame'. See ?write.table There is a method for `table' in `as.data.frame'. Try as.data.frame(table(1:3)) in the console or R gui to get a sense of what happens. There is also an `array' method for `as.data.frame', but with a one dimensional array it passes control to the `vector' method. Try: as.data.frame(sort(table(1:3))) So it is really differences in the result of as.data.frame() that you were seeing. I DK what RStudio does, but it must try harder a little harder to present 1 dimensional arrays. HTH, Chuck