From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Charles C. Berry" Subject: Re: [PATCH] -for review- Tangling with variable transfer of variables Date: Mon, 23 Jun 2014 10:56:05 -0700 Message-ID: References: <87zjh8bo8s.fsf@gmail.com> Mime-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-1566834250-1403546165=:341" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43939) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz8TX-0002rM-Ng for emacs-orgmode@gnu.org; Mon, 23 Jun 2014 13:56:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz8TR-0003Fg-3j for emacs-orgmode@gnu.org; Mon, 23 Jun 2014 13:56:15 -0400 Received: from iport-bcv1-out.ucsd.edu ([132.239.0.119]:22214) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz8TQ-0003FE-Ld for emacs-orgmode@gnu.org; Mon, 23 Jun 2014 13:56:09 -0400 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rainer M Krug Cc: emacs-orgmode@gnu.org, Eric Schulte This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --0-1566834250-1403546165=:341 Content-Type: TEXT/PLAIN; charset=utf-8; format=flowed Content-Transfer-Encoding: 8BIT On Mon, 23 Jun 2014, Rainer M Krug wrote: > One more question concerning the variable transfer of tables: > > ,---- > | (let ((file (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))) > | (header (if (or (eq (nth 1 value) 'hline) colnames-p) > | "TRUE" "FALSE")) > | (row-names (if rownames-p "1" "NULL"))) > | (if (= max min) > | (format "%s <- local({ > | con <- textConnection( > | %S > | ) > | res <- read.table( > | con, > | header = %s, > | row.names = %s, > | sep = \"\\t\", > | as.is = TRUE > | ) > | close(con) > | res > | })" name file header row-names) > | (format "%s <- local({ > | con <- textConnection( > | %S > | ) > | res <- read.table( > | con, > | header = %s, > | row.names = %s, > | sep = \"\\t\", > | as.is = TRUE, > | fill = TRUE, > | col.names = paste(\"V\", seq_len(%d), sep =\"\") > | ) > | close(con) > | res > | })" name file header row-names max)))) > `---- > > It seems that the two variable transfer routines only differ slightly: > > 1. routine: =header= is present (TRUE) and defined in table when passed > as =colnames= while > > 2. routine: =header= is not present (FALSE) and =colnames= is generated > as V1 .. Vn > > This generation is actually not needed as this is the R default value > which is used when =colnames= is not supplied. > > Also: I do not undestand why the argument =fill= is TRUE in the second > routine. From R: > > ,---- > | fill: logical. If ‘TRUE’ then in case the rows have unequal length, > | blank fields are implicitly added. See ‘Details’. > `---- > > If I understands tables in org correctly, this is not needed as the rows > always have equal length? > > so if I am not mistaken the following lines could be deleted: > > ,---- > | row.names = %s, > | sep = \"\\t\", > | as.is = TRUE, > | - fill = TRUE, > | - col.names = paste(\"V\", seq_len(%d), sep =\"\") > `---- > > Or am I missing something here? You need not pass a table - this #+BEGIN_SRC R :var x='(1 2 3)(4 5)) will produce a data.frame with two rows with is.na(x[2,2]) being TRUE. Re col.names, from help("read.table") The number of data columns is determined by looking at the first five lines of input (or the whole file if it has less than five lines), or from the length of 'col.names' if it is specified and is longer. This could conceivably be wrong if 'fill' or 'blank.lines.skip' are true, so specify 'col.names' if necessary (as in the 'Examples'). This block #+BEGIN_SRC R :var x=(append (make-vector 10 '(1 2)) '((1 2 3))) x #+END_SRC makes an 11 by 3 data.frame with all(is.na(x[,1:10])) but taking away the col.names arg will cause it to make a 12 by 2 data.frame with x[12,1]==3 and is.na(x[12,2]). so leave the col.names as is, I think. Without fill, read.table will throw an error in that block Chuck [rest deleted] --0-1566834250-1403546165=:341--