Dear Everybody!
I want to export data to LaTeX. As I want to employ the data as freely as
possible I want to avoid the xtable-command and instead generate some List
like
\MyOwnPrettyCommand{Adam}{Auer}{17}
\MyOwnPrettyCommand{Bertram}{Bauer}{14}
\MyOwnPrettyCommand{Christoph}{Huber}{75}
\MyOwnPrettyCommand{Damian}{Dorfer}{69}
\MyOwnPrettyCommand{Emanuel}{Eder}{43}
with \MyOwnPrittyCommand defined elsewhere.
As a pitty, if I make up about such a table in r, lets call it "A",
and use
the commands
sink("tabelle.tex")
A
sink("anderedatei")
tabelle.tex will look like this:
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] "MyOwnPrettyCommand{" "Adam" "}{"
"Auer" "}{" "17" "}"
[2,] "MyOwnPrettyCommand{" "Bertram" "}{"
"Bauer" "}{" "14" "}"
[3,] "MyOwnPrettyCommand{" "Christoph" "}{"
"Huber" "}{" "75" "}"
[4,] "MyOwnPrettyCommand{" "Damian" "}{"
"Dorfer" "}{" "69" "}"
[5,] "MyOwnPrettyCommand{" "Emanuel" "}{"
"Eder" "}{" "43" "}"
So my question is how to export the data properly, without line-indices,
without quotes but WITH backslashes.
Thank you in advance.
Yours,
Mag. Ferri Leberl
Mag. Ferri Leberl wrote:> Dear Everybody! > I want to export data to LaTeX. As I want to employ the data as freely as > possible I want to avoid the xtable-command and instead generate some List > like > > \MyOwnPrettyCommand{Adam}{Auer}{17} > \MyOwnPrettyCommand{Bertram}{Bauer}{14} > \MyOwnPrettyCommand{Christoph}{Huber}{75} > \MyOwnPrettyCommand{Damian}{Dorfer}{69} > \MyOwnPrettyCommand{Emanuel}{Eder}{43} > > with \MyOwnPrittyCommand defined elsewhere. > As a pitty, if I make up about such a table in r, lets call it "A", and use > the commands > > sink("tabelle.tex") > A > sink("anderedatei") > > tabelle.tex will look like this: > > [,1] [,2] [,3] [,4] [,5] [,6] [,7] > [1,] "MyOwnPrettyCommand{" "Adam" "}{" "Auer" "}{" "17" "}" > [2,] "MyOwnPrettyCommand{" "Bertram" "}{" "Bauer" "}{" "14" "}" > [3,] "MyOwnPrettyCommand{" "Christoph" "}{" "Huber" "}{" "75" "}" > [4,] "MyOwnPrettyCommand{" "Damian" "}{" "Dorfer" "}{" "69" "}" > [5,] "MyOwnPrettyCommand{" "Emanuel" "}{" "Eder" "}{" "43" "}" > > So my question is how to export the data properly, without line-indices, > without quotes but WITH backslashes. >mydf <- as.data.frame( rbind(c("Adam", "Auer", 17), c("Bertram", "Bauer", 14), c("Christoph", "Huber", 75), c("Damian", "Dorfer", 69), c("Emanuel", "Eder", 43)) ) cat( paste("\\MyCommand{", mydf[,"V1"], "}{", mydf[,"V2"], "}{", mydf[,"V3"], "}", sep ="", collapse = "\n") , file = "tabelle.tex") HTH, Tobias> Thank you in advance. > Yours, > Mag. Ferri Leberl > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > >
Mag. Ferri Leberl <ferri.leberl <at> gmx.at> writes:> I want to export data to LaTeX. As I want to employ the data as freely as > possible I want to avoid the xtable-command and instead generate some List > like > > \MyOwnPrettyCommand{Adam}{Auer}{17} > \MyOwnPrettyCommand{Bertram}{Bauer}{14} > \MyOwnPrettyCommand{Christoph}{Huber}{75} > > with \MyOwnPrittyCommand defined elsewhere.Method 1: Use latex in package Hmisc. It is VERY flexible, and works for me in most cases. Hint 1: "\" rarely works in R as in C, it must be escaped to "\\" Hint 2: To increase you changes of getting a reply, always provide a full example generating the sample data. For example, in most cases "Adam" will be stored as a factor in the dataframe, which make things a bit more tricky. I used I() to avoid this in the example below d = data.frame(name=I(c("Auer","Caesar")), vname=I(c("Dieter","Karl")),age=c(10,30)) for (i in 1:nrow(d)) { d0 = d[i,] cat("\\MyNiceCommand{",d0$name,"}{",d0$vname,"}{",d0$age,"}\n",sep="") } You may nest this with sink, or better use the file argument in cat, don't forget append. Or directly use Rweave, which should not be too difficult for a LaTeXer, and does not require the sink stuff. Dieter