Skip to content

Commit

Permalink
add: ESS (kind of) integration
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Jun 4, 2012
1 parent 10cf787 commit 6b55ee5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* ~~add example files and html/pdf/docx exports~~
* ~~add absolute path to examples (as view from two locations)~~
* ~~remove `rapport` dependency~~
* add [ESS](http://ess.r-project.org/) functions
* ~~add [ESS](http://ess.r-project.org/) functions~~
* add: short documentation (or at least mention!): `evals`

## Github pages

Expand Down
11 changes: 11 additions & 0 deletions inst/README.brew
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,14 @@ myReport$export(tempfile())
## You do not want to see the generated report after generation?
myReport$export(open = FALSE)
```

# ESS

I have created some simple LISP functions which would be handy if you are using the best damn IDE for R. These functions and default key-bindings are [shipped with the package](https://github.com/daroczig/pander/tree/master/inst/pander.el), feel free to personalize:

* `pander-brew` (`C-c p b`): Run `Pandoc.brew` on current buffer and show results in *ess-output* while setting working directory to `tempdir()` temporary.
* `pander-brew-to-HTML` (`C-c p B`): Like the above function but exporting results to HTML too (and opening that automatically in default browser).
* `pander-evals-region` (`C-c p e`): Run `evals` on region and show results in *ess-output* while setting working directory to `tempdir()` temporary.
* `pander-region` (`C-c p r`): Run `pander` (after `eval`) on region and show results in *ess-output* while setting working directory to `tempdir()` temporary.

These functions are rather a POC of what could be done with `pander` to speed up writing reports, but having great potentials - and besides that: doing a great job right now too (for me).
4 changes: 2 additions & 2 deletions inst/examples/minimal.brew
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ For example `mtcars`'s first 5 cases look like:

As you can see some formatting was added to the returned table and was also split up as the original table would have been too wide.

We could try other R objects too, for example `prcomp` on `iris`:
We could try other R objects too, for example let us check `chisq.test` on some variables of `mtcars`:

<%=prcomp(iris[, 1:4])%>
<%=chisq.test(mtcars$am, mtcars$gear)%>

## Returning plot

Expand Down
42 changes: 42 additions & 0 deletions pander.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(defun pander-brew ()
"Run Pandoc.brew on current buffer and show results in *ess-output* while setting working directory to tempdir() temporary."
(interactive)
(ess-execute (format "require(pander);wd<-getwd();setwd(tempdir());Pandoc.brew(\"%s\");setwd(wd)\n" buffer-file-name))
)

(defun pander-brew-to-HTML ()
"Run Pandoc.brew on current buffer and export results in HTML. Also tries to open that automatically in default browser."
(interactive)
(ess-command (format "require(pander);wd<-getwd();setwd(tempdir());Pandoc.brew(\"%s\", output = tempfile(), convert = 'html');setwd(wd)\n" buffer-file-name))
)

(defun pander-evals-region ()
"Run evals on region and show results in *ess-output* while setting working directory to tempdir() temporary."
(interactive)
(if mark-active
(let (
(selection (buffer-substring-no-properties (region-beginning) (region-end))))
(if (= (length selection) 0)
(message "Nothing to pass to evals.")
(ess-execute (format "require(pander);wd<-getwd();setwd(tempdir());evals(\"%s\");setwd(wd)\n" selection)))
)
(error "mark not active"))
)

(defun pander-region ()
"Run pander (after eval) on region and show results in *ess-output* while setting working directory to tempdir() temporary."
(interactive)
(if mark-active
(let (
(selection (buffer-substring-no-properties (region-beginning) (region-end))))
(if (= (length selection) 0)
(message "Nothing to pass to evals.")
(ess-execute (format "require(pander);wd<-getwd();setwd(tempdir());pander(evals(\"%s\")[[1]]);setwd(wd)\n" selection)))
)
(error "mark not active"))
)

(global-set-key (kbd "C-c p b") 'pander-brew)
(global-set-key (kbd "C-c p B") 'pander-brew-to-HTML)
(global-set-key (kbd "C-c p e") 'pander-evals-region)
(global-set-key (kbd "C-c p r") 'pander-region)

0 comments on commit 6b55ee5

Please sign in to comment.