emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Variable in file name for babel output?
@ 2013-06-27 12:55 Loris Bennett
  2013-06-27 23:07 ` Andreas Leha
  0 siblings, 1 reply; 3+ messages in thread
From: Loris Bennett @ 2013-06-27 12:55 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Is it possible to pass a variable to a source block such that the
variable can be used as part of the name of the output file?

Currently I have

#+HEADER: :var data=timelimit-elapsed-data year=2011 :colnames yes
#+HEADER: :session *r* :file (org-babel-temp-file "time-elapsed-" ".pdf")

which gets me a different name for each value of 'year', but ideally I
would like the files to be called

time-elapsed-2011.pdf
time-elapsed-2012.pdf
time-elapsed-2013.pdf

etc.

Can this be done? 

Cheers,

Loris

-- 
This signature is currently under construction.

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

* Re: Variable in file name for babel output?
  2013-06-27 12:55 Variable in file name for babel output? Loris Bennett
@ 2013-06-27 23:07 ` Andreas Leha
  2013-06-28  6:21   ` Loris Bennett
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Leha @ 2013-06-27 23:07 UTC (permalink / raw)
  To: emacs-orgmode

Hi Loris,

"Loris Bennett" <loris.bennett@fu-berlin.de> writes:

> Hi,
>
> Is it possible to pass a variable to a source block such that the
> variable can be used as part of the name of the output file?
>
> Currently I have
>
> #+HEADER: :var data=timelimit-elapsed-data year=2011 :colnames yes
> #+HEADER: :session *r* :file (org-babel-temp-file "time-elapsed-" ".pdf")
>
> which gets me a different name for each value of 'year', but ideally I
> would like the files to be called
>
> time-elapsed-2011.pdf
> time-elapsed-2012.pdf
> time-elapsed-2013.pdf
>
> etc.
>
> Can this be done? 


Maybe not what you are looking for, but you could handle the assembly of
the filename within your code block.

Something like:

#+HEADER: :var year=2011 :session *r* :results file
#+begin_src R
  filename <- paste0("time-elapsed-", year, ".pdf")
  
  pdf(filename)
    ## your code
  dev.off()
  
  filename
#+end_src

Regards,
Andreas

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

* Re: Variable in file name for babel output?
  2013-06-27 23:07 ` Andreas Leha
@ 2013-06-28  6:21   ` Loris Bennett
  0 siblings, 0 replies; 3+ messages in thread
From: Loris Bennett @ 2013-06-28  6:21 UTC (permalink / raw)
  To: emacs-orgmode

Hi Andreas,

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> Hi Loris,
>
> "Loris Bennett" <loris.bennett@fu-berlin.de> writes:
>
>> Hi,
>>
>> Is it possible to pass a variable to a source block such that the
>> variable can be used as part of the name of the output file?
>>
>> Currently I have
>>
>> #+HEADER: :var data=timelimit-elapsed-data year=2011 :colnames yes
>> #+HEADER: :session *r* :file (org-babel-temp-file "time-elapsed-" ".pdf")
>>
>> which gets me a different name for each value of 'year', but ideally I
>> would like the files to be called
>>
>> time-elapsed-2011.pdf
>> time-elapsed-2012.pdf
>> time-elapsed-2013.pdf
>>
>> etc.
>>
>> Can this be done? 
>
>
> Maybe not what you are looking for, but you could handle the assembly of
> the filename within your code block.
>
> Something like:
>
> #+HEADER: :var year=2011 :session *r* :results file
> #+begin_src R
>   filename <- paste0("time-elapsed-", year, ".pdf")
>   
>   pdf(filename)
>     ## your code
>   dev.off()
>   
>   filename
> #+end_src
>
> Regards,
> Andreas

Thanks, that is in fact exactly what I need.  Looking at the
documentation again, I see that it says:

"Some languages including R, gnuplot, dot, and ditaa provide special
handling of the :file header argument automatically wrapping the code
block body in the boilerplate code required to save output to the
specified file. This is often useful for saving graphical output of a
code block to the specified file."

I just didn't understand this at first.  Maybe the following sentence
should/could be added:

"... the specified file.  This means that the argument of the :file
header can be omitted and the file name can be generated within the
source block."

Cheers,

Loris

-- 
This signature is currently under construction.

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

end of thread, other threads:[~2013-06-28  6:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-27 12:55 Variable in file name for babel output? Loris Bennett
2013-06-27 23:07 ` Andreas Leha
2013-06-28  6:21   ` Loris Bennett

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).