diff --git a/existing_tools/exp-blocks/example-for-r.html b/existing_tools/exp-blocks/example-for-r.html new file mode 100644 index 000000000..285428a3e --- /dev/null +++ b/existing_tools/exp-blocks/example-for-r.html @@ -0,0 +1,90 @@ + + + +a <- 3 + + + + + + + +

a <- 3

+ + +
+
+> a
+
+
+ + +

Author: Eric Schulte +<schulte.eric@gmail.com> +

+

Date: 2009-02-05 15:26:32 PST

+

HTML generated by org-mode 6.20f in emacs 23

+
+ diff --git a/existing_tools/exp-blocks/example-for-r.org b/existing_tools/exp-blocks/example-for-r.org new file mode 100644 index 000000000..fcadb4fd8 --- /dev/null +++ b/existing_tools/exp-blocks/example-for-r.org @@ -0,0 +1,12 @@ +#+BEGIN_R +a <- 3 +a +#+END_R + +- the value of a is \R{a} +- the value of a + 3 is \R{a + 3} + +#+BEGIN_R hidden_block, echo=FALSE, results=HIDE + a <- 3 + b <- 6 +#+END_R diff --git a/existing_tools/org-exp-blocks.el b/existing_tools/exp-blocks/org-exp-blocks.el similarity index 98% rename from existing_tools/org-exp-blocks.el rename to existing_tools/exp-blocks/org-exp-blocks.el index b4e72412d..25386701e 100644 --- a/existing_tools/org-exp-blocks.el +++ b/existing_tools/exp-blocks/org-exp-blocks.el @@ -80,8 +80,10 @@ Each block export function should accept three argumets..." :type 'alist) (defcustom org-export-interblocks - '((r org-export-interblocks-format-R) - (R org-export-interblocks-format-R)) + '( + (r org-export-interblocks-format-R) + (R org-export-interblocks-format-R) + ) "Use this a-list to associate block types with block exporting functions. The type of a block is determined by the text immediately following the '#+BEGIN_' portion of the block header. @@ -316,8 +318,9 @@ export." (goto-char start) (interblock-initiate-R-buffer) (let (code replacement) - (while (and (< (point) end) (re-search-forward "\\\\R{\\(.*\\)}" end t)) + (while (and (< (point) end) (re-search-forward "\\\\R{\\([^}]*\\)}" end t)) (save-match-data (setf code (match-string 1))) + (message (format "\R{%s}" code)) (setf replacement (interblock-R-command-to-string code)) (setf replacement (cond (htmlp replacement) diff --git a/existing_tools/exp-blocks/running.el b/existing_tools/exp-blocks/running.el new file mode 100644 index 000000000..3d75f34c0 --- /dev/null +++ b/existing_tools/exp-blocks/running.el @@ -0,0 +1,9 @@ +(load "org-exp-blocks.el") + +(defun org-exp-preprocess () + "This is a simple helper to preprocess a file without actually +exporting to html or latex. Useful for debugging." + (interactive) + (let ((htmlp t)) + (org-export-blocks-preprocess))) + diff --git a/existing_tools/exp-blocks/testing.Rorg b/existing_tools/exp-blocks/testing.Rorg new file mode 100644 index 000000000..19422e830 --- /dev/null +++ b/existing_tools/exp-blocks/testing.Rorg @@ -0,0 +1,73 @@ +# -*- mode: org -*- +#+OPTIONS: LaTeX:t + +* Sweave and org-mode + If you're reading a PDF version of this document, you should also + look at [[file:testing.Rorg][testing.Rorg]] (the source file) and [[file:testing.org][testing.org]] (the output + of the Sweave process). + + Keep in mind that one of the advantages of a block-based approach is + using \texttt{C-'} to edit code in its native mode. + +** Use the Sweave package for latex formatting + Org allows us to issue commands to be included in \{LaTeX} export. +#+LATEX_HEADER \usepackage{Sweave} + +** R blocks + The first argument to an R block when using Sweave is the label for + that block. + + Not all R blocks are printed. Sweave options allow the printing of + the evaluated code, the output of the code, both, or neither. + +*** R code that is not printed +#+BEGIN_R hidden_block, echo=FALSE, results=HIDE + a <- 3 + b <- 6 +#+END_R + +*** R code that is printed +#+BEGIN_R visible_block + c <- 4 +#+END_R + + We can use block labels to embed blocks by reference (even if they + weren't printed before). +*** R code that references other blocks +#+BEGIN_R combined_block +#+R_CODEREF: hidden_block +#+R_CODEREF: visible_block + a + b +c +#+END_R + +** Inline references to R data + We can evaluate R code inline. +*** Used in text + The value of =a= is 3. + +*** Used in a table + | a | b | c | TOTAL | + |-------+-------+-------+---------------| + | \R{a} | \R{b} | \R{c} | \R{a + b + c} | + +** Single-line R commands + If we want a line of R code to be evaluated but not printed, + there's a convenient shorthand. This only works for single lines + of R code, but you can have more than one in a row. +#+R library(lattice) +#+R data(cars) + +** Graphics + We use values defined elsewhere in the buffer to produce this + graph. The new CAPTION and LABEL arguments work just fine. + +#+CAPTION: speed by distance +#+LABEL: fig:speed_by_distance +#+BEGIN_R figure.eps +print(xyplot(speed ~ dist, cars, + panel = function (x, y, ...) { + panel.xyplot(x, y, ...) + panel.abline(h=a) + panel.abline(v=b) + })) +#+END_R diff --git a/existing_tools/exp-blocks/testing.html b/existing_tools/exp-blocks/testing.html new file mode 100644 index 000000000..759a2544d --- /dev/null +++ b/existing_tools/exp-blocks/testing.html @@ -0,0 +1,276 @@ + + + +testing + + + + + + + +

