[Rd] relative path to source files in vignette
Gabor Grothendieck
ggrothendieck at gmail.com
Sat Oct 11 01:59:59 CEST 2008
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.
More information about the R-devel
mailing list