mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-23 18:10:43 +00:00
Removing all support for hlines/colnames -- they persist in branch rowcolnames. Also removing comments.
This commit is contained in:
parent
8ac2a7daa6
commit
f6452b272a
|
@ -62,16 +62,14 @@ R process in `org-babel-R-buffer'."
|
||||||
(unless org-babel-R-buffer (error "No active R buffer"))
|
(unless org-babel-R-buffer (error "No active R buffer"))
|
||||||
(org-babel-R-input-command
|
(org-babel-R-input-command
|
||||||
(if (listp value)
|
(if (listp value)
|
||||||
(let ((transition-file (make-temp-file "org-babel-R-import"))
|
(let ((transition-file (make-temp-file "org-babel-R-import")))
|
||||||
has-header)
|
|
||||||
;; ensure VALUE has an orgtbl structure (depth of at least 2)
|
;; ensure VALUE has an orgtbl structure (depth of at least 2)
|
||||||
(unless (listp (car value)) (setq value (list value)))
|
(unless (listp (car value)) (setq value (list value)))
|
||||||
(setq has-header (and (symbolp (cadr value)) (equal (cadr value) 'hline)))
|
|
||||||
(with-temp-file transition-file
|
(with-temp-file transition-file
|
||||||
(insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field)))
|
(insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field)))
|
||||||
(insert "\n"))
|
(insert "\n"))
|
||||||
(format "%s <- read.table(\"%s\", header=%s, sep=\"\\t\", as.is=TRUE)"
|
(format "%s <- read.table(\"%s\", header=FALSE, sep=\"\\t\", as.is=TRUE)"
|
||||||
name transition-file (if has-header "TRUE" "FALSE")))
|
name transition-file))
|
||||||
(format "%s <- %s" name (org-babel-R-quote-tsv-field value)))))
|
(format "%s <- %s" name (org-babel-R-quote-tsv-field value)))))
|
||||||
|
|
||||||
(defun org-babel-R-to-elisp (func-name)
|
(defun org-babel-R-to-elisp (func-name)
|
||||||
|
@ -79,7 +77,8 @@ R process in `org-babel-R-buffer'."
|
||||||
`org-babel-R-buffer' as Emacs lisp."
|
`org-babel-R-buffer' as Emacs lisp."
|
||||||
(let ((tmp-file (make-temp-file "org-babel-R")) result)
|
(let ((tmp-file (make-temp-file "org-babel-R")) result)
|
||||||
(org-babel-R-input-command
|
(org-babel-R-input-command
|
||||||
(format "write.table(%s(), file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=FALSE, col.names=FALSE, quote=FALSE)"
|
(format
|
||||||
|
"write.table(%s(), file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=FALSE, col.names=FALSE, quote=FALSE)"
|
||||||
func-name tmp-file))
|
func-name tmp-file))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(condition-case nil
|
(condition-case nil
|
||||||
|
@ -88,9 +87,7 @@ R process in `org-babel-R-buffer'."
|
||||||
(delete-file tmp-file)
|
(delete-file tmp-file)
|
||||||
(setq result (mapcar (lambda (row)
|
(setq result (mapcar (lambda (row)
|
||||||
(mapcar #'org-babel-R-read row))
|
(mapcar #'org-babel-R-read row))
|
||||||
(org-table-to-lisp)))
|
(org-table-to-lisp))))
|
||||||
;; (setq result (org-babel-R-set-header-row result))
|
|
||||||
)
|
|
||||||
(error nil))
|
(error nil))
|
||||||
(if (null (cdr result)) ;; if result is trivial vector, then scalarize it
|
(if (null (cdr result)) ;; if result is trivial vector, then scalarize it
|
||||||
(if (consp (car result))
|
(if (consp (car result))
|
||||||
|
@ -100,27 +97,6 @@ R process in `org-babel-R-buffer'."
|
||||||
(car result))
|
(car result))
|
||||||
result))))
|
result))))
|
||||||
|
|
||||||
(defun org-babel-R-set-header-row (table)
|
|
||||||
"Check whether the table appears to have (a) genuine
|
|
||||||
user-supplied column names, or (b) default column names added
|
|
||||||
automatically by R. In case (a), maintain the first row of the
|
|
||||||
table as a header row and insert an hline. In case (b), remove
|
|
||||||
the first row and return the org table without an hline."
|
|
||||||
(if (or (string-equal (caar table) "V1")
|
|
||||||
(string-equal (caar table) "x"))
|
|
||||||
|
|
||||||
;; write.table(1, col.names=TRUE) makes a colname called "x". I
|
|
||||||
;; think shows that this approach is too much of a hack: we
|
|
||||||
;; can't take some totally different action just because we see
|
|
||||||
;; an "x" there that might or might not be a automatic name.
|
|
||||||
|
|
||||||
;; The first row looks like it contains default column names
|
|
||||||
;; added by R. This condition could be improved so that it
|
|
||||||
;; checks whether the first row is ("V1" "V2" ... "V$n") where
|
|
||||||
;; $n is the number of columns.
|
|
||||||
(cdr table)
|
|
||||||
(cons (car table) (cons 'hline (cdr table)))))
|
|
||||||
|
|
||||||
(defun org-babel-R-read (cell)
|
(defun org-babel-R-read (cell)
|
||||||
"Strip nested \"s from around strings in exported R values."
|
"Strip nested \"s from around strings in exported R values."
|
||||||
(org-babel-read (or (and (stringp cell)
|
(org-babel-read (or (and (stringp cell)
|
||||||
|
@ -134,8 +110,6 @@ the first row and return the org table without an hline."
|
||||||
|
|
||||||
(defun org-babel-R-initiate-R-buffer ()
|
(defun org-babel-R-initiate-R-buffer ()
|
||||||
"If there is not a current R process then create one."
|
"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 org-babel-R-buffer) (get-buffer org-babel-R-buffer))
|
(unless (and (buffer-live-p org-babel-R-buffer) (get-buffer org-babel-R-buffer))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(R)
|
(R)
|
||||||
|
|
Loading…
Reference in a new issue