浏览代码

R-based solution to variable-row-length tables

Thomas Dye 13 年之前
父节点
当前提交
870b4e3c9d
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8 2
      lisp/ob-R.el

+ 8 - 2
lisp/ob-R.el

@@ -173,10 +173,16 @@ This function is called by `org-babel-execute-src-block'."
         (with-temp-file transition-file
           (insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field)))
           (insert "\n"))
-        (format "%s <- read.table(\"%s\", header=%s, row.names=%s, sep=\"\\t\", as.is=TRUE)"
+        (format "if (max(count.fields(\"%s\", sep=\"\\t\")) == min(count.fields(\"%s\", sep=\"\\t\"))) %s <- read.table(\"%s\", header=%s, row.names=%s, sep=\"\\t\", as.is=TRUE) else  %s <- read.table(\"%s\", header=%s, row.names=%s, sep=\"\\t\", as.is=TRUE, fill=TRUE, col.names = paste(\"V\", seq_len(max(count.fields(\"%s\", sep=\"\\t\"))), sep =\"\"))"
+		(org-babel-process-file-name transition-file 'noquote)
+		(org-babel-process-file-name transition-file 'noquote)
                 name (org-babel-process-file-name transition-file 'noquote)
 		(if (or (eq (nth 1 value) 'hline) colnames-p) "TRUE" "FALSE")
-		(if rownames-p "1" "NULL")))
+		(if rownames-p "1" "NULL")
+                name (org-babel-process-file-name transition-file 'noquote)
+		(if (or (eq (nth 1 value) 'hline) colnames-p) "TRUE" "FALSE")
+		(if rownames-p "1" "NULL")
+		(org-babel-process-file-name transition-file 'noquote)))
     (format "%s <- %s" name (org-babel-R-quote-tsv-field value))))
 
 (defvar ess-ask-for-ess-directory nil)