This is the official manual for the latest Org-mode release.

Table of Contents

Next: , Previous: output-dir, Up: Specific header arguments


14.8.2.7 :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 RET, and then not supplying :dir. Under the surface, :dir simply sets the value of the Emacs variable default-directory.

When using :dir, relative paths (for example, :file myfile.jpg or :file results/myfile.jpg) become relative to the default directory.

For example, to save the plot file in the ‘Work’ folder of the home directory (notice tilde is expanded):

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

To evaluate the code block on a remote machine, supply a remote directory name using ‘Tramp’ syntax. For example:

     #+BEGIN_SRC R :file plot.png :dir /dand@yakuba.princeton.edu:
     plot(1:10, main=system("hostname", intern=TRUE))
     #+END_SRC

Org first captures the text results as usual for insertion in the Org file. Then Org also inserts a link to the remote file, thanks to Emacs ‘Tramp’. Org constructs the remote path to the file name from :dir and default-directory, as illustrated here:

     [[file:/scp:dand@yakuba.princeton.edu:/home/dand/plot.png][plot.png]]
Some more warnings