more opining about R tables
This commit is contained in:
parent
3e403fc9bb
commit
a9bb21865d
|
@ -33,6 +33,23 @@
|
|||
|
||||
(litorgy-add-interpreter "R")
|
||||
|
||||
(defvar litorgy-R-var-name "litorgy_R_variable")
|
||||
|
||||
(defvar litorgy-R-var-as-table
|
||||
"write.org.table <- function (x, write.rownames = TRUE)
|
||||
{
|
||||
if(!is.null(dim(x)) && length(dim(x)) > 2)
|
||||
stop(\"Object must be 1- or 2-dimensional\") ;
|
||||
if(is.vector(x) || is.table(x) || is.factor(x) || is.array(x))
|
||||
x <- as.matrix(x) ;
|
||||
if(!(is.matrix(x) || inherits(x, c('matrix', 'data.frame')))) {
|
||||
invisible() ;
|
||||
print(x) ;
|
||||
stop(\"Object not recognised as 1- or 2-dimensional\") ;
|
||||
} ;
|
||||
x
|
||||
}")
|
||||
|
||||
(defun litorgy-execute:R (body params)
|
||||
"Execute a block of R code with litorgy. This function is
|
||||
called by `litorgy-execute-src-block'."
|
||||
|
@ -48,6 +65,28 @@ called by `litorgy-execute-src-block'."
|
|||
(litorgy-R-initiate-R-buffer)
|
||||
(litorgy-R-command-to-string body))))
|
||||
|
||||
(defun litorgy-R-table-or-scalar (var-name)
|
||||
"Determine whether the variable in `litorgy-R-buffer' named
|
||||
VAR-NAME has any associated dimensions. If it does have
|
||||
dimensions then return it as a list, otherwise just read it as a
|
||||
single variable."
|
||||
(if (litorgy-R-multidimensional-p var-name)
|
||||
(litorgy-R-vecotr-to-elisp-list var-name)
|
||||
(read result)))
|
||||
|
||||
(defun litorgy-R-multidimensional-p (var-name)
|
||||
"Return t if the variable named VAR-NAME in `litorgy-R-buffer'
|
||||
is multidimensional."
|
||||
|
||||
)
|
||||
|
||||
(defun litorgy-R-vector-to-elisp-list (var-name)
|
||||
"Assumes that var-name is multidimensional in which case it
|
||||
then converts it's value into an Emacs-lisp list which is
|
||||
returned."
|
||||
|
||||
)
|
||||
|
||||
;; functions for evaluation of R code
|
||||
(defvar litorgy-R-buffer nil
|
||||
"Holds the buffer for the current R process")
|
||||
|
|
21
rorg.org
21
rorg.org
|
@ -31,6 +31,27 @@ options (maybe more)
|
|||
This is now implemented see the example in the [[* silent evaluation][sandbox]]
|
||||
|
||||
** TODO insert 2-D R results as tables
|
||||
everything is working but R and shell
|
||||
|
||||
*** TODO shells
|
||||
|
||||
*** TODO R
|
||||
|
||||
This has already been tackled by Dan in [[file:existing_tools/org-R.el::defconst%20org%20R%20write%20org%20table%20def][org-R:check-dimensions]]. The
|
||||
functions there should be useful in combination with [[http://cran.r-project.org/doc/manuals/R-data.html#Export-to-text-files][R-export-to-csv]]
|
||||
as a means of converting multidimensional R objects to emacs lisp.
|
||||
|
||||
It may be as simple as first checking if the data is multidimensional,
|
||||
and then, if so using =write= to write the data out to a temporary
|
||||
file from which emacs can read the data in using =org-table-import=.
|
||||
|
||||
Looking into this further, is seems that there is no such thing as a
|
||||
scalar in R [[http://tolstoy.newcastle.edu.au/R/help/03a/3733.html][R-scalar-vs-vector]]. In that light I am not sure how to
|
||||
deal with trivial vectors (scalars) in R. I'm tempted to just treat
|
||||
them as vectors, but then that would lead to a proliferation of
|
||||
trivial 1-cell tables...
|
||||
|
||||
|
||||
** TODO allow variable initialization from source blocks
|
||||
Currently it is possible to initialize a variable from an org-mode
|
||||
table with a block argument like =table=sandbox= (note that the
|
||||
|
|
Loading…
Reference in New Issue