From mboxrd@z Thu Jan 1 00:00:00 1970 From: tsd@tsdye.com (Thomas S. Dye) Subject: Re: Babel: communicating irregular data to R source-code block Date: Wed, 25 Apr 2012 20:34:15 -1000 Message-ID: References: <1335039472.9075.YahooMailNeo@web161901.mail.bf1.yahoo.com> <87ipgrn4by.fsf@gmx.com> <1335219898.41851.YahooMailNeo@web161901.mail.bf1.yahoo.com> <87aa22t5vn.fsf@gmx.com> <1335251229.83988.YahooMailNeo@web161905.mail.bf1.yahoo.com> <1335405982.82297.YahooMailNeo@web161901.mail.bf1.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:39029) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNIHh-00073p-A8 for emacs-orgmode@gnu.org; Thu, 26 Apr 2012 02:34:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SNIHa-0007Ty-NA for emacs-orgmode@gnu.org; Thu, 26 Apr 2012 02:34:32 -0400 Received: from oproxy9.bluehost.com ([69.89.24.6]:47415) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1SNIHa-0007Nk-DR for emacs-orgmode@gnu.org; Thu, 26 Apr 2012 02:34:26 -0400 In-Reply-To: <1335405982.82297.YahooMailNeo@web161901.mail.bf1.yahoo.com> (Michael Hannon's message of "Wed, 25 Apr 2012 19:06:22 -0700 (PDT)") 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: Michael Hannon Cc: Org-Mode List , Eric Schulte Michael Hannon writes: > On Wednesday, April 25, 2012 at 4:52 PM Thomas S. Dye wrote: > >>Michael Hannon writes: >> >>> On Monday, April 23, 2012 at 11:44 PM Thomas S. Dye wrote: >>> . >>> . >>> . >>>> The documentation of read.table has this: >>> >>>> The number of data columns is determined by looking at the first five >>>> lines >>>> of input (or the whole file if it has less than five lines), or from t= he >>>> length of col.names if it is specified and is longer. This could >>>> conceivably >>>> be wrong if fill or blank.lines.skip are true, so specify col.names if >>>> necessary (as in the =E2=80=98Examples=E2=80=99). >>> >>>> The example is this: >>> >>>> read.csv(tf, fill =3D TRUE, header =3D FALSE, >>>>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 col.names =3D paste("V= ", seq_len(ncol), sep =3D "")) >>> >>>> where read.csv is a synonym of read.table with preset arguments. >>> >>>> This explains why the sixth line wraps. >>> . >>> . >>> . >>> >>> Thanks, Tom.=C2=A0 I had just run across this myself. I guess I need to= walk a >>> mile >>> in somebody's moccasins before complaining, but this behavior on the pa= rt >>> of R >>> seems totally stupid to me. >>> >>> I'm going to have to mull this over some more. >>> >>> -- Mike >>> >>> >>Aloha Mike, >> >>Eric Schulte has pushed up some patches designed to make R source block >>variables accept irregular data.=C2=A0 So, with pascals-triangle(8), for >>instance, one gets a potentially useful dataframe in R: >> >>#+NAME: sanity-check >>#+HEADER: :var sc_input=3Dpascals-triangle >>#+BEGIN_SRC R >>sc_input >>#+END_SRC >> >>#+RESULTS: sanity-check >>| 1 | nil | nil | nil | nil | nil | nil | nil | nil | >>| 1 |=C2=A0=C2=A0 1 | nil | nil | nil | nil | nil | nil | nil | >>| 1 |=C2=A0=C2=A0 2 |=C2=A0=C2=A0 1 | nil | nil | nil | nil | nil | nil | >>| 1 |=C2=A0=C2=A0 3 |=C2=A0=C2=A0 3 |=C2=A0=C2=A0 1 | nil | nil | nil | n= il | nil | >>| 1 |=C2=A0=C2=A0 4 |=C2=A0=C2=A0 6 |=C2=A0=C2=A0 4 |=C2=A0=C2=A0 1 | nil= | nil | nil | nil | >>| 1 |=C2=A0=C2=A0 5 |=C2=A0 10 |=C2=A0 10 |=C2=A0=C2=A0 5 | 1=C2=A0=C2=A0= | nil | nil | nil | >>| 1 |=C2=A0=C2=A0 6 |=C2=A0 15 |=C2=A0 20 |=C2=A0 15 | 6=C2=A0=C2=A0 | 1= =C2=A0=C2=A0 | nil | nil | >>| 1 |=C2=A0=C2=A0 7 |=C2=A0 21 |=C2=A0 35 |=C2=A0 35 | 21=C2=A0 | 7=C2=A0= =C2=A0 | 1=C2=A0=C2=A0 | nil | >>| 1 |=C2=A0=C2=A0 8 |=C2=A0 28 |=C2=A0 56 |=C2=A0 70 | 56=C2=A0 | 28=C2= =A0 | 8=C2=A0=C2=A0 | 1=C2=A0=C2=A0 | >> >>Could you pull the development version of Org mode and see if this >>solves your problem? > > Well, NOW you've done it!=C2=A0 Just when I thought I could beg off on th= is talk, > it all seems to be working ;-)=C2=A0 Thanks, Tom and Eric. > > I've appended a sample output, just FYI.=C2=A0 I also tried it for n=3D7 = and got the > correct results.=C2=A0 Magic! > > As an aside, the rows of the Pascal Triangle should sum to 2^n, which the= y do > in my test cases.=C2=A0 I haven't yet implemented Eric's (much sexier) > "sum(sub-diagonal-elements) =3D=3D Fibonacci nos." test, but I'll look in= to it. > > Thanks again, > > -- Mike Good news. Please consider sharing your seminar talk on Worg, if you think it might be appropriate. All the best, Tom > > ############################################################# > > Org-mode version 7.8.09 (release_7.8.09-390-gfb7ebd @ > /usr/local/emacs.d/org-mode/org-devel/org-mode/lisp/org-install.el) > > ----- > > #+PROPERTY: session *R* > * verify PT > > #+name: pascals_triangle > #+begin_src python :var n=3D5 :exports none :results value > def pascals_triangle(n): > =C2=A0=C2=A0=C2=A0 if n =3D=3D 0: > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return [[1]] > =C2=A0=C2=A0=C2=A0 prev_triangle =3D pascals_triangle(n-1) > =C2=A0=C2=A0=C2=A0 prev_row =3D prev_triangle[n-1] > =C2=A0=C2=A0=C2=A0 this_row =3D map(sum, zip([0] + prev_row, prev_row + [= 0])) > =C2=A0=C2=A0=C2=A0 return prev_triangle + [this_row] > > pascals_triangle(n) > #+end_src > > #+RESULTS: pascals_triangle > | 1 |=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |= =C2=A0=C2=A0 | > | 1 | 1 |=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0=C2= =A0 | > | 1 | 2 |=C2=A0 1 |=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2=A0=C2=A0 | > | 1 | 3 |=C2=A0 3 |=C2=A0 1 |=C2=A0=C2=A0 |=C2=A0=C2=A0 | > | 1 | 4 |=C2=A0 6 |=C2=A0 4 | 1 |=C2=A0=C2=A0 | > | 1 | 5 | 10 | 10 | 5 | 1 | > > > #+NAME: sanity-check(sc_input=3Dpascals_triangle) > #+BEGIN_SRC R :fill yes :results output > =C2=A0=20 > =C2=A0 pt <- sc_input > =C2=A0 pt[is.na(pt)] <- 0 > =C2=A0 rowSums(pt) > =C2=A0=20 > =C2=A0=20 > #+END_SRC =C2=A0 > > #+RESULTS: sanity-check > : [1]=C2=A0 1=C2=A0 2=C2=A0 4=C2=A0 8 16 32 > > --=20 Thomas S. Dye http://www.tsdye.com