:dirand remote execution
:file header argument can be used to specify the path to the
:dir specifies the default directory during ‘src’
code block execution. If it is absent, then the directory associated with
the current buffer is used. In other words, supplying
temporarily has the same effect as changing the current directory with
M-x cd path <RET>, and then not supplying
:dir. Under the
:dir simply sets the value of the Emacs variable
:dir, relative paths (for example,
: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
To evaluate the ‘src’ code block on a remote machine, supply a remote s directory name using ‘Tramp’ syntax. For example:
#+BEGIN_SRC R :file plot.png :dir /scp:firstname.lastname@example.org: 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
default-directory, as illustrated here:
:diris used with
:session, Org sets the starting directory for a new session. But Org will not alter the directory of an already existing session.
:exports resultsor with
:exports bothto avoid Org inserting incorrect links to remote files. That is because Org does not expand
default directoryto avoid some underlying portability issues.