emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Using cat() with R prints R session prompt (>) in results block
@ 2013-03-22 23:19 John Hendy
  2013-03-23 22:20 ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: John Hendy @ 2013-03-22 23:19 UTC (permalink / raw)
  To: emacs-orgmode

With an older orgmode file, I used a block like shown in this thread
to export multiple plots resulting from some modeling work in my
summary document:
- http://lists.gnu.org/archive/html/emacs-orgmode/2012-08/msg01222.html

The code I used was like so:

#+begin_src R :session model :results output raw :exports results

cat("#+begin_center")
cat("\n")

for() {

output-filename <- something[i]

ggplot code

pdf(output-filename)
print(p)
dev.off()

cat(paste("[[../plots/",output-filename,"]]",sep=""), sep="\n")
cat("\n")

} # end plotting loop

cat("#+end_center")

#+end_src

When I do that now, I'm getting the > prompt from my R session output
with the cat() command. For example:

#+name: test
#+begin_src R :session r :results output raw :exports results

cat(paste("#+end_center"))
cat("\n")

#+end_src

#+RESULTS: test
#+end_center>

How do I stop that?

As a side note... if I remove cat("\n"), nothing gets put into the
#+results block -- it's just empty. I don't understand why.


Thanks,
John

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using cat() with R prints R session prompt (>) in results block
  2013-03-22 23:19 Using cat() with R prints R session prompt (>) in results block John Hendy
@ 2013-03-23 22:20 ` Eric Schulte
  2013-03-24  1:32   ` John Hendy
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Schulte @ 2013-03-23 22:20 UTC (permalink / raw)
  To: John Hendy; +Cc: emacs-orgmode

[...]
> I'm getting the > prompt from my R session output
> with the cat() command. For example:
>
> #+name: test
> #+begin_src R :session r :results output raw :exports results
>
> cat(paste("#+end_center"))
> cat("\n")
>
> #+end_src
>
> #+RESULTS: test
> #+end_center>
>
> How do I stop that?
>
> As a side note... if I remove cat("\n"), nothing gets put into the
> #+results block -- it's just empty. I don't understand why.
>

Hi John,

This seems to be related to newlines and the parsing of session output.
Results aren't noticed without a newline, and when intermediately
printed results do not end in a newline, the prompt is pasted along with
the results.

If we look at the R session buffer, the cause of this bad behavior can
be seen.

    ,----[ESS buffer]
    | > cat(paste("#+end_center"))
    | cat("\n")
    | 'org_babel_R_eoe'
    | cat(paste("#+end_center"))
    | #+end_center> cat("\n")
    | 
    | 
    | > 'org_babel_R_eoe'
    | [1] "org_babel_R_eoe"
    `----

I'm not sure that we can (robustly and reasonably) distinguish the R
prompt from R process output when the prompt does not appear at the
start of a line.  Perhaps ESS could mark R prompts with a special text
property which would make this much easier from the Org-mode side?

Is it possible simply to ensure that code block output lines end in
newlines?

Cheers,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using cat() with R prints R session prompt (>) in results block
  2013-03-23 22:20 ` Eric Schulte
@ 2013-03-24  1:32   ` John Hendy
  0 siblings, 0 replies; 3+ messages in thread
From: John Hendy @ 2013-03-24  1:32 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

On Sat, Mar 23, 2013 at 5:20 PM, Eric Schulte <schulte.eric@gmail.com> wrote:
> [...]
>> I'm getting the > prompt from my R session output
>> with the cat() command. For example:
>>
>> #+name: test
>> #+begin_src R :session r :results output raw :exports results
>>
>> cat(paste("#+end_center"))
>> cat("\n")
>>
>> #+end_src
>>
>> #+RESULTS: test
>> #+end_center>
>>
>> How do I stop that?
>>
>> As a side note... if I remove cat("\n"), nothing gets put into the
>> #+results block -- it's just empty. I don't understand why.
>>
>
> Hi John,
>
> This seems to be related to newlines and the parsing of session output.
> Results aren't noticed without a newline, and when intermediately
> printed results do not end in a newline, the prompt is pasted along with
> the results.
>
> If we look at the R session buffer, the cause of this bad behavior can
> be seen.
>
>     ,----[ESS buffer]
>     | > cat(paste("#+end_center"))
>     | cat("\n")
>     | 'org_babel_R_eoe'
>     | cat(paste("#+end_center"))
>     | #+end_center> cat("\n")
>     |
>     |
>     | > 'org_babel_R_eoe'
>     | [1] "org_babel_R_eoe"
>     `----
>
> I'm not sure that we can (robustly and reasonably) distinguish the R
> prompt from R process output when the prompt does not appear at the
> start of a line.  Perhaps ESS could mark R prompts with a special text
> property which would make this much easier from the Org-mode side?
>

So babel filters out the ">" prompt if it's the first character? Makes sense?

> Is it possible simply to ensure that code block output lines end in
> newlines?

As in, instead of =cat(paste("#+end_center"))= use
=cat(paste("#+end_center \n"))= ?

If so, absolutely. I think for some reason I had trouble with this
once before, but I don't recall specifics. I'll give it a try on
Monday and confirm this works. If so, perhaps I could add a tidbit in
ob-R-doc about doing this when not simply including a single file for
export output.


Thanks for chiming in,
John

>
> Cheers,
>
> --
> Eric Schulte
> http://cs.unm.edu/~eschulte

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-24  1:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-22 23:19 Using cat() with R prints R session prompt (>) in results block John Hendy
2013-03-23 22:20 ` Eric Schulte
2013-03-24  1:32   ` John Hendy

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).