I found an answer to my question. It turned out this behavior is described in the documentation for org-babel-expand-noweb-references: "Note that any text preceding the <> construct on a line will be interposed between the lines of the replacement text. So for example if <> is placed behind a comment, then the entire replacement text will also be commented." It is also documented in the manual http://orgmode.org/manual/noweb.html#noweb in the "Noweb prefix lines" section. So, in my case the solution is to put the <> reference on the next line: #+begin_src R :session *R* :noweb yes result <- submit_query(" <>") #+end_src It doesn't look as nice as before but it works. Alex On Wed, Sep 18, 2013 at 7:43 PM, Alexander Vorobiev < alexander.vorobiev@gmail.com> wrote: > Hi Tom, > > Unfortunately I can't have pure SQL output in my org files for two reasons: > > 1. The result set I am dealing with for this particular problem is about > 20000 records > 2. My SQL server (Netezza, "big data appliance") is not supported by > Babel-SQL. I configured sql-mode to work with Netezza but session-based SQL > is not supported by Babel either. I started adding support for SQL sessions > to ob-sql.el and it kind of works but the results I am getting are > inconsistent and only a small subset of header parameters is supported. Of > course I haven't tested is with any other database. I can share what I've > done if anybody is interested. > > Regards, > Alex > > > On Wed, Sep 18, 2013 at 5:27 PM, Thomas S. Dye wrote: > >> Aloha Alex, >> >> My work flow in this situation evaluates the SQL to create an Org-mode >> table, which serves as input to the R source code block. >> >> For me, seeing the SQL output in a table is a sanity check. >> >> hth, >> Tom >> >> Alexander Vorobiev writes: >> >> > I have R code which submits SQL statements to a database server. Since >> the >> > SQL is rather complex, I want to put it into a separate code block in >> order >> > to have proper formatting, syntax highlighting, etc: >> > >> > #+name: long-sql >> > #+begin_src sql >> > select * >> > from many, tables >> > where >> > complex_condition1 = 1, >> > complex_condition2 = 2 >> > #+end_src >> > >> > * Load the data to R session >> > #+begin_src R :session *R* :noweb yes >> > result <- submit_query('<>') >> > #+end_src >> > >> > Unfortunately, the R block doesn't work. When I open the file generated >> by >> > Babel, I see this: >> > >> > result <- submit_query('select * >> > result <- submit_query('from many, tables >> > etc >> > >> > instead of the one R submit_query call with my SQL statement as an >> > argument. Is there anything I can do to achieve that? >> > >> > Thanks >> > Alex >> > I have R code which submits SQL statements to a database server. Since >> > the SQL is rather complex, I want to put it into a separate code block >> > in order to have proper formatting, syntax highlighting, etc: >> > >> > #+name: long-sql >> > #+begin_src sql >> > select * >> > from many, tables >> > where >> > complex_condition1 = 1, >> > complex_condition2 = 2 >> > #+end_src >> > >> > * Load the data to R session >> > #+begin_src R :session *R* :noweb yes >> > result <- submit_query('<>') >> > #+end_src >> > >> > Unfortunately, the R block doesn't work. When I open the file >> > generated by Babel, I see this: >> > >> > result <- submit_query('select * >> > result <- submit_query('from many, tables >> > etc >> > >> > instead of the one R submit_query call with my SQL statement as an >> > argument. Is there anything I can do to achieve that? >> > >> > Thanks >> > Alex >> > >> > >> >> -- >> Thomas S. Dye >> http://www.tsdye.com >> > >