From peter.ruckdeschel at web.de  Tue Oct 14 18:03:57 2008
From: peter.ruckdeschel at web.de (Peter Ruckdeschel)
Date: Tue, 14 Oct 2008 18:03:57 +0200
Subject: [Rd] relative path to source files in vignette [a solution
	somehow]
In-Reply-To: <971536df0810101659j710b91cahdf7e4fac3b0af280@mail.gmail.com>
References: <48EF9CAD.8090006@web.de>	
	<971536df0810101127n49084413pd97ec451e3040228@mail.gmail.com>	
	<48EFA380.8080801@web.de>	
	<971536df0810101334w12014877t408732c9f12edc20@mail.gmail.com>	
	<48EFDFE9.1050806@web.de>
	<971536df0810101659j710b91cahdf7e4fac3b0af280@mail.gmail.com>
Message-ID: <48F4C2ED.2080307@web.de>

Gabor Grothendieck schrieb:
> On Fri, Oct 10, 2008 at 7:06 PM, Peter Ruckdeschel
> <peter.ruckdeschel at web.de> wrote:
>   
[snip]
>> This could indeed be an option, but as noted in my reply to Robert, my
>> guess is that in the library where you install your packages to and which is
>> found with system.file(), you will no longer find the R source files but rather
>> some .rdb or .rdx file. At least this is what I found --- or is there some 
>> magic trick to get back the source files from this?
>>     
>
> Yes, that is what occurs. That's why it was suggested to copy it.
>
>
>   
Not sure whether this is helpful to anyone else out there, but
here is my solution:

I could not find a satisfactory automatic solution
%
(which should find the source folder[s] to my package[s]
 automatically and correspondingly, in R should fill string
 variables),
%
so I placed a README file into the  inst/doc folder where
I explain that to build / check / install my package[s] including
the building of the vignette, one either has to call R CMD from
the parent folder of the source folder to my package (distr)
or one has to define path(s) in a file myPATH.

In the preamble of my .Rnw file, I put

%--------------------------------------------------------------
% --- begin of code from newDistribution.Rnw in pkg distr --- %
%
<<setPath, results=tex, echo=FALSE>>=
if(file.exists("myPATH")){
   cat("\\def\\distrPATH{",readLines("myPATH")[1],"}\n",sep="")
   cat("\\def\\distrExPATH{",readLines("myPATH")[2],"}\n",sep="")
}else{
   cat("\\def\\distrPATH{../../../distr}\n",sep="")
   cat("\\def\\distrExPATH{../../../distrEx}\n",sep="")
}
@
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% define \lstinputlistingWithPath to be able to work with
% path information (parameter #2)
% so syntax for \lstinputlistingWithPath
%
%    \lstinputlistingWithPath[key=value-list]{<path>}{<file>}
%
% which then calls \lstinputlisting[key=value-list]{<path>/<file>}
%(but where <path> may be a macro which is expanded)
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\makeatletter
\def\lstinputlistingWithPath{\@ifnextchar[%
     {\@lstinputlistingWithPath}{\@lstinputlistingWithPath[]}}
\def\@lstinputlistingWithPath[#1]#2#3{%
    \def\@doLIstInput{\lstinputlisting[#1]}
    \expandafter\@doLIstInput\expandafter{#2/#3}
}
\makeatother
%
% --- end of code from newDistribution.Rnw in pkg distr --- %
%--------------------------------------------------------------

and in the .Rnw file I use

\lstinputlistingWithPath[firstline=<nn>, lastline = <nn>]%
         {\distrPATH}{R/<filename-of-myRsource>.R}

resp.

\lstinputlistingWithPath{\distrPATH}%
  {man/<filename-of-myRsource>.Rd}
 
to include some man-file.
>
> Perhaps you should just preprocess your Sweave files prior to the build.
> The brew package could be used, for example.
>   

I should have a look to it.

Thank you once again,
Peter



[Rd] relative path to source files in vignette [a solution somehow]
Peter Ruckdeschel