emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: tsd@tsdye.com (Thomas S. Dye)
To: Michael Hannon <jm_hannon@yahoo.com>
Cc: Org-Mode List <emacs-orgmode@gnu.org>,
	Eric Schulte <eric.schulte@gmx.com>
Subject: Re: Babel: communicating irregular data to R source-code block
Date: Tue, 24 Apr 2012 09:23:17 -1000	[thread overview]
Message-ID: <m17gx5x7bu.fsf@tsdye.com> (raw)
In-Reply-To: <m1bomhxd44.fsf@tsdye.com> (Thomas S. Dye's message of "Tue, 24 Apr 2012 07:18:19 -1000")

tsd@tsdye.com (Thomas S. Dye) writes:

> Michael Hannon <jm_hannon@yahoo.com> writes:
>
>> On Monday, April 23, 2012 at 11:44 PM Thomas S. Dye wrote:
>> .
>> .
>> .
>>> The documentation of read.table has this:
>>
>>> 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’).
>>
>>> The example is this:
>>
>>> read.csv(tf, fill = TRUE, header = FALSE,
>>>         col.names = paste("V", seq_len(ncol), sep = ""))
>>
>>> where read.csv is a synonym of read.table with preset arguments.
>>
>>> This explains why the sixth line wraps.
>> .
>> .
>> .
>>
>> Thanks, Tom.  I had just run across this myself. I guess I need to walk a mile
>> in somebody's moccasins before complaining, but this behavior on the part of R
>> seems totally stupid to me.
>>
>> I'm going to have to mull this over some more.
>>
>> -- Mike
>>
>>
> Yes, please do. I'm not a programmer, and often get things wrong, but I
> trust you'll help rein me in if I get off on a tangent. 
>
> It would be good if this limitation in ob-R were eliminated.  The way I
> see it, ob-R is designed to handle a subset of the expected input.  It
> coerces a variable into a tsv table, then reads it into R, expecting all
> cells are filled.  At the same time, other babel modules are free to
> export structures (in the Pascal's triangle example, a list of lists)
> that orgtbl-to-tsv interprets as a table with empty cells.  It would be
> nice if ob-R could be made to read all the tables that orgtbl-to-tsv is
> able to create.
>
> All the best,
> Tom 

Here is about as far as I can go with this.  It appears to work for
tables with or without column heads.  The 6 is still hard-coded.  I
can't find a way to determine the number of columns in VALUE, but assume
there is one.  If the number of columns in VALUE were to replace the
hard-coded 6, this might work.

        (format "%s <- read.table(\"%s\", header=%s, row.names=%s, sep=\"\\t\", as.is=TRUE, fill=TRUE%s)"
                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 (eq (nth 1 value) 'hline) "" ", col.names = paste(\"V\", seq_len(6), sep = \"\")")))

All the best,
Tom
-- 
Thomas S. Dye
http://www.tsdye.com

  reply	other threads:[~2012-04-24 19:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-21 20:17 Babel: communicating irregular data to R source-code block Michael Hannon
2012-04-22  0:44 ` Thomas S. Dye
2012-04-22 15:58   ` Eric Schulte
2012-04-23 16:46     ` Thomas S. Dye
2012-04-23 15:41       ` Eric Schulte
2012-04-23 19:17         ` Thomas S. Dye
2012-04-23 22:24     ` Michael Hannon
2012-04-23 21:05       ` Eric Schulte
2012-04-24  0:23       ` Thomas S. Dye
2012-04-23 22:55         ` Eric Schulte
2012-04-24  6:44           ` Thomas S. Dye
2012-04-24  7:07             ` Michael Hannon
2012-04-24 17:18               ` Thomas S. Dye
2012-04-24 19:23                 ` Thomas S. Dye [this message]
2012-04-25 23:52               ` Thomas S. Dye
2012-04-26  2:06                 ` Michael Hannon
2012-04-26  6:34                   ` Thomas S. Dye

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=m17gx5x7bu.fsf@tsdye.com \
    --to=tsd@tsdye.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=eric.schulte@gmx.com \
    --cc=jm_hannon@yahoo.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).