

I am using R for Unix and want to make some LaTeX tables. I have
already played around in R for Windows and have succeeded in making
tables that I want using the following code:
latex(Estimates, file='out.tex', rowlabel='',digits=3)
However, when I use this code in Unix, I can never find the file
"out.tex". I assumed that R would send the file to whatever directory
I was working in, but that does not seem to be the case. So, I tried
specifiying the exact location where I want the file:
latex(Estimates, file='/home/b/bquinif/bq/9095/out.tex', rowlabel='',digits=3)
When I do that, I get an error message sayin that the file/directory
does not exist. I have written lots of files from Stata to locations
specified like above, so I don't understand what's going on.
Can anyone help me straighten this out?
Thanks,
Brian
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide! http://www.Rproject.org/postingguide.html


"Brian Quinif" < [hidden email]> writes:
> I am using R for Unix and want to make some LaTeX tables. I have
> already played around in R for Windows and have succeeded in making
> tables that I want using the following code:
>
> latex(Estimates, file='out.tex', rowlabel='',digits=3)
>
> However, when I use this code in Unix, I can never find the file
> "out.tex". I assumed that R would send the file to whatever directory
> I was working in, but that does not seem to be the case. So, I tried
> specifiying the exact location where I want the file:
>
> latex(Estimates, file='/home/b/bquinif/bq/9095/out.tex', rowlabel='',digits=3)
>
> When I do that, I get an error message sayin that the file/directory
> does not exist. I have written lots of files from Stata to locations
> specified like above, so I don't understand what's going on.
>
> Can anyone help me straighten this out?
I assume you mean latex() from the Hmisc package? You might want to
ask its maintainer. I can't reproduce your problem though; I get the
file nicely in the current directory. (I got slightly bugged by
Frank's idea of having the print method run latex on the file and fire
up a viewer  didn't play well with a terminal login. However, that's
completely unrelated).
Can you give a completely reproducible example that others might try?

O__  Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_  Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*)  University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~  ( [hidden email]) FAX: (+45) 35327907
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide! http://www.Rproject.org/postingguide.html


Yes, Peter, I do mean the later() function from the Hmsic package.
Below is a reproducible example. Also, does anyone know how to stop R
from automatically running LaTeX on the file produced by latex()
library(Matching)
library(Hmisc)
#make up some data
X < matrix(rnorm(1000*5), ncol=5)
Y1 < as.vector(rnorm(1000))
Tr < c(rep(1,500),rep(0,500))
#estimate nearest neighbor, 11 matching, ATT
a < Match(Y=Y1, X=X, Tr=Tr, M=1)
summary(a)
#make up some more data
Y2 < as.vector(rnorm(1000))
#estimate nearest neighbor, 11 matching, ATT
b < Match(Y=Y2, X=X, Tr=Tr, M=1)
summary(b)
#Generate table of estimates
Estimates < matrix(c(a$est, b$est, a$se, b$se),nrow=2)
rownames(Estimates) = c("a","b")
colnames(Estimates) = c("Estimate","Standard Error")
print(Estimates)
#I use the next line of code for running in Windowsit works, and I
can find the file out.tex
#latex(Estimates, file='out.tex', rowlabel='',digits=3)
#I use the next line of code for running in UnixI get an error
message saying the file/directory does not exist
#latex(Estimates, file='/home/b/bquinif/bq/9095/out.tex', rowlabel='',digits=3)
05 Apr 2006 22:29:54 +0200, Peter Dalgaard < [hidden email]>:
> "Brian Quinif" < [hidden email]> writes:
>
> > I am using R for Unix and want to make some LaTeX tables. I have
> > already played around in R for Windows and have succeeded in making
> > tables that I want using the following code:
> >
> > latex(Estimates, file='out.tex', rowlabel='',digits=3)
> >
> > However, when I use this code in Unix, I can never find the file
> > "out.tex". I assumed that R would send the file to whatever directory
> > I was working in, but that does not seem to be the case. So, I tried
> > specifiying the exact location where I want the file:
> >
> > latex(Estimates, file='/home/b/bquinif/bq/9095/out.tex', rowlabel='',digits=3)
> >
> > When I do that, I get an error message sayin that the file/directory
> > does not exist. I have written lots of files from Stata to locations
> > specified like above, so I don't understand what's going on.
> >
> > Can anyone help me straighten this out?
>
> I assume you mean latex() from the Hmisc package? You might want to
> ask its maintainer. I can't reproduce your problem though; I get the
> file nicely in the current directory. (I got slightly bugged by
> Frank's idea of having the print method run latex on the file and fire
> up a viewer  didn't play well with a terminal login. However, that's
> completely unrelated).
>
> Can you give a completely reproducible example that others might try?
>
> 
> O__  Peter Dalgaard Øster Farimagsgade 5, Entr.B
> c/ /'_  Dept. of Biostatistics PO Box 2099, 1014 Cph. K
> (*) \(*)  University of Copenhagen Denmark Ph: (+45) 35327918
> ~~~~~~~~~~  ( [hidden email]) FAX: (+45) 35327907
>
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide! http://www.Rproject.org/postingguide.html


