Question: Is there a way to print, from within R, a LaTeX table directly to an image file (for inclusion in another document/webpage). Basically, I'd like to supply LaTeX code to a function that saves it as an image to the working directory. 

Pipe dreams?

Answer: 
There are various LaTeX-to-Image converter scripts, designed to do things like convert equations into images for including on web pages.

If you can find one of those (dvipng perhaps?) then you can go from a table in R to LaTeX easy enough and then from LaTeX to png.

If you have dvipng, you can leverage Hmisc's latex conversions to make a neater function to do it:

```
dvipng.dvi <-
  function (object, file, ...) 
{
  cmd <- if (missing(file)) 
    paste("dvipng -T tight", shQuote(object$file))
  else paste("dvipng -T tight", "-o", file, shQuote(object$file))
  invisible(sys(cmd))
}

```

And then you can do:

```
> tt   # here is a table
   y
x    1  2  3
  1  9 12 11
  2 18  9 10
  3 10  7 14
> dvipng.dvi(dvi.latex(latex(tt)))

```

And that will produce a png file with a random name in the working directory. The -T tight option will crop all the whitespace from round it.

That's about as direct as I can think it possible.

Linux or Windows or Mac or Atari?
xtable provides the option to output either latex or html markup. You could put the html in directly.

Having said that I too would like to be able to go directly from knit or sweave to png or svg. I was trying to do this just last week. I am building an inkscape infographic (svg) and have been looking for a way to insert a linked image of a table that updates by running R code.

In initial testing I combined the use of xtable and Spacedman's (+1) code to get some nice png output (Ubuntu). -D option allows controlling of resolution.

I'm looking into a dvi->svg converter which is more like what I am after.
<http://dvisvg.sourceforge.net/>

```
dvipng.dvi <- function (object, file, res=600)
{
    if (missing(file)){
        invisible(sys(
                paste("dvipng -T tight", "-D", res, shQuote(object$file)))
            )
}
    else{
        invisible(sys(
                paste("dvipng -T tight", "-D", res, "-o", file, shQuote(object$file)))
            )
    }
}

tt <- head(iris)

dvipng.dvi(dvi.latex(latex(xtable(tt))), file='iris.png')

```