to allow evaluating R code, evaluate this source block by putting point inside and typing [C-c C-c] (control C followed by control C) and giving permission for it to be evaluated.
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t) (R . t)))
to allow editing R code, evaluate this source block, etc.
(require 'ess-r-mode)
A source block can be evaluated, exported, “tangled”, edited
## only the code here is exported
if (TRUE) {
cat("we did this!\n")
}
rnorm(7)
- the output of one source block can be used as input to another
## here, both the code and the results are exported
summary(avector)
Min. :-1.0295 |
1st Qu.:-0.6115 |
Median :-0.4063 |
Mean :-0.4120 |
3rd Qu.:-0.1716 |
Max. : 0.1181 |
- enter
[C-c C-e C-s h o]
and give permission to evaluate the code blocks, to open a web browser on an export of just this subtree.
value versus output
cat("42\n")
invisible(23)
cat("42\n")
invisible(23)
what kind of result? here, a graphic file (named by the :file
header argument).
## from "?graphics::plot"
Speed <- cars$speed
Distance <- cars$dist
plot(Speed, Distance, panel.first = grid(8, 8),
pch = 0, cex = 1.2, col = "blue")
plot(Speed, Distance,
panel.first = lines(stats::lowess(Speed, Distance), lty = "dashed"),
pch = 0, cex = 1.2, col = "blue")
([C-c C-o] to open)
## this will run in a session
demo <- function(a) {
2*a
}