emacs org R源代码块中cat()的输出结果

Output results of cat() in emacs org R source block

我正在尝试获取包含在我的 emacs org 文件中的 cat() 命令的结果。我正在尝试以下

#+BEGIN_SRC R :session *R* :exports results :results replace output raw :eval export
 cat(c("1","2","3"))
#+END_SRC

当我评估时,我什么也没看到。

当我这样做时:

#+BEGIN_SRC R :session *R* :exports results :results replace output raw :eval export
 print(c("1","2","3"))
#+END_SRC

然后评估我得到这个:

#+RESULTS:
[1] "1" "2" "3"

我不能用。

背景:我想在 R 中打印乳胶表的元素,然后将其包含在制表环境中的导出中。我知道存在像 xtable() 这样的函数,但这是最灵活的方法,并且适用于复杂的表格。我已经在 Sweave 中使用 cat() 完成了这项工作,效果很好。

谢谢!

Eric Sc​​hulte 在此处的类似 post 中解决了此问题:

https://lists.gnu.org/archive/html/emacs-orgmode/2013-03/msg01600.html

没有换行符的结果不会被注意到。但是,将换行符放在打印的参数中也很重要,否则结果将包含 R 中下一行的“>”。

所以这有效:

#+BEGIN_SRC R :session *R* :results output raw
  cat(c("1","2","3","\n"))
#+END_SRC

#+RESULTS:
1 2 3