[R] Printing/Generating/Outputting a Table (Not Latex)

Richard M. Heiberger rmh at temple.edu
Wed Dec 10 02:06:05 CET 2014


?latex
answers a lot of these questions.

The design intent of the latex() function is to construct one table at
a time in its own .tex flle.
The user then collects these and inserts them into a full document,
either manually or with Sweave.

The individual table has no context and no caption.
It is a convenience that the dvi() function wraps the table into a pdf
and displays it immediately.

The ?latex documentation shows that there is a file= argument for the
latex() function, not for the others,
You do get information on where the pdf file was stored, so moving it
is a nuisance but not a difficulty.

Changing size is documented.

dvi(tmp.latex, height=11, width=8.5) ## measured in inches

Rich



On Tue, Dec 9, 2014 at 7:14 PM, Kate Ignatius <kate.ignatius at gmail.com> wrote:
> Okay, all.
>
> I have it to work using this:
>
> library(Hmisc)
> options(latexcmd='pdflatex')
> options(dviExtension='pdf')
> options(xdvicmd='gnome-open')
>
> Running your simple code from above... by question is this:  the pdf
> is saved in a tmp directory... where do I change the directory path? I
> thought it was simply this:
>
> tmp.dvi <- dvi(latex(m2,file='/path/to/file/tmp.pdf', label="Title"))
>
> But maybe not.  In addition is it possible to change page size with this?
>
> K.
>
> On Tue, Dec 9, 2014 at 4:02 PM, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
>> On 09/12/2014 20:47, Richard M. Heiberger wrote:
>>>
>>> the last one is wrong.  That is the one for which I don't know the
>>> right answer on linux.
>>>
>>> 'xdvi' displays dvi files.  you need to display a pdf file.
>>> whatever is the right program on linux to display pdf files is what
>>> belongs there.
>>>
>>> On Macintosh we can avoid knowing by using 'open', which means use the
>>> system standard.
>>> I don't know what the linux equivalent is, either the exact program or
>>> the instruction to use the standard.
>>
>>
>> xdg-open (but like OS X it depends on having the right associations set).
>>
>>
>>>
>>> On Tue, Dec 9, 2014 at 3:36 PM, Kate Ignatius <kate.ignatius at gmail.com>
>>> wrote:
>>>>
>>>> I set these options:
>>>>
>>>> options(latexcmd='pdflatex')
>>>> options(dviExtension='pdf')
>>>> options(xdvicmd='xdvi')
>>>>
>>>> Maybe one too many?  I'm running in Linux.
>>>>
>>>>
>>>>
>>>> On Tue, Dec 9, 2014 at 3:24 PM, Richard M. Heiberger <rmh at temple.edu>
>>>> wrote:
>>>>>
>>>>> It looks like you skipped the step of setting the options.
>>>>> the latex function doesn't do pdflatex (by default it does regular
>>>>> latex) unless you set the options
>>>>> as I indicated.
>>>>>
>>>>> On Tue, Dec 9, 2014 at 3:11 PM, Kate Ignatius <kate.ignatius at gmail.com>
>>>>> wrote:
>>>>>>
>>>>>> Ah yes, you're right.
>>>>>>
>>>>>> The log has this error:
>>>>>>
>>>>>> ! LaTeX Error: Missing \begin{document}.
>>>>>>
>>>>>> Though can't really find much online on how to resolve it.
>>>>>>
>>>>>> On Tue, Dec 9, 2014 at 1:15 PM, Jeff Newmiller
>>>>>> <jdnewmil at dcn.davis.ca.us> wrote:
>>>>>>>
>>>>>>> pdflatex appears to have run, because it exited. You should look at
>>>>>>> the tex log file, the problem is more likely that the latex you sent out to
>>>>>>> pdflatex was incomplete.
>>>>>>>
>>>>>>> ---------------------------------------------------------------------------
>>>>>>> Jeff Newmiller                        The     .....       .....  Go
>>>>>>> Live...
>>>>>>> DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live
>>>>>>> Go...
>>>>>>>                                        Live:   OO#.. Dead: OO#..
>>>>>>> Playing
>>>>>>> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
>>>>>>> /Software/Embedded Controllers)               .OO#.       .OO#.
>>>>>>> rocks...1k
>>>>>>>
>>>>>>> ---------------------------------------------------------------------------
>>>>>>> Sent from my phone. Please excuse my brevity.
>>>>>>>
>>>>>>> On December 9, 2014 8:43:02 AM PST, Kate Ignatius
>>>>>>> <kate.ignatius at gmail.com> wrote:
>>>>>>>>
>>>>>>>> Thanks!  I do get several errors though when running on Linux.
>>>>>>>>
>>>>>>>> Running your code, I get this:
>>>>>>>>
>>>>>>>> Error in system(cmd, intern = TRUE, wait = TRUE) :
>>>>>>>> error in running command
>>>>>>>>
>>>>>>>> Fiddling around with the code and running this:
>>>>>>>>
>>>>>>>> tmp <- matrix(1:9,3,3)
>>>>>>>> tmp.tex <- latex(tmp, file='tmp.tex')
>>>>>>>> print.default(tmp.tex)
>>>>>>>> tmp.dvi <- dvi(tmp.tex)
>>>>>>>> tmp.dvi
>>>>>>>> tmp.tex
>>>>>>>> dvips(tmp.dvi)
>>>>>>>> dvips(tmp.tex)
>>>>>>>> library(tools)
>>>>>>>> texi2dvi(file='tmp.tex', pdf=TRUE, clean=TRUE)
>>>>>>>>
>>>>>>>> I get this:
>>>>>>>>
>>>>>>>> Error in texi2dvi(file="tmp.tex",,  :
>>>>>>>>   Running 'texi2dvi' on 'tmp.tex' failed.
>>>>>>>> Messages:
>>>>>>>> /usr/bin/texi2dvi: pdflatex exited with bad status, quitting.
>>>>>>>>
>>>>>>>> I've read that it may have something to do with the path of pdflatex.
>>>>>>>>
>>>>>>>> Sys.which('pdflatex')
>>>>>>>>
>>>>>>>>            pdflatex
>>>>>>>>
>>>>>>>> "/usr/bin/pdflatex"
>>>>>>>>
>>>>>>>>
>>>>>>>> Sys.which('texi2dvi')
>>>>>>>>
>>>>>>>>            texi2dvi
>>>>>>>>
>>>>>>>> "/usr/bin/texi2dvi"
>>>>>>>>
>>>>>>>>> file.exists(Sys.which('texi2dvi'))
>>>>>>>>
>>>>>>>>
>>>>>>>> [1] TRUE
>>>>>>>>
>>>>>>>>> file.exists(Sys.which('pdflatex'))
>>>>>>>>
>>>>>>>>
>>>>>>>> [1] TRUE
>>>>>>>>
>>>>>>>> Is there a specific path I should be giving with pdflatex and/or
>>>>>>>> 'texi2dvi to make this work?
>>>>>>>>
>>>>>>>> Thanks!
>>>>>>>>
>>>>>>>> On Mon, Dec 8, 2014 at 11:13 PM, Richard M. Heiberger
>>>>>>>> <rmh at temple.edu>
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> yes of course, and the answer is latex() in the Hmisc package.
>>>>>>>>> Why were you excluding it?
>>>>>>>>> Details follow
>>>>>>>>>
>>>>>>>>> Rich
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> The current release of the Hmisc package has this capability on
>>>>>>>>> Macintosh and Linux.
>>>>>>>>> For Windows, you need the next release 3.14-7 which is available now
>>>>>>>>
>>>>>>>> at github.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ## windows needs these lines until the new Hmisc version is on CRAN
>>>>>>>>> install.packages("devtools")
>>>>>>>>> devtools::install_github("Hmisc", "harrelfe")
>>>>>>>>>
>>>>>>>>> ## All operating systems
>>>>>>>>> options(latexcmd='pdflatex')
>>>>>>>>> options(dviExtension='pdf')
>>>>>>>>>
>>>>>>>>> ## Macintosh
>>>>>>>>> options(xdvicmd='open')
>>>>>>>>>
>>>>>>>>> ## Windows, one of the following
>>>>>>>>>
>>>>>>>>
>>>>>>>> options(xdvicmd='c:\\progra~1\\Adobe\\Reader~1.0\\Reader\\AcroRd32.exe')
>>>>>>>>>
>>>>>>>>> ## 32-bit windows
>>>>>>>>>
>>>>>>>>
>>>>>>>> options(xdvicmd='c:\\progra~2\\Adobe\\Reader~1.0\\Reader\\AcroRd32.exe')
>>>>>>>>>
>>>>>>>>> ## 64 bit windows
>>>>>>>>>
>>>>>>>>> ## Linux
>>>>>>>>> ## I don't know the xdvicmd value
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ## this works on all R systems
>>>>>>>>> library(Hmisc)
>>>>>>>>> tmp <- matrix(1:9,3,3)
>>>>>>>>> tmp.dvi <- dvi(latex(tmp))
>>>>>>>>> print.default(tmp.dvi) ## prints filepath of the pdf file
>>>>>>>>> tmp.dvi  ## displays the pdf file on your screen
>>>>>>>>>
>>>>>>>>> On Mon, Dec 8, 2014 at 9:31 PM, Kate Ignatius
>>>>>>>>
>>>>>>>> <kate.ignatius at gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I have a simple question.  I know there are plenty of packages out
>>>>>>>>>> there that can provide code to generate a table in latex.  But I
>>>>>>>>>> was
>>>>>>>>>> wondering whether there was one out there where I can generate a
>>>>>>>>
>>>>>>>> table
>>>>>>>>>>
>>>>>>>>>> from my data (which ever way I please) then allow me to save it as
>>>>>>>>>> a
>>>>>>>>>> pdf?
>>>>>>>>>>
>>>>>>>>>> Thanks
>>>>>>>>>>
>>>>>>>>>> K.
>>>>>>>>>>
>>>>>>>>>> ______________________________________________
>>>>>>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>>>>>>> PLEASE do read the posting guide
>>>>>>>>
>>>>>>>> http://www.R-project.org/posting-guide.html
>>>>>>>>>>
>>>>>>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>>>>>
>>>>>>>>
>>>>>>>> ______________________________________________
>>>>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>>>>> PLEASE do read the posting guide
>>>>>>>> http://www.R-project.org/posting-guide.html
>>>>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>>>>
>>>>>>>
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>> --
>> Brian D. Ripley,                  ripley at stats.ox.ac.uk
>> Emeritus Professor of Applied Statistics, University of Oxford
>> 1 South Parks Road, Oxford OX1 3TG, UK



More information about the R-help mailing list