- publishing free software manuals
The Org Mode 7 Reference Manual
by Carsten Dominik and others
Paperback (6"x9"), 282 pages
ISBN 9781906966089
RRP £9.95 ($14.95)

Sales of this book support the Org project! Get a printed copy>>>

14.8.2.4 :dir and remote execution

While the :file header argument can be used to specify the path to the output file, :dir specifies the default directory during code block execution. If it is absent, then the directory associated with the current buffer is used. In other words, supplying :dir path temporarily has the same effect as changing the current directory with M-x cd path, and then not supplying :dir. Under the surface, :dir simply sets the value of the Emacs variable default-directory.

When using :dir, you should supply a relative path for file output (e.g. :file myfile.jpg or :file results/myfile.jpg) in which case that path will be interpreted relative to the default directory.

In other words, if you want your plot to go into a folder called ‘Work’ in your home directory, you could use

#+begin_src R :file myplot.png :dir ~/Work
matplot(matrix(rnorm(100), 10), type="l")
#+end_src

Remote execution

A directory on a remote machine can be specified using tramp file syntax, in which case the code will be evaluated on the remote machine. An example is

#+begin_src R :file plot.png :dir /dand@example.edu:
plot(1:10, main=system("hostname", intern=TRUE))
#+end_src

Text results will be returned to the local Org-mode buffer as usual, and file output will be created on the remote machine with relative paths interpreted relative to the remote directory. An Org-mode link to the remote file will be created.

So, in the above example a plot will be created on the remote machine, and a link of the following form will be inserted in the org buffer:

[[file:/scp:dand@example.edu:/home/dand/plot.png][plot.png]]

Most of this functionality follows immediately from the fact that :dir sets the value of the Emacs variable default-directory, thanks to tramp. Those using XEmacs, or GNU Emacs prior to version 23 may need to install tramp separately in order for these features to work correctly.

Further points

ISBN 9781906966089The Org Mode 7 Reference ManualSee the print edition