emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rainer M Krug <Rainer@krugs.de>
To: "Charles C. Berry" <ccberry@ucsd.edu>
Cc: emacs-orgmode@gnu.org, Eric Schulte <schulte.eric@gmail.com>
Subject: Re: [PATCH] -for review- Tangling with variable transfer of variables
Date: Tue, 24 Jun 2014 14:08:36 +0200	[thread overview]
Message-ID: <m21tueldbv.fsf@krugs.de> (raw)
In-Reply-To: <alpine.OSX.2.00.1406231020550.341@charles-berrys-macbook.local> (Charles C. Berry's message of "Mon, 23 Jun 2014 10:56:05 -0700")

[-- Attachment #1: Type: text/plain, Size: 4680 bytes --]

"Charles C. Berry" <ccberry@ucsd.edu> writes:

> 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))

I always forget that there are other objects wich can be passed from org
to R.

>
> 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.

I will - promised.
 
>
> Without fill, read.table will throw an error in that block

This is true for these cases - I was only thinking about tables which
can be passed to R

Thanks,

Rainer

>
> Chuck
>
> [rest deleted]
>

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug

PGP: 0x0F52F982

[-- Attachment #2: Type: application/pgp-signature, Size: 494 bytes --]

  reply	other threads:[~2014-06-24 12:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-19 20:19 [PATCH] -for review- Tangling with variable transfer of variables Rainer M Krug
2014-06-19 21:09 ` Aaron Ecay
2014-06-19 23:23   ` Charles Berry
2014-06-20 13:15     ` Rainer M Krug
2014-06-20 20:34       ` Rainer M Krug
2014-06-21 19:44         ` Charles C. Berry
2014-06-22  3:39           ` Aaron Ecay
2014-06-23 10:46             ` Rainer M Krug
2014-06-23  8:57           ` Rainer M Krug
2014-06-23  9:14           ` Rainer M Krug
2014-06-23 17:56             ` Charles C. Berry
2014-06-24 12:08               ` Rainer M Krug [this message]
2014-06-23 10:45           ` Rainer M Krug
2014-06-23 18:25             ` Charles C. Berry
2014-06-24 12:28               ` Rainer M Krug
2014-06-20 13:07   ` Rainer M Krug

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m21tueldbv.fsf@krugs.de \
    --to=rainer@krugs.de \
    --cc=ccberry@ucsd.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=schulte.eric@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).