[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] [PATCH] -for review- Tangling with variable transfer of variable
From: |
Rainer M Krug |
Subject: |
Re: [O] [PATCH] -for review- Tangling with variable transfer of variables |
Date: |
Mon, 23 Jun 2014 11:14:59 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) |
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?
Cheers,
Rainer
"Charles C. Berry" <address@hidden> writes:
> On Fri, 20 Jun 2014, Rainer M Krug wrote:
>
>> Attached please find =the reworked patch.
>>
>> 1) uses local() and closes connection
>> 2) does not leave a variable cal;led file behind
>>
>
> Seems to work on a few test cases.
>
> I'd move the strings to defconsts.
>
> Putting a newline before each `%S' will outdent the first line of
> :var value when it is echoed in the session log so it will be easier to
> view.
>
> ===
>
> With Eric's input on this:
>
> Would you also change this at the end of org-babel-R-assign-elisp:
>
> res})" name file header row-names max))))
> - (format "%s <- %s" name (org-babel-R-quote-tsv-field value))))
> + (format "%s <- %S" name
> + (if (stringp value) value (prin1-to-string value)))))
>
> ??
>
> I think this is innocuous for plain strings with no internal quotes, but
> allows almost anything to be passed to R as a string.
>
> So
> :var x=[1 2 3 "4" 5]
>
> will be passed to R as x <- "[1 2 3 \"4\" 5]"
>
> instead of x <- "[1 2 3 "4" 5] which throws an error.
>
> And this just works:
>
> #+NAME: latex-capt
> #+BEGIN_SRC latex
> \begin{math}
> y = X\beta,
> \mbox{where } \beta = %beta%
> \end{math}
> #+END_SRC
>
> #+BEGIN_SRC R :var ytxt=latex-capt :results raw :wrap latex
> beta <- 1.234
> sub("%beta%",beta,ytxt)
> #+END_SRC
>
>
> HTH,
>
> Chuck
--
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: address@hidden
Skype: RMkrug
PGP: 0x0F52F982
pgp95DXfRLvA4.pgp
Description: PGP signature
- [O] [PATCH] -for review- Tangling with variable transfer of variables, Rainer M Krug, 2014/06/19
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Aaron Ecay, 2014/06/19
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Charles Berry, 2014/06/19
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Rainer M Krug, 2014/06/20
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Rainer M Krug, 2014/06/20
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Charles C. Berry, 2014/06/21
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Aaron Ecay, 2014/06/21
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Rainer M Krug, 2014/06/23
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Rainer M Krug, 2014/06/23
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables,
Rainer M Krug <=
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Charles C. Berry, 2014/06/23
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Rainer M Krug, 2014/06/24
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Rainer M Krug, 2014/06/23
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Charles C. Berry, 2014/06/23
- Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Rainer M Krug, 2014/06/24
Re: [O] [PATCH] -for review- Tangling with variable transfer of variables, Rainer M Krug, 2014/06/20