动态计算参数值

Ken*_*ams 8 emacs r org-mode

当我将参数传递给#+begin_src块时,有没有办法动态计算它们?

具体来说,我想将:height属性设置为依赖于我的R代码中的一些变量的东西,如下面的模型:

#+begin_src R
x <- 5
#+end_src

#+begin_src R :results graphics :file foo.svg :height (3*getvar('x'))
...draw picture here
#+end_src
Run Code Online (Sandbox Code Playgroud)

那个getvar()东西,以及那些计算,也许是我的一厢情愿的想法.

ton*_*day 1

Org-mode 现在将标头规范中的括号解释为 elisp,因此您可以在中间使用一些 elisp 来执行此操作:

命名为 R src 块

 #+name: default-height
 #+begin_src R
   x <- 300
 #+end_src

 #+results: default-height
 : 300
Run Code Online (Sandbox Code Playgroud)

将 R 的结果设为 emacs 变量

#+begin_src emacs-lisp :var incoming = default-height :results silent
  (setq dh incoming)
#+end_src
Run Code Online (Sandbox Code Playgroud)

在源块头中使用elisp

#+begin_src R :results graphics :file test.png :height (* dh 3)
  plot(rnorm(100))
#+end_src

#+results:
[[file:test.png]]
Run Code Online (Sandbox Code Playgroud)

对我有用:)