From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Hannon Subject: Re: Babel: communicating irregular data to R source-code block Date: Wed, 25 Apr 2012 19:06:22 -0700 (PDT) Message-ID: <1335405982.82297.YahooMailNeo@web161901.mail.bf1.yahoo.com> 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> Reply-To: Michael Hannon 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]:42090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNE6E-0000MV-TT for emacs-orgmode@gnu.org; Wed, 25 Apr 2012 22:06:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SNE6C-0000MZ-Se for emacs-orgmode@gnu.org; Wed, 25 Apr 2012 22:06:26 -0400 Received: from nm5-vm0.bullet.mail.bf1.yahoo.com ([98.139.213.150]:47853) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1SNE6C-0000MC-JT for emacs-orgmode@gnu.org; Wed, 25 Apr 2012 22:06:24 -0400 In-Reply-To: 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: "Thomas S. Dye" Cc: Org-Mode List , Eric Schulte On Wednesday, April 25, 2012 at 4:52 PM Thomas S. Dye wrote:=0A=0A>Michael = Hannon writes:=0A>=0A>> On Monday, April 23, 2012 at = 11:44 PM Thomas S. Dye wrote:=0A>> .=0A>> .=0A>> .=0A>>> The documentation = of read.table has this:=0A>>=0A>>> The number of data columns is determined= by looking at the first five=0A>>> lines=0A>>> of input (or the whole file= if it has less than five lines), or from the=0A>>> length of col.names if = it is specified and is longer. This could=0A>>> conceivably=0A>>> be wrong = if fill or blank.lines.skip are true, so specify col.names if=0A>>> necessa= ry (as in the =E2=80=98Examples=E2=80=99).=0A>>=0A>>> The example is this:= =0A>>=0A>>> read.csv(tf, fill =3D TRUE, header =3D FALSE,=0A>>>=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 ""))=0A>>=0A>>> where read.csv is a synonym of read.table with pr= eset arguments.=0A>>=0A>>> This explains why the sixth line wraps.=0A>> .= =0A>> .=0A>> .=0A>>=0A>> Thanks, Tom.=C2=A0 I had just run across this myse= lf. I guess I need to walk a=0A>> mile=0A>> in somebody's moccasins before = complaining, but this behavior on the part=0A>> of R=0A>> seems totally stu= pid to me.=0A>>=0A>> I'm going to have to mull this over some more.=0A>>=0A= >> -- Mike=0A>>=0A>>=0A>Aloha Mike,=0A>=0A>Eric Schulte has pushed up some = patches designed to make R source block=0A>variables accept irregular data.= =C2=A0 So, with pascals-triangle(8), for=0A>instance, one gets a potentiall= y useful dataframe in R:=0A>=0A>#+NAME: sanity-check=0A>#+HEADER: :var sc_i= nput=3Dpascals-triangle=0A>#+BEGIN_SRC R=0A>sc_input=0A>#+END_SRC=0A>=0A>#+= RESULTS: sanity-check=0A>| 1 | nil | nil | nil | nil | nil | nil | nil | ni= l |=0A>| 1 |=C2=A0=C2=A0 1 | nil | nil | nil | nil | nil | nil | nil |=0A>|= 1 |=C2=A0=C2=A0 2 |=C2=A0=C2=A0 1 | nil | nil | nil | nil | nil | nil |=0A= >| 1 |=C2=A0=C2=A0 3 |=C2=A0=C2=A0 3 |=C2=A0=C2=A0 1 | nil | nil | nil | ni= l | nil |=0A>| 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 |=0A>| 1 |=C2=A0=C2=A0 5 |=C2=A0 10 |=C2=A0 1= 0 |=C2=A0=C2=A0 5 | 1=C2=A0=C2=A0 | nil | nil | nil |=0A>| 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 |=0A>| 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 |=0A>| 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 = |=0A>=0A>Could you pull the development version of Org mode and see if this= =0A>solves your problem?=0A=0AWell, NOW you've done it!=C2=A0 Just when I t= hought I could beg off on this talk,=0Ait all seems to be working ;-)=C2=A0= Thanks, Tom and Eric.=0A=0AI've appended a sample output, just FYI.=C2=A0 = I also tried it for n=3D7 and got the=0Acorrect results.=C2=A0 Magic!=0A=0A= As an aside, the rows of the Pascal Triangle should sum to 2^n, which they = do=0Ain my test cases.=C2=A0 I haven't yet implemented Eric's (much sexier)= =0A"sum(sub-diagonal-elements) =3D=3D Fibonacci nos." test, but I'll look i= nto it.=0A=0AThanks again,=0A=0A-- Mike=0A=0A##############################= ###############################=0A=0AOrg-mode version 7.8.09 (release_7.8.0= 9-390-gfb7ebd @=0A/usr/local/emacs.d/org-mode/org-devel/org-mode/lisp/org-i= nstall.el)=0A=0A-----=0A=0A#+PROPERTY: session *R*=0A* verify PT=0A=0A#+nam= e: pascals_triangle=0A#+begin_src python :var n=3D5 :exports none :results = value=0Adef pascals_triangle(n):=0A=C2=A0=C2=A0=C2=A0 if n =3D=3D 0:=0A=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return [[1]]=0A=C2=A0=C2=A0=C2=A0 p= rev_triangle =3D pascals_triangle(n-1)=0A=C2=A0=C2=A0=C2=A0 prev_row =3D pr= ev_triangle[n-1]=0A=C2=A0=C2=A0=C2=A0 this_row =3D map(sum, zip([0] + prev_= row, prev_row + [0]))=0A=C2=A0=C2=A0=C2=A0 return prev_triangle + [this_row= ]=0A=0Apascals_triangle(n)=0A#+end_src=0A=0A#+RESULTS: pascals_triangle=0A|= 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 |=0A| 1 | 1 |=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0= |=C2=A0=C2=A0 |=0A| 1 | 2 |=C2=A0 1 |=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 |=C2= =A0=C2=A0 |=0A| 1 | 3 |=C2=A0 3 |=C2=A0 1 |=C2=A0=C2=A0 |=C2=A0=C2=A0 |=0A|= 1 | 4 |=C2=A0 6 |=C2=A0 4 | 1 |=C2=A0=C2=A0 |=0A| 1 | 5 | 10 | 10 | 5 | 1 = |=0A=0A=0A#+NAME: sanity-check(sc_input=3Dpascals_triangle)=0A#+BEGIN_SRC R= :fill yes :results output=0A=C2=A0 =0A=C2=A0 pt <- sc_input=0A=C2=A0 pt[is= .na(pt)] <- 0=0A=C2=A0 rowSums(pt)=0A=C2=A0 =0A=C2=A0 =0A#+END_SRC =C2=A0= =0A=0A#+RESULTS: sanity-check=0A: [1]=C2=A0 1=C2=A0 2=C2=A0 4=C2=A0 8 16 32