cameronbracken / pgfSweave

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

setwd(newwd) causes Lyx/pgfsweave to freeze #13

Closed MartinInFrankfurtAM closed 13 years ago

MartinInFrankfurtAM commented 13 years ago

Example Lyx-code chunks: Not sure the following setup chunk is essential (just FYI)

Sweave opts externalize=TRUE,pdf=FALSE,eps=FALSE
<<setup, echo=FALSE>>=
options(keep.blank.line=FALSE)
@

<<test,echo=T,eval=T,results=verbatim,cache=F,tidy=T>>=
oldwd=getwd()
setwd('~') # or anything alse
newwd=getwd()
# Commenting out the following command line causes pgfsweave to freeze 
# or display the last available pdf-version.
setwd(oldwd)
@

It might prevent some hairs turning grey if this were documented somewhat prominently or -better - if the change in wd would be intercepted and reversed outside the user code.

yihui commented 13 years ago

This is quite likely to be my fault...

Cameron, I will look into this issue first.

yihui commented 13 years ago

Confirmed. It is completely my fault in LyX configuration. I was not aware that users might use setwd() to change the working directory -- I never do that in my R code because this is not reproducible.

@MartinInFrankfurtaM: I have updated my R code for LyX to run Sweave: http://gitorious.org/yihui/lyx-sweave/blobs/raw/master/lyx-sweave-exec.R

You can either download that script and put it under ~/.lyx/scripts/, or simply run my auto-configuration script again (source("http://gitorious.org/yihui/lyx-sweave/blobs/raw/master/lyx-sweave-config.R")).

Maybe I need to clarify that the working directory for R in LyX is the just the directory where you LyX document comes from. Usually I put all the files needed in the same directory as my LyX documents, so I can use relative directories to read/write files. This is better for reproducibility (when you work with others, or on two computers)

yihui commented 13 years ago

Ahh... I just realized I committed another crime in my LyX demo: externalize=TRUE is a typo -- should be external=TRUE. This is terrible. I don't know how many users were mislead by this typo. Externalizing is so important to pgfSweave...

cameronbracken commented 13 years ago

Thanks for clearing this up, I had no idea how to go about it....

MartinInFrankfurtAM commented 13 years ago

Not quite worst-case proof yet. The tikz-files are still stored in what I set in setwd() - and not found by latex in the next step. Forewarned is forearmed, however. You may still argue that a man who cannot dance should not get a sword to begin with.

yihui commented 13 years ago

Haha, thanks for teaching me proverbs. I did not know the last one.

This time, however, I think the problem is really out of my control. I've corrected my fault.

This is not pgfSweave's problem either -- I think it comes from the fact that Sweave uses relative paths to write the plots instead of using absolute paths, so the the plots will not be in the same directory with the .tex file if you have changed the working directory in your R code.

I agree such a problem should be fixed, but I have no idea about how the R core (or the authors of Sweave) would think.

Again, I really do not recommend you to use setwd() anywhere in Sweave. Anyway, you might want to wrestle with R core :)

MartinInFrankfurtAM commented 13 years ago

Thank you, Yihui. I had better learn to dance with R first, however.