Skip to content

a question about "latex" in Hmisc

30 messages · Richard M. Heiberger, Shi, Tao, Erik Iverson +5 more

Messages 1–25 of 30

#
Hi list,

Excuse me b/c this is probably a more "TeX" then "R" 
question.

I've been using "latex" function in my .Rnw file to 
generate tables, but I've always been using it without assigning the 
result to a object, i.e.

x <- matrix(1:6, nrow=2, 
dimnames=list(c('a','b'),c('c','d','this that')))
latex(x)

so, I always get the error window (attached) poped out.  But since I can 
just click OK and everything seems fine except in my working directory I get a bunch of "junk" files (.log, .dvi, etc...), I've been ignoring 
it.

Now I know by doing e.g. tmp <- latex(x) will suppress 
this error message, but I'm still curious on how to get rid of the error window when I just use latex(x).   I read the "Example" section of 
"latex" help file and I tried to include the following into my PATH:

"C:\Program Files\MiKTeX 2.7\tex\latex"

but that didn't work.

I'm 
using R.2.11.0, Hmisc 3.7, and MiKtex 2.7 on WinXP.

Thanks!

...Tao
#
Shi, Tao wrote:
Your attachment did not come through, most likely because it is not a 
type that is supported by the list.
Well I can't directly help you with your issue, since I don't know what 
error you're receiving, the reason this is happening is that when you 
don't assign the result of your latex call, the function 'print.latex' 
is getting called, which if I understand tries to compile the LaTeX 
output and display the result in a suitable viewer.  By assigning the 
results of the latex call in R, you stop this printing from happening.

As for what your issue is, I don't know since your attachment did not 
come through.
#
Hi Tao,
I think you just need latex(x, file="")

Best,
Ista
On Wednesday 12 May 2010 3:18:42 pm Shi, Tao wrote:
#
Shi, Tao wrote:
The image was stripped by the mailer.  Please type the text of the error 
into the body of the email.
Where?  In the Windows environment on the Control Panel?  Through R?
What does R think the the path is?

    Sys.getenv("PATH")

Does it have two backslash characters everywhere you only one backslash 
character?
My R shows
C:\\Program Files\\MiKTeX 2.7\\miktex\\bin;
Please define "didn't work".  Include the full message that you received.

Rich
#
Ista Zahn wrote:
I think I misunderstood the question, I believe that is what is needed 
here.
#
Hi Erik,

Thanks for the quick reply!

My attachment was in .png which should be supported by the list ....  I'm resending it.

Yes, I knew by assigning it to an object, I can avoid this.  But, I'm curious to know what if I choose to do e.g. just latex(x), how can I get rid of the error window.  It actually worked for me once (i.e. I got Yap poped out to preview the table I'm generating), but I had no idea what I did differently.

...Tao




----- Original Message ----

        
Shi, Tao wrote:
Your attachment did not come through, most likely because it
Well I can't directly help you with your issue, since I
As for what your
#
Hi Richard,

Obviously, the list doesn't like my attachment.  Here it is:

http://i41.tinypic.com/15qz387.jpg

I set the path using Windows control panel.  And "didn't work" means I'm still getting the same error window shown above.

...Tao




----- Original Message ----
The image was stripped by the mailer.  Please type the text of the
Where?  In the Windows environment on the
What does R think the the path
Sys.getenv("PATH")

Does it have two backslash
My R
C:\\Program Files\\MiKTeX 2.7\\miktex\\bin;
Please define "didn't work".  Include the full
Rich
#
Shi, Tao wrote:
Well, it's hard to say what's going on unless I can get on a Windows 
machine and replicate it.  That path is R's temporary directory, so it 
seems the DVI file is either not getting created, it's getting created 
in a different place than it's expected, or something is looking in the 
wrong spot for the .dvi file.  You mention in your original post that 
the .dvi file is created.  Can you confirm that this is true?  Did you 
mean in the temp directory, or in your working directory?  Check the 
.log file in the temp directory if one exists with the same base name as 
the .dvi file in the error message.
#
Erik,  No, you didn't misunderstand my question.


Ista, 

I have no access to LaTex now, so I can't test your solution right away.  My understanding to your solution is that, basically, you just let 'latex' function generate the tex text which is directly incorporated into the big .tex file (rather a separate .tex file just for that table).  Am I right?

Thanks,

...Tao





----- Original Message ----

        
Ista Zahn wrote:
I think I misunderstood the question, I believe that is
______________________________________________
PLEASE do read the posting
and provide commented,
#
The .dvi file is being created in the working directory for sure, not sure whether it's in the tmp folder or not.  (I just tested on my home machine which only has R but no MikTex installed, I can see only .tex file in the tmp folder.  No .log file in the tmp folder.)

...Tao
  



----- Original Message ----

        
Shi, Tao wrote:
Well, it's hard to say what's going on
#
On Wednesday 12 May 2010 3:58:08 pm Shi, Tao wrote:
Yes, that is correct. As far as I'm aware the print method for latex() 
actually typesets the table. To avoid this, simply set file="" as I suggested.

If you would rather have a separate file for your table you can continue to 
use your original method, e.g., 
<<>>=
tmp <- latex(x, file="x.tex")
@
\include{x.tex}

(not sure what your objection to this was in the first place).

-Ista
#
Hi Ista,

