Skip to content

latex() hangs R console

5 messages · Michael Friendly, Richard M. Heiberger, Dennis Murphy +1 more

#
[Env: R 2.11.1, Win Xp, Miktex 2.7]

I've just started using Hmisc::latex and friends, and find that running 
latex() produces the .tex and .dvi files, but hangs,
presumably trying to run yap.  An example is below.  What could be wrong?

My PATH seems OK:
 > strsplit(Sys.getenv("path"),';')
$path
  [1] "c:\\program files\\imagemagick-6.4.4-q16"                   
"c:\\Rtools\\bin"
  [3] "c:\\Rtools\\perl\\bin"                                      
"c:\\Rtools\\MinGW\\bin"
  [5] "C:\\Program Files\\MiKTeX 2.7\\miktex\\bin"                 
"C:\\WINDOWS\\system32"
  [7] "C:\\WINDOWS"                                                
"C:\\WINDOWS\\System32\\Wbem"
  [9] "C:\\Program Files\\Intel\\DMIX"                             
"C:\\Program Files\\ATI Technologies\\ATI.ACE\\"
[11] "C:\\Program Files\\Common Files\\Roxio Shared\\DLLShared\\" 
"C:\\WINDOWS\\system32\\nls"
[13] "C:\\WINDOWS\\system32\\nls\\ENGLISH"                        
"C:\\Program Files\\SecureCRT\\"
[15] "C:\\Program Files\\IDM Computer Solutions\\UltraEdit-32"    
"C:\\Program Files\\SAS\\Shared Files\\Formats"
[17] "C:\\Program Files\\Graphviz2.20\\Bin"                       
"C:\\Program Files\\MATLAB\\R2008a\\bin"
[19] "C:\\Program Files\\MATLAB\\R2008a\\bin\\win32"              
"C:\\Program Files\\TortoiseSVN\\bin"
[21] "C:\\Program Files\\HTML Help Workshop"                      
"C:\\Program Files\\QuickTime\\QTSystem\\"

Example:

 > x <- matrix(1:6, nrow=2, dimnames=list(c('a','b'),c('c','d','this 
that')))
 > latex(x, file="")
% latex.default(x, file = "")
%
\begin{table}[!tbp]
  \begin{center}
  \begin{tabular}{lrrr}\hline\hline
\multicolumn{1}{l}{x}&\multicolumn{1}{c}{c}&\multicolumn{1}{c}{d}&\multicolumn{1}{c}{this 
that}\tabularnewline
\hline
a&$1$&$3$&$5$\tabularnewline
b&$2$&$4$&$6$\tabularnewline
\hline
\end{tabular}
\end{center}
\end{table}

 > cd("c:/r/test")
 > latex(x)
This is pdfTeX, Version 3.1415926-1.40.9 (MiKTeX 2.7)
entering extended mode
(C:/WINDOWS/TEMP/Rtmpz0QkT8/file311f289a.tex
LaTeX2e <2005/12/01>
Babel <v3.8l> and hyphenation patterns for english, dumylang, 
nohyphenation, ge
rman, ngerman, french, loaded.
("C:\Program Files\MiKTeX 2.7\tex\latex\base\report.cls"
Document Class: report 2005/09/16 v1.4f Standard LaTeX document class
("C:\Program Files\MiKTeX 2.7\tex\latex\base\size10.clo"))
("C:\Program Files\MiKTeX 2.7\tex\latex\geometry\geometry.sty"
("C:\Program Files\MiKTeX 2.7\tex\latex\graphics\keyval.sty")
("C:\Program Files\MiKTeX 2.7\tex\latex\geometry\geometry.cfg"))
No file file311f289a.aux.
[1] (file311f289a.aux) )
Output written on file311f289a.dvi (1 page, 372 bytes).
Transcript written on file311f289a.log.

At this point, I have to press ESC after a few minutes to regain the 
console, and no .dvi (yap) window appears.
If I go to the temp directory, C:/WINDOWS/TEMP/Rtmpz0QkT8/, the .dvi 
file is there and double-click
launches yap.

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

Reading the code of print.latex -> show.latex -> show.dvi, I tried 
executing  system() directly, in the forms

 > system(paste("yap", "C:/WINDOWS/TEMP/Rtmpz0QkT8/file311f289a.dvi"), 
intern=TRUE)

 > system(paste("yap", "C:/WINDOWS/TEMP/Rtmpz0QkT8/file311f289a.dvi"))

However, both of these result in the same behavior -- R console hangs 
until I press ESC.
#
I guess I know the answer but I am not completely clear about the
reason; print.latex() calls show.dvi() to open the DVI file using
system(), and under Windows it is usually better using shell() instead
of system(). The help page says shell() is a "friendly" wrapper of
system() under Windows, and this works:

shell(paste("yap", "C:/WINDOWS/TEMP/Rtmpz0QkT8/file311f289a.dvi"))

So if might help to add an additional line for Windows:

if (.Platform$OS.type == 'windows') system = shell
function (object, width = 5.5, height = 7)
{
    viewer <- optionsCmds("xdvi")
    cmd <- if (viewer == "yap") {
        paste(viewer, object$file)
    }
    else if (viewer == "kdvi") {
        paste(viewer, object$file)
    }
    else if (viewer == "xdvi") {
        paste(viewer, " -paper ", width, "x", height, "in -s 0 ",
            object$file, sep = "")
    }
    else {
        paste(viewer, object$file)
    }
    if (.Platform$OS.type == 'windows') system = shell
    system(cmd, intern = TRUE, wait = TRUE)
    invisible(NULL)
}
<environment: namespace:Hmisc>


Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
On Tue, Dec 7, 2010 at 8:05 PM, Dennis Murphy <djmuser at gmail.com> wrote:
#
On 12/7/2010 9:35 PM, Yihui Xie wrote:
I can confirm that using shell() directly on the .dvi file generated by 
latex() works, while system() does not -- it hangs
as before.

However, Yihui's patch, in this form still hangs, so maybe there is 
something else going on here.

`show.dvi` <-
function (object, width = 5.5, height = 7)
{
     viewer <- optionsCmds("xdvi")
     cmd <- if (viewer == "yap") {
         paste(viewer, object$file)
     }
     else if (viewer == "kdvi") {
         paste(viewer, object$file)
     }
     else if (viewer == "xdvi") {
         paste(viewer, " -paper ", width, "x", height, "in -s 0 ",
             object$file, sep = "")
     }
     else {
         paste(viewer, object$file)
     }
     if (.Platform$OS.type == 'windows') system = shell
     system(cmd, intern = TRUE, wait = TRUE)
     invisible(NULL)
}
environment(show.dvi) <- environment(latex)