testing

+ + +
+

Table of Contents

+
+ +
+
+ +
+

1 Sweave and org-mode

+
+ +

If you're reading a PDF version of this document, you should also +look at testing.Rorg (the source file) and testing.org (the output +of the Sweave process). +

+

+Keep in mind that one of the advantages of a block-based approach is +using \texttt{C-'} to edit code in its native mode. +

+ +
+ +
+

1.1 Use the Sweave package for latex formatting

+
+ +

Org allows us to issue commands to be included in \{LaTeX} export. +

+
+ +
+ +
+

1.2 R blocks

+
+ +

The first argument to an R block when using Sweave is the label for +that block. +

+

+Not all R blocks are printed. Sweave options allow the printing of +the evaluated code, the output of the code, both, or neither. +

+ +
+ +
+

1.2.1 R code that is not printed

+
+ + + + +
+
+>    a <- 3
+>    b <- 6
+
+
+ +
+ +
+ +
+

1.2.2 R code that is printed

+
+ + + + +
+
+>    c <- 4
+
+
+ +

+We can use block labels to embed blocks by reference (even if they +weren't printed before). +

+ +
+ +
+

1.2.3 R code that references other blocks

+
+ + + + +
+
+> #+R_CODEREF:  hidden_block
+> #+R_CODEREF:  visible_block
+>    a + b +c
+
+
+ +
+
+ +
+ +
+

1.3 Inline references to R data

+
+ +

We can evaluate R code inline. +

+
+ +
+

1.3.1 Used in text

+
+ +

The value of a is 3. +

+
+ +
+ +
+

1.3.2 Used in a table

+
+ + ++ + + + + + +
abcTOTAL
36413
+ + +
+
+ +
+ +
+

1.4 Single-line R commands

+
+ +

If we want a line of R code to be evaluated but not printed, +there's a convenient shorthand. This only works for single lines +of R code, but you can have more than one in a row. +

+
+ +
+ +
+

1.5 Graphics

+
+ +

We use values defined elsewhere in the buffer to produce this +graph. The new CAPTION and LABEL arguments work just fine. +

+ + + +
+
+> print(xyplot(speed ~ dist, cars,
+>        panel = function (x, y, ...) {
+>          panel.xyplot(x, y, ...)
+>          panel.abline(h=a)
+>          panel.abline(v=b)
+>        }))
+
+
+

+file:e.eps +

+
+
+

Author: Eric Schulte +<schulte.eric@gmail.com> +

+

Date: 2009-02-05 15:41:29 PST

+

HTML generated by org-mode 6.20f in emacs 23

+
+ diff --git a/rorg.org b/rorg.org index 6a6ee01af..ed8494a47 100644 --- a/rorg.org +++ b/rorg.org @@ -58,7 +58,30 @@ a ** evaluate R code and make the output available for processing in an org buffer ** evaluate R code and format the output for export +Special editing and evaluation of source code in R blocks. +Unfortunately org-mode how two different block types. Source code +blocks which look like the following allow for the special editing of +code inside of the block through `org-edit-special'. + +#+begin_src R + +#+end_src + +dblocks, which look like the following allow for evaluation of the +code inside of the block by calling =\C-c\C-c= on the header of the +block. This is handy, as org-mode will automatically call +`org-dblock-write:dblock-type' where dblock-type is the string +following the =#+BEGIN:= portion of the line. + +#+BEGIN: dblock-type +#+END: + +Note that upper and lower case are not relevant in block headings. + +I'm leaning towards using the =#+begin_src= blocks, as that is really +what these blocks contain is source code. * tasks - +* buffer dictionary + LocalWords: DBlocks dblocks