组织 8.2.10
Emacs 24.5.1
OSX 10.10.3
#+BEGIN_SRC R
1 + 2
#+END_SRC
#+RESULTS:
: 3
但与
#+BEGIN_SRC R
x <- rnorm(100)
summary(x)
#+END_SRC
#+RESULTS:
“代码块没有输出”
并且 *Messages* 缓冲区包含:
Error reading results: (beginning-of-buffer)
Code block produced no output.
我不确定为什么我没有看到第二个示例的任何输出。它在我机器上的 R 安装中运行 find,
我将非常感谢任何帮助。
最佳答案
添加 :results output
到标题行,例如
#+BEGIN_SRC R :results output
x <- rnorm(100)
summary(x)
#+END_SRC
#+RESULTS:
: Min. 1st Qu. Median Mean 3rd Qu. Max.
: -2.63500 -0.42370 0.02539 0.04136 0.48370 1.92000
组织can capture results from code blocks in two different ways :The following options are mutually exclusive, and specify how the results should be collected from the code block.
value
This is the default. The result is the value of the last statement in the code block. This header argument places the evaluation in functional mode. Note that in some languages, e.g., Python, use of this result type requires that areturn
statement be included in the body of the source code block. E.g.,:results value
.
output
The result is the collection of everything printed to STDOUT during the execution of the code block. This header argument places the evaluation in scripting mode. E.g.,:results output
.
由于您的第一个 block 返回一个常规值,它无需为
:results
指定任何内容即可工作。 , 使用默认 value
环境。你的第二 block returns a value that must be explicitly printed :
The default method returns an object of class
c("summaryDefault", "table")
which has a specialized
R code that returns values with specialized
print
methods must be treated specially in Org (强调我的):If the source code block uses grid-based R graphics, e.g., the lattice and ggplot2 packages, then care must be taken either to print() the graphics object, specify
:results output
, or run the code in a:session
. This is because the graphics functions from lattice and ggplot2 return objects that must be explicitly printed to see them, using the print function. This happens automatically when run interactively, e.g.,:session
, but when called inside another function, it does not. The way:results value
is defined to operate, device and ggplot2 function calls are wrapped in amain
function, and unless the object is specifically printed, no output is produced.
如前所述,显式调用
print
并在 :session
中运行代码是其他可能的解决方案。
关于r - 使用 R 的 org-babel 代码没有输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31099977/