Aaron Ecay <aaronecay <at> gmail.com> writes: > > Hi Rainer, > > I have not tested the patch (I rarely use :var), but here are some > comments from reading the patch. > [snip] > > > (header (if (or (eq (nth 1 value) 'hline) colnames-p) > > "TRUE" "FALSE")) > > (row-names (if rownames-p "1" "NULL"))) > > (if (= max min) > > - (format "%s <- read.table(\"%s\", > > + (format "%s <- read.table(textConnection('%s'), > > This will fail if ‘file’ contains an apostrophe character. I guess you > need to escape apostrophes in ‘file’. >
There are a bunch of issues with the textConnection - the point Aaron makes, the nasty name (try showConnections() to see), and close()-ing it. I think you need something more like this: ==== (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.object <- %S con <- textConnection(con.object) res <- read.table(con, header=%s, row.names=%s, sep=\"\\t\", as.is=TRUE) close(con) res})" name file header row-names) ==== Notes: %S handles Aaron's quoting issue. local() keeps unwanted objects out of user's way. This worked on a couple of simple tests If you have `:session :results output' headers your session transcript will have `file' dumped into it, which might be an annoyance. HTH, Chuck