>>Gorjanc Gregor <gregor.gorj...@bfro.uni-lj.si> writes:
>> Can you clarify about how R would be able to read this variable?
>
> With Sys.getenv()

OK. Then this could be

<<>>=
setwd(dir=Sys.getenv(LYX_...))
@

But I would vote for automatic solution. I agree that this needs more work
and that adding the above code by the user is a good compromise for the moment

...

>> I think this should be done automatically. Afterall the source of the
>> problem is that LyX jumps to some other place. Why is this actually
>> done?

> In the good old days, it was possible to choose between these two ways
> of functioning. However this has been changed to 'only tmpdir' because
> of hard technical problems I cannot remember right now.
>
> In LaTeX code, for example, this is not a problem att all since we set
> the macro \in...@path which does some magic. Alas, R does not have such
> a mechanism (AFAIK).

Hmm. I also do not know about anything similar. I would like to stress that 
using
the above solution can cause another problem with the produced figures. Please
correct me if I am wrong. LyX "copies" the original file to some tempdir and 
does
all the work there. If we use the above solution, the relative paths will work, 
but
the produced figures will be places in the origdir and LyX (LaTeX) will not be 
able to
find the figures in the tempdir - they will be in the origdir. Perhaps the 
prefix.string
option of Sweave could be used.

Let me show the complete example - I will work with Sweave file. The original 
file
test.Rnw lies in origdir = /home/gg/, but we will move it to tempdir = /tmp for
the processing. The original version of the file would be

--- test.Rnw start ---

\documentclass{article}
\usepackage{Sweave}
\begin{document}

<<fig=TRUE>>=
hist(rnorm(100))
@

\end{document}

--- test.Rnw end ---

Now the copied version would be

--- test.Rnw start ---

%% Added automatically start
<<>>=
setwd(dir="/home/gg")
@
\SweaveOpts{prefix.string=/tmp}
%% Added automatically end

\documentclass{article}
\usepackage{Sweave}

\begin{document}

<<fig=TRUE>>=
hist(rnorm(100))
@

\end{document}

--- test.Rnw end ---

I wonder if there is a scenario that this could fail? If a user uses 
\SweaveOpts{prefix.string=...} then
the LaTeX compilation would fail. Perhaps a search over the file for such cases 
could be done to throw
an error.

gg

Reply via email to