From 0c68fce725d0c362db6f2472aeeab9898e2c213a Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 17 May 2009 20:42:04 -0400 Subject: [PATCH] Proposals for some minor reworkings of litorgy-R.el code added to rorg.org and as comments in litorgy-R.el --- examples.org | 30 ++---------------------------- litorgy/litorgy-R.el | 10 ++++++++-- rorg.org | 21 ++++++++++++++++++--- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/examples.org b/examples.org index 3ad94402d..6c9383efc 100644 --- a/examples.org +++ b/examples.org @@ -11,23 +11,10 @@ labeled directory-pie and press =\C-c\C-c=. #+srcname: directories #+begin_src bash :results replace -du -sc * |grep -v total +du -sc * |grep -v total | head -n 1 #+end_src -| 4 | "block" | -| 36 | "COPYING" | -| 4 | "#dan-notes.org#" | -| 4 | "#examples.org#" | -| 4 | "examples.org" | -| 256 | "existing_tools" | -| 4 | "intro.org" | -| 144 | "litorgy" | -| 4 | "README.markdown" | -| 12 | "rorg.html" | -| 68 | "#rorg.org#" | -| 68 | "rorg.org" | -| 8 | "test-export.html" | -| 4 | "test-export.org" | +| 4 | "block" | [Eric] I sometimes get weird results here, where R will import the labels into the third column instead of the second. I don't entirely @@ -38,16 +25,3 @@ trust the R table importing mechanisms so far. pie(dirs[,1], labels = dirs[,2]) #+end_src -| 4 | "block" | -| 36 | "COPYING" | -| 4 | "dan-notes.org" | -| 4 | "#examples.org#" | -| 4 | "examples.org" | -| 256 | "existing_tools" | -| 4 | "intro.org" | -| 140 | "litorgy" | -| 4 | "README.markdown" | -| 12 | "rorg.html" | -| 68 | "rorg.org" | -| 8 | "test-export.html" | -| 4 | "test-export.org" | diff --git a/litorgy/litorgy-R.el b/litorgy/litorgy-R.el index ede3576de..1bb67f318 100644 --- a/litorgy/litorgy-R.el +++ b/litorgy/litorgy-R.el @@ -67,9 +67,13 @@ R process in `litorgy-R-buffer'." cell (format "%S" cell))) row)) value))) (with-temp-file transition-file - (insert (orgtbl-to-tsv value '(:sep "\t" :fmt litorgy-R-quote-tsv-field))) + ;; DED: I think the :sep "\t" is redundant here as + ;; orgtbl-to-tsv adds it automatically? + (insert (orgtbl-to-tsv value '(:sep "\t" :fmt litorgy-R-quote-tsv-field))) (insert "\n")) - (litorgy-R-input-command (format "%s <- read.table(\"%s\", as.is=TRUE)" name transition-file))))) + (litorgy-R-input-command + (format "%s <- read.table(\"%s\", sep=\"\\t\", as.is=TRUE)" name transition-file))))) + (defun litorgy-R-to-elisp (func-name) "Return the result of calling the function named FUNC-NAME in @@ -104,6 +108,8 @@ R process in `litorgy-R-buffer'." (defun litorgy-R-initiate-R-buffer () "If there is not a current R process then create one." + ;; DED: Ideally I think we should use ESS mechanisms for this sort + ;; of thing. See ess-force-buffer-current. (unless (and (buffer-live-p litorgy-R-buffer) (get-buffer litorgy-R-buffer)) (save-excursion (R) diff --git a/rorg.org b/rorg.org index 118cc2f1d..db0406342 100644 --- a/rorg.org +++ b/rorg.org @@ -4,8 +4,23 @@ #+STARTUP: oddeven * Tasks [8/19] +** PROPOSED use textConnection to pass tsv to R? + When passing args from the org buffer to R, the following route is + used: arg in buffer -> elisp -> tsv on file -> data frame in R. I + think it would be possible to avoid having to write to file by + constructing an R expression in litorgy-R-assign-elisp, something + like this +#+begin_src emacs-lisp +(litorgy-R-input-command + (format "%s <- read.table(textConnection(\"%s\"), sep=\"\\t\", as.is=TRUE)" + name (orgtbl-to-tsv value '(:sep "\t" :fmt litorgy-R-quote-tsv-field)))) +#+end_src + + I haven't tried to implement this yet as it's basically just + fiddling with something that works. The only reason for it I can + think of would be efficiency and I haven't tested that. ** PROPOSED re-implement R evaluation using ess-command or ess-execute - I can't see anything wrong with the current R evaluation code or + I don't have any complaints with the current R evaluation code or behaviour, but I think it would be good to use the ESS functions from a political point of view. Plus of course it has the normal benefits of an API (insulates us from any underlying changes etc). [DED] @@ -613,11 +628,11 @@ Time.now #+begin_src R :results replace a <- 9 -b <- 14 +b <- 16 a + b #+end_src -: 23 +: 25 #+begin_src R hist(rgamma(20,3,3))