Org Babel 中 R 不能输出图形

4

我已经尝试了这个页面上的所有四个源代码块: https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-R.html

* does /not/ produce a file
#+begin_src R :file 1.png :results value graphics
library(lattice)
xyplot(1:10 ~ 1:10)
#+end_src
* does produce a file, by printing object
#+begin_src R :file 2.png :results value graphics
library(lattice)
print(xyplot(1:10 ~ 1:10))
#+end_src
* does produce a file, by using :results output
#+begin_src R :file 3.png :results output graphics
library(lattice)
xyplot(1:10 ~ 1:10)
#+end_src
* does produce a file, by evaluating in :session
#+begin_src R :file 4.png :session :results graphics
library(lattice)
xyplot(1:10 ~ 1:10)
#+end_src

所有这些都没有输出任何东西,尽管图像仍然保存为1.png、2.png等。

我肯定已启用R,因为我已经用它做了其他不需要可视化的事情。

2个回答

7

我也遇到过同样的问题,非常令人沮丧。malcook给出的答案基本上解决了这个问题。在9.3版本的org-mode中有一个重大变化,头文件必须包含:results output graphics file,而以前不需要file。以下是org-mode 9.3.2中的一个可工作示例:

#+BEGIN_SRC R :exports both :results output graphics file :file Example9832.png
  library(tidyverse)
  mtcars <- as_tibble(mtcars)
  myplot <-  ggplot(mtcars, aes(x = disp, y = mpg, col = hp, shape = as.factor(cyl))) +
    geom_point() +
    theme_classic() +
    labs(col = "HorsePower", shape = "Cylinders")
  myplot
#+END_SRC

这应该会产生这样的输出:

Org-Babel Ggplot2 示例


1
请运行 meta-x org-version。
它是9.3吗?
那么请参见:版本 9.3 不兼容更改

:文件头参数不再假定“file”:结果对于返回指向文件的链接的代码块,现在强制使用“file”:结果值。:file或:file-ext头参数不再暗示期望“file”结果。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接