From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: Error Embedding SQL Source from code block into R Source of Another (noweb) Date: Tue, 30 Sep 2014 10:05:57 +0200 Message-ID: References: <87lhp2x7p9.fsf@air.ben-zion.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYsRt-0000dd-C7 for emacs-orgmode@gnu.org; Tue, 30 Sep 2014 04:06:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XYsRo-0002Vk-1r for emacs-orgmode@gnu.org; Tue, 30 Sep 2014 04:06:17 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:45183) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYsRn-0002VA-NX for emacs-orgmode@gnu.org; Tue, 30 Sep 2014 04:06:11 -0400 Received: by mail-wi0-f174.google.com with SMTP id cc10so1737480wib.7 for ; Tue, 30 Sep 2014 01:06:05 -0700 (PDT) In-Reply-To: <87lhp2x7p9.fsf@air.ben-zion.org> (Eric Brown's message of "Mon, 29 Sep 2014 19:39:30 -0500") 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: Eric Brown Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Eric Brown writes: > Dear List: > > It is possible to embed SQL code as a string to be evaluated in R. I am > interested in formatting the SQL code in its own source code block, with > its own syntax highlighting and editing mode (C-c '). This sounds very interesting, and I would be interested in doing thia as well. Up to now, I was writing the sql statements in R, which is a pain (paste, paste0, ...). But editing them in org and passing them to an R source block as a variable sounds interestin, but I don't think this will work. What might work is using noweb expansion, but I never used it. Check out the worg [1] "Simple Literate Programming Example (Noweb syntax)" From=20the page: ,---- | In the Org-mode file: |=20 | #+name: hello-world-prefix | #+begin_src sh :exports none | echo "/-----------------------------------------------------------\\" | #+end_src | HTML export of code: In the Org-mode file |=20 | #+name: hello-world-postfix #+begin_src sh :exports none echo | "\-----------------------------------------------------------/" | #+end_src |=20 | HTML export of code: The third code block does have a tangle header | argument indicating the name of the file to which the tangled source | code will be written. It also has Noweb style references to the two | previous code blocks. These references will be expanded during | tangling to include them in the output file as well. |=20 | In the Org-mode file: |=20 | #+name: hello-world | #+begin_src sh :tangle hello :exports none :noweb yes | <> | echo "| hello world |" | <> | #+end_src | | HTML export of code: Calling org-babel-tangle will result in the following | shell source code being written to the hello.sh file: |=20 | #!/usr/bin/env sh |=20 | # [[file:~/org/temp/index.org::*Noweb%20test][hello-world]] |=20 | echo "/-----------------------------------------------------------\\" | echo "| hello world |" | echo "\-----------------------------------------------------------/" | # hello-world ends here | | In addition, the following syntax can be used to insert the results of | evaluating a code block, in this case one named example-block. |=20 | # <> `---- I guess this should work - and I will try it out - learned something. Thanks for the question, Rainer > > The first time I run the code, I am prompted for R starting directory, > but I get an error: > > --- > load ESSR: + + + Error: unexpected string constant in: > source('~/.emacs.d/elpa/ess-20140913.1153/etc/ESSR/R/.load.R', > local=3DTRUE) #define load.ESSR > load.ESSR('" > --- > > and the console locks. I can C-g to get out of it, and then > re-evaluate, and the code prints what I expect -- the text of the SQL > command. > > Is this the right way to go about this? Have I discovered a bug, or > perhaps accidentally a wrong way to get the right answer? > > Is this an ESS problem, and not an orgmode problem, per se? My ESS > normally starts up fine, so I thought I would ask on this list first. > > A minimal example (first failing, second evaluation giving expected > output) follows. > > Best regards, > > Eric > > Debian GNU/Linux (jessie) > Emacs 24.3.93 > Org current from org repo > ESS from MELPA (ca. 14.09) > R 3.1.1 compiled from source > > > > ----- SESSION ----- > #+TITLE: Test SQL Code > #+AUTHOR: Eric Brown=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20 > #+EMAIL: brown@fastmail.fm > #+PROPERTY: session *R*=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20 > #+PROPERTY: cache no > > #+name: sqlsource > #+begin_src sql :engine postgresql :eval yes :noweb-ref sqlsrc :exports c= ode :results none > select=20 > *=20 > from=20 > t=20 > limit=20 > 10 > #+end_src > > #+name: rsource > #+begin_src R :noweb yes :results output :exports both > input <- ' > <> > ' > cat(input) > # dbGetQuery(connectionHandle, input) > #+end_src > > #+RESULTS: rsource > :=20 > : select=20 > : *=20 > : from=20 > : t=20 > : limit=20 > : 10 > --------------------- > > > > Footnotes:=20 [1] http://orgmode.org/worg/org-contrib/babel/intro.html =2D-=20 Rainer M. Krug email: Rainerkrugsde PGP: 0x0F52F982 --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) iQEcBAEBAgAGBQJUKmRpAAoJENvXNx4PUvmCemAH/3fWMdcdksxLqcRN51KDPzFl CyKNU2pQ7BUNv4/zHjYYD1shXWzUHAITrBdawAoFxfWD3XbX0bwewD53OXdhWGVb lrCxZNRBrTagNm84F1hy2HPFH1+ZQz23yBbOkayf3CcCVGQvthL+lujXXQvzRZsV 8chC5QHmCi9RD/yChja/tT0ZZQW4vPR38HgmCTRQ6hUa9oMz4M37sqB4aWtyASRg Bruot4J3nan1Jb0hu7yMP5HBCFL5UIA2bTiEa65ruRLhfuQpfaj6wGVGB5LVL1yq 2KFMWMUuyFEBYNm4uD2wJIT+CpXqNvsFuyyQRas0m8hoaUcM6Mnjx0TJpJ4RxO4= =5iMP -----END PGP SIGNATURE----- --=-=-=--