"Brian Quinif" < [hidden email]> writes:
> Yes, Peter, I do mean the later() function from the Hmsic package.
> Below is a reproducible example. Also, does anyone know how to stop R
> from automatically running LaTeX on the file produced by latex()
The last bit is easy. It's the print method that does that, so just
don't print. E.g.
invisible(latex(....))

O__  Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_  Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*)  University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~  ( [hidden email]) FAX: (+45) 35327907
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide! http://www.Rproject.org/postingguide.html


I seem to have straightened out the problem I was having by typing
ls ald /home/b/bquinif/bq/9095/
before running R.
Thanks again to the ever helpful people on this list.
BQ
before you start
05 Apr 2006 23:11:12 +0200, Peter Dalgaard < [hidden email]>:
> "Brian Quinif" < [hidden email]> writes:
>
> > Yes, Peter, I do mean the later() function from the Hmsic package.
> > Below is a reproducible example. Also, does anyone know how to stop R
> > from automatically running LaTeX on the file produced by latex()
>
> The last bit is easy. It's the print method that does that, so just
> don't print. E.g.
>
> invisible(latex(....))
>
> 
> O__  Peter Dalgaard Øster Farimagsgade 5, Entr.B
> c/ /'_  Dept. of Biostatistics PO Box 2099, 1014 Cph. K
> (*) \(*)  University of Copenhagen Denmark Ph: (+45) 35327918
> ~~~~~~~~~~  ( [hidden email]) FAX: (+45) 35327907
>
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide! http://www.Rproject.org/postingguide.html


Your command
latex(Estimates, file='out.tex', rowlabel='',digits=3)
works for me in a unix environment, and produces
the file out.tex in the current working directory.
(your second example is not reproducible, in
general, since I don't have directory named
/home/b/bquinif/bq/9095
)
Your first message indicated that the command
latex(Estimates, file='out.tex', rowlabel='',digits=3)
did *not* return an error, just that you could
not find the file. If that's the case, then try
getwd()
to find out what R thinks your current directory
is. That is where R should be putting the file.
You can also try, from within R,
list.files()
list.files(patt='tex')
to see what is there.
Don
At 4:47 PM 0400 4/5/06, Brian Quinif wrote:
>Yes, Peter, I do mean the later() function from the Hmsic package.
>Below is a reproducible example. Also, does anyone know how to stop R
>from automatically running LaTeX on the file produced by latex()
>
>library(Matching)
>library(Hmisc)
>
>#make up some data
>X < matrix(rnorm(1000*5), ncol=5)
>Y1 < as.vector(rnorm(1000))
>Tr < c(rep(1,500),rep(0,500))
>
>#estimate nearest neighbor, 11 matching, ATT
>a < Match(Y=Y1, X=X, Tr=Tr, M=1)
>summary(a)
>
>#make up some more data
>Y2 < as.vector(rnorm(1000))
>
>#estimate nearest neighbor, 11 matching, ATT
>b < Match(Y=Y2, X=X, Tr=Tr, M=1)
>summary(b)
>
>#Generate table of estimates
>Estimates < matrix(c(a$est, b$est, a$se, b$se),nrow=2)
>rownames(Estimates) = c("a","b")
>colnames(Estimates) = c("Estimate","Standard Error")
>print(Estimates)
>
>#I use the next line of code for running in Windowsit works, and I
>can find the file out.tex
>#latex(Estimates, file='out.tex', rowlabel='',digits=3)
>
>#I use the next line of code for running in UnixI get an error
>message saying the file/directory does not exist
>#latex(Estimates,
>file='/home/b/bquinif/bq/9095/out.tex',
>rowlabel='',digits=3)
>
>
>05 Apr 2006 22:29:54 +0200, Peter Dalgaard < [hidden email]>:
>> "Brian Quinif" < [hidden email]> writes:
>>
>> > I am using R for Unix and want to make some LaTeX tables. I have
>> > already played around in R for Windows and have succeeded in making
>> > tables that I want using the following code:
>> >
> > > latex(Estimates, file='out.tex', rowlabel='',digits=3)
>> >
>> > However, when I use this code in Unix, I can never find the file
> > > "out.tex". I assumed that R would send the file to whatever directory
>> > I was working in, but that does not seem to be the case. So, I tried
>> > specifiying the exact location where I want the file:
>> >
> > > latex(Estimates,
>file='/home/b/bquinif/bq/9095/out.tex',
>rowlabel='',digits=3)
>> >
>> > When I do that, I get an error message sayin that the file/directory
>> > does not exist. I have written lots of files from Stata to locations
>> > specified like above, so I don't understand what's going on.
>> >
>> > Can anyone help me straighten this out?
>>
>> I assume you mean latex() from the Hmisc package? You might want to
>> ask its maintainer. I can't reproduce your problem though; I get the
>> file nicely in the current directory. (I got slightly bugged by
>> Frank's idea of having the print method run latex on the file and fire
>> up a viewer  didn't play well with a terminal login. However, that's
>> completely unrelated).
>>
>> Can you give a completely reproducible example that others might try?
>>
>> 
>> O__  Peter Dalgaard Øster Farimagsgade 5, Entr.B
>> c/ /'_  Dept. of Biostatistics PO Box 2099, 1014 Cph. K
>> (*) \(*)  University of Copenhagen Denmark Ph: (+45) 35327918
>> ~~~~~~~~~~  ( [hidden email]) FAX: (+45) 35327907
>>
>
>______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rhelp>PLEASE do read the posting guide! http://www.Rproject.org/postingguide.html

Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide! http://www.Rproject.org/postingguide.html


Peter Dalgaard wrote:
> "Brian Quinif" < [hidden email]> writes:
>
>
>>Yes, Peter, I do mean the later() function from the Hmsic package.
>>Below is a reproducible example. Also, does anyone know how to stop R
>>from automatically running LaTeX on the file produced by latex()
>
>
> The last bit is easy. It's the print method that does that, so just
> don't print. E.g.
>
> invisible(latex(....))
Or do w < latex(.., file='...')
Frank
>

Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide! http://www.Rproject.org/postingguide.html
Frank Harrell
Department of Biostatistics, Vanderbilt University


This thread piqued my interest in how to use Hmisc latex() to produce
the tables that I actually want, rather than the ones that come out by
default. Actually, I'd be glad to use R2HTML or any other tool if I
can make the output suit my taste.
Here's a small working example that does not require any special libraries.
x < rnorm(100)
y < rnorm(100)
mylm < lm(y~x)
Estimates < cbind(coef(mylm), sqrt(diag(vcov(mylm))))
colnames(Estimates) < c("OLS estimate","std. error")
rownames(Estimates) < c("Intercept","Education")
latex(Estimates,file="/home/pauljohn/test4.tex",digits=4)
That creates the top part of the table like I want it, except there
are no stars on the standard errors.
I want to add the diagnostic information, sample size, the Rsquare,
and root mean square error:
sumobj < summary(mylm)
## tedious pasting alert:
sumStat < paste("N= ",sum(sumobj$df[1]), ", R^2 =",
sumobj$r.squared, ", RMSE = ", sumobj$sigma)
# The following does not have the desired effect because it creates
and appends a whole new table
latex(sumStat, file="/home/pauljohn/test4.tex", append=T)
How can I "snug up" sumStat right at the end of the table?
pj
On 4/5/06, Frank E Harrell Jr < [hidden email]> wrote:
> Peter Dalgaard wrote:
> > "Brian Quinif" < [hidden email]> writes:
> >
> >
> >>Yes, Peter, I do mean the later() function from the Hmsic package.
> >>Below is a reproducible example. Also, does anyone know how to stop R
> >>from automatically running LaTeX on the file produced by latex()
> >
> >
> > The last bit is easy. It's the print method that does that, so just
> > don't print. E.g.
> >
> > invisible(latex(....))
>
> Or do w < latex(.., file='...')
>
> Frank
> >
>
>
> 
> Frank E Harrell Jr Professor and Chair School of Medicine
> Department of Biostatistics Vanderbilt University
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide! http://www.Rproject.org/postingguide.html>

Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide! http://www.Rproject.org/postingguide.html


The difficulty you are running into is related to the fact that
print methods return their argument as their value. They do not
return a representation of the text that appears on the screen.
At some level, it looks like the intent is to capture the screen text
and reformat it for LaTeX. This is not easily done without getting
inside the print method.
You can get an effect close to what you want with the single statement
tmp < latex(list(Estimates, sumStat)) ## assignment prevents automatic printing
but it will still produce two table environments, one for each component
of the list.
The result you are looking for is not a simple rectangular array.
We have zillions of arguments in latex() for controlling the appearance
of rectangular arrays. The types of controls that are needed for more
general structures are more general and we don't have all that you would want.
You might want to look at the insert.bottom argument and the caption and caption.loc
arguments.
For full control, you have the choice of doing formatting on the R side or
on the LaTeX side. You can write
sumStat < paste("\multicolumn{3}{l}{", "N= ",sum(sumobj$df[1]), ", R^2 =",
sumobj$r.squared, ", RMSE = ", sumobj$sigma, "}")
on the R side. Or you can edit the latex file to add
the \multicolumn. Since you will need to edit the latex anyway to move
the line from its own table to the bottom of the first table,
I think it would be easier to do everything on the LaTeX side.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide! http://www.Rproject.org/postingguide.html