Thanks for the reply!

You actually misunderstood me.  I never objected the "tmp <- latex(x)" method (in fact, that's what I'm doing now in my .Rnw file).  As I stated in my original post, I'm simply curious about what causes the error window and wanted to get to the bottom of it.

...Tao


=====================================

If you would rather have a
use your original method,
<<>>=
tmp <- latex(x,
@
\include{x.tex}

(not sure what your objection to
-Ista
#
On 12/05/2010 4:33 PM, Shi, Tao wrote:
latex(x) returns an object of class "latex".  When you don't assign it, 
it prints.  The print method for "latex" objects tries to run latex and 
then display the resulting .dvi file.  (Or maybe it runs pdflatex and 
displays the .pdf file).

If you can't run latex, you can't print those objects.  That's why 
you're getting an error.

Duncan Murdoch
#
On 05/12/2010 03:33 PM, Shi, Tao wrote:
Not clear why the earlier suggestion someone made to use latex(object, 
file='') is not the method of choice with Sweave.

Frank

  
    
#
HI:
If you don't mind me asking this question about latex:
Based on Duncan's comment:
"The print method for "latex" objects tries to run latex and then display the resulting .dvi file.? (Or maybe it runs pdflatex and displays the .pdf file)."
Where in MikTex can I change to pdflatex? everytime I use latex it displays?the dvi file which is a problem because tables that I want to see landscaped don't work. Thanks
?
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA



----- Original Message ----
latex(x) returns an object of class "latex".? When
If you can't run latex, you can't
Duncan
______________________________________________
PLEASE do read the posting
and provide commented,
#
On 13.05.2010 16:32, Felipe Carrillo wrote:
Run pdflatex rather than latex?

Uwe Ligges
#
On 13/05/2010 10:48 AM, Uwe Ligges wrote:
Or if using texify, use the --pdf option.

Duncan Murdoch
#
Felipe Carrillo wrote:
I don't work in a Windows environment, but I think the process is the 
same here.

You have to know what the print.latex function in Hmisc is doing.  It 
simply calls show.latex.  If you look at the source for show.latex, it 
looks at the latex object passed to it, and inspects the file argument. 
  If the file argument is the empty string ( "" ), it does not attempt 
to show the resulting output in a dvi.  If the file argument is a file 
name, show.latex will call dvi.latex on the object, which will wrap the 
latex code in some basic latex, and call optionsCmds("latex") on the file.

This is by default set to

 > optionsCmds("latex")
[1] "/usr/bin/latex"

This will of course create a dvi and attempt to display it with 
show.dvi, which will in turn use

 > optionsCmds("xdvi")
[1] "xdvi"

to display the resulting file.

I'm guessing MikTex comes with pdflatex, just like it comes with a 
binary called latex.  You'd just have to find it and make sure it's in 
your path.

Then, by setting the relevant options I just described above to pdflatex 
and a suitable pdf viewer, you might get what you want.  But there might 
be other things I haven't thought of that will prohibit this from 
working.  In fact, it looks like dvi.latex naturally assumes the 
extension .dvi from its output, and so this may not work.  You/I might 
have to write separate functions to carry this out it appears.  Of 
course, someone else may have already, and I just don't know about it.

--Erik
#
Looks good.  I came up with something on my own which was basically to 
re-write print.latex.  I call pdflatex a few times because with the 
longtable package, sometimes things don't line up right until you run 
pdflatex multiple times.  I think mine is less flexible though, and I 
like your solution better.

The only thing I can see to make your solution more flexible is to note 
that there is already options("pdfviewer") in R, so maybe you could just 
use whatever that is for options("xdvicmd") and then in show.dvi, you 
can test

if(viewer == options("pdfviewer")) {
...
}

--Erik
RICHARD M. HEIBERGER wrote:
#
<snip>
Somehow with my own data and not using the awkward bit, it worked on my 
Linux machine?  At least I thought it did, since I believe show.dvi is 
an exported function, can't you just overwrite it in your global 
environment and anything that calls it will use your copy?  I'll have to 
  look into how I got your code working on my system, because I know I 
didn't use that trick!

--Erik
#
Hi Duncan,

I have no problems running latex or pdflatex.  I re-ran my code and it seems the problem is that R (or MiKTex ?) put the .tex file (the one wrapping everything in a document format for displaying purpose) in a R tmp folder, but the corresponding .log, .aux, and .dvi in my working directory.  So when YAP was called, it was looking for the .dvi file in the R temp folder.  Therefore, the error window.  

http://i41.tinypic.com/15qz387.jpg

I wonder how to fix that?

Thanks!

...Tao





----- Original Message ----
latex(x) returns an object of class "latex".  When
If you can't run latex, you can't
Duncan
#
Hi Prof. Harrell,

Originally, I was thinking that by putting tables (especially those long tables) into separate .tex files would make my 'big' .tex file more organized (i.e. rather than having an one giant .tex file).  But now I'm having a second thought, b/c I don't really have to worry how my 'big' .tex file looks, as it's just a intermediate and I'll do all my editing in the .Rnw file.  So, I think I'll use the latex(x, file="") method more.  This also will make my working directory cleaner.

Thank you very much!

...Tao





----- Original Message ----
Not clear why the earlier suggestion someone
file='') is not the method of choice with
Frank