From ggrothendieck at gmail.com  Sat Oct 11 01:59:59 2008
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Fri, 10 Oct 2008 19:59:59 -0400
Subject: [Rd] relative path to source files in vignette
In-Reply-To: <48EFDFE9.1050806@web.de>
References: <48EF9CAD.8090006@web.de>
	<971536df0810101127n49084413pd97ec451e3040228@mail.gmail.com>
	<48EFA380.8080801@web.de>
	<971536df0810101334w12014877t408732c9f12edc20@mail.gmail.com>
	<48EFDFE9.1050806@web.de>
Message-ID: <971536df0810101659j710b91cahdf7e4fac3b0af280@mail.gmail.com>

On Fri, Oct 10, 2008 at 7:06 PM, Peter Ruckdeschel
<peter.ruckdeschel at web.de> wrote:
> Thanks again Gabor, for your quick reply,
>> Try placing a copy of the files in the inst directory and then
>> accessing them via system.files("myfile.R", package = "mypackage")
>>
> you mean I should do this in an S-chunk in the .Rnw file?
> I.e., running Sweave on it would then produce the copy into my Sweave file
> I need?
>
> This could indeed be an opition, 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.

>
>> or place them in the same directory as the Sweave file
>> and then access them without a directory path at all:
>> readLines("myfile.R")
>>
> If I put the sources statically into the same directory as the Sweave file
> (i.e. in [...]/myRsources/myPkg/inst/doc),
> of course everything works fine;
>
> The issue is that I want to "dynamically" include parts of the source
> R code itself (without unnecessary static copying the source R code
> due to consistency traps, when changing the R code but not
> the copy)  from the R directory of the package into the Sweave
> file by something like
>
>  \input{[Path]/myRfile.R}
>
> so that once I change the R code, I do not have to change
> the .Rnw file.
>
> [I do not include the whole .R file but only certain lines of it, of course]
>
> As already said, in a standard configuration something like
> \input{../../../myPkg/R/myRfile.R}
>   % goes from [...]/myRSources/myPkg/inst/src to [...]/myRSources/myPkg/R
>   % in R CMD build
>   % resp. from [...]/myRSources/myPkg.Rcheck/inst/src to
> [...]/myRSources/myPkg/R
>   % in R CMD check
> does the job.
>
> Now if I am in [...]/myRSources and say something like
>
> R CMD build myPkg     ### still works
> R CMD check myPkg -o  /yetAnotherPath/myCheck
>   ## does not work as  /yetAnotherPath/myPkg/R need not be [...]/myPkg/R
>
> So what I was looking for was something like defining an environment
> variable
> $myRSources (in a platform-independent way)
> which may be accessed (in a platform-independent way) from
> the TeX command \input{...}  --- perhaps with something like
>
> \input{$myRSources/myPkg/R/myRfile.R}
>
> but I cannot figure out how to do this...
>
> Thank you once again
> Peter
>
>

Perhaps you should just preprocess your Sweave files prior to the build.
The brew package could be used, for example.



[Rd] relative path to source files in vignette
Gabor Grothendieck