UP | HOME

Org-babel: Uses

Table of Contents

ascii package

ascii package (available on CRAN) creates appropriate plain text representations of many R objects, and features an option to specify that the plain text representations should be in Org format (as well as asciidoc, txt2tags, restructuredtext and textile). This can be particularly useful for retrieving non-tabular R data structures in Org.

babel using ascii

First, (install), load ascii package and set org as the default output:

library(ascii)
options(asciiType="org")
Le chargement a nécessité le package : proto

Then, use ascii function:

ascii(summary(table(1:4, 1:4)))
  • Number of cases in table: 4
  • Number of factors: 2
  • Test for independence of all factors:
    • Chisq = 12, df = 9, p-value = 0.2133
    • Chi-squared approximation may be incorrect
counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12)
outcome <- gl(3, 1, 9)
treatment <- gl(3, 3)
d.AD <- data.frame(treatment, outcome, counts)
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())
ascii(glm.D93)
EstimateStd. Errorz valuePr(> | z | )
(Intercept)3.040.1717.810.00
outcome2-0.450.20-2.250.02
outcome3-0.290.19-1.520.13
treatment20.000.200.001.00
treatment30.000.200.001.00
ascii(anova(glm.D93))
DfDevianceResid. DfResid. Dev
NULL8.0010.58
outcome2.005.456.005.13
treatment2.000.004.005.13
ascii(sessionInfo())
R version
R version 2.11.0 (2010-04-22), i486-pc-linux-gnu
locale
LC_CTYPE=fr_FR.utf8, LC_NUMERIC=C, LC_TIME=fr_FR.utf8, LC_COLLATE=fr_FR.utf8, LC_MONETARY=C, LC_MESSAGES=fr_FR.utf8, LC_PAPER=fr_FR.utf8, LC_NAME=C, LC_ADDRESS=C, LC_TELEPHONE=C, LC_MEASUREMENT=fr_FR.utf8, LC_IDENTIFICATION=C
attached base packages
stats, graphics, grDevices, utils, datasets, methods, base
other attached packages
ascii_0.6-3, proto_0.3-8

With Sweave

ascii package provides a Sweave driver for org markup.

When using Sweave, just replace RweaveLatex driver by RweaveOrg:

 Sweave("yourfile.Rnw", driver = RweaveOrg)

Bug

Cell spanning

I am not an org guru, but as much I can know, org doesn't support row or col spanning. l/r/t/bgroup options of ascii function are ignored in org output, and some of these examples will not produce the expected results.