cameronbracken / pgfSweave

Quality graphics and speedy compilation with Sweave
http://r-forge.r-project.org/projects/pgfsweave/
29 stars 6 forks source link

pgfSweave crashes with {ggplot2}scales_y_log - ( because of the exponents on the axis? ) #20

Closed MartinInFrankfurtAM closed 13 years ago

MartinInFrankfurtAM commented 13 years ago

"Error in grid.Call.graphics("L_text", as.graphicsAnnot(x$label), x$x, : Metric information not available for this family/device " results from

require(ggplot2) df=data.frame(x = c(0,1) ,y = c(1,10) ) Graph=qplot(x,y,data=df) +scale_y_log10() print(Graph)

The code works from the Rconsole (e.g. rkward) for details see: http://stackoverflow.com/questions/4692974/ggplot2-code-that-works-interactively-rkward-crashes-under-lyx-pgfsweave-hint

My present work-around follows http://www.stat.auckland.ac.nz/~paul/R/CM/cmTutorial.pdf It amounts to "pdf()" from inside a chunk and embedding the pdf as graphic float. I tune the update of the graphics file by eval=T/F from the code chunk. and use my custom print wrapper:

ggprint<-function(Graph,Graph.fn,...){ pdf('FigCache.pdf',width=9,height=3,family='CM') print(Graph) dev.off() embedFonts(file='FigCache.pdf',outfile=Graph.fn,fontpaths=) }

One advantage is that I can use the chunk from the "rkward" console with identical results avoiding the repeated Latex compilation. How would the equivalent ggprint function for pgf/TikZ have to look?

Sharpie commented 13 years ago

Sorry to hear that you are having trouble! I am able to create this graph using tikz() and running your code from the R console---so at first glance it does not appear to be a problem with the exponents. I am interested in trying to reproduce your problem using LyX, however, neither Cameron nor I are LyX users.

Could you post an example LyX document in a gist and provide a link? It would help a lot.

MartinInFrankfurtAM commented 13 years ago

Thank you for your fast response, Sharpie! The files are at https://gist.github.com/781918 The lyx file demo-LyX-pgfSweave-crashes-with-ggplot-scales_y_log10.lyx is based on the options/preamble of Yihui's LyX-pgfSweave-minimal-demo.lyx at http://gitorious.org/yihui/lyx-sweave/blobs/raw/master/demo/LyX-pgfSweave-minimal-demo.lyx In addition, various files generated until the crash that appeared remotely possibly helpful are included at the same URL. For the incomplete files, I also included the corresponding files generated by commenting out "+scales_y_log10()" in the lyx file, i.e. demo-LyX-pgfSweave-runs-without-ggplot-scales_y_log10.* From the rkward R CLI, everything works fine with and without scales_y_log10().

BTW, before generating all these files, I did reinstall R, rkwark, lyx1.6.8 (compilation) , run an update of texlive2010 including texhash, and go through Yihui's http://gitorious.org/yihui/lyx-sweave/blobs/raw/master/lyx-sweave-config.R to reinstall pgfsweave.

I still feel like the proverbial man who is given a sword although he cannot dance. A pointer to a lean instruction on how to generate an R-interactive preview of the tikz-graph that will appear in my final pdf document would be very helpful.

Thank you!

Sharpie commented 13 years ago

Allright, I was able to reproduce your error using LyX 1.6.5 on Linux Mint. The error message:

Error in grid.Call.graphics("L_text", as.graphicsAnnot(x$label), x$x, : Metric information not available for this family/device

Suggests that for some reason a device is not being opened for output.

I still don't know how Yihui's LyX-Sweave works exactly, but I assume that it compiles the .Rnw file generated by LyX using the lyx-sweave-exec.R script. If I run the script manually on a .Rnw file produced from your LyX document:

Rscript ~/code/testbed/lyx-crash/lyx-sweave/lyx-sweave-exec.R 'UTF-8' 'pgfSweave' $PWD $PWD test_document.Rnw

I get the same error:

Error: chunk 3 Error in grid.Call.graphics("L_text", as.graphicsAnnot(x$label), x$x, : Metric information not available for this family/device

(6074)/ ClientApp::doIt: Creating ClientApp kioclient(6074) ClientApp::kde_open: KUrl("file:///home/sharpie/code/testbed/lyx-crash/test/test_document.Rnw.log") Error during wrapup: Take a look at the error log file: /home/sharpie/code/testbed/lyx-crash/test/test_document.Rnw.log Execution halted

Whereas if I try to compile the document using straight R commands:

R --vanilla --slave -e "require(pgfSweave); pgfSweave('test_document.Rnw', compile.tex=FALSE)"

Everything works. So at this point, I would diagnose the problem as a bug in lyx-sweave-exec.R. Yihui would probably have a better idea as to what is going on at this point than I do.

A pointer to a lean instruction on how to generate an R-interactive preview of the tikz-graph that will appear in my final pdf document would be very helpful.

At present, this is not possible due to the way the tikzDevice builds output. You either compile a complete, finished graph or nothing at all---there is no way to view a half-finished state. Funny thing is, I was pondering some changes just last night that would allow the device to generate previews, so perhaps this will be possible in future versions.

Right now, the best strategy I have is to create the graph interactively using the R console and look at the output in an x11() window. When you are satisfied, trade the x11() device for tikz() and, if we did our job right, everything should look the same.

yihui commented 13 years ago

This has nothing to do with pgfSweave. I've explained in stackoverflow. Sorry for the inconvenience.