[R] Including a text file (JAGS model) in an R package

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Aug 2 19:32:51 CEST 2010


Here is how I do it:

write("
model {
   for (year in 1:N) {
        D[year] ~ dpois(mu[year])
        log(mu[year]) <- b[1] + step(year - changeyear) * b[2]
   }
   for (j in 1:2) { b[j] ~ dnorm(0.0, 1.0E-6) }
   changeyear ~ dunif(1,N)
}
", "coalmining.jags")

which has the advantage that the model description is right there in 
the .Rd file.

If you want a file to be part of the package, put it in e.g.

<pkg source>/inst/JAGSmodels/model.txt

and in the example use

system.file("JAGSmodels", "model.txt", package="whatever")


On Mon, 2 Aug 2010, Conor Lawless wrote:

> Hello,
>
> I can`t figure out how to include a text file for use in an example in the .Rd help files of an R package I am writing.
>
> I want the examples section of one help file to look like this:
>
> \examples{
>
> # Load the JAGS model
> mod <- jags.model("model.txt")
>
> }
>
> The function jags.model tries to read in the file model.txt.  So far every time I run R CMD check, I get an error message:
>
> Error in jags.model("model.txt"): Cannot open model file "model.txt"
>
> It's not clear to me where in the package directory structure I can put this file to make this example work.  I've tried demo, inst, data and man.
>
> Is it possible to do this?  If not, how can I go about including a JAGS model in an R package example?
>
> Regards,
>
> CONOR.
>
>
>
> __
> (oO)
> /||\
> Biogerontology
> Institute for Ageing and Health
> Newcastle University
> Campus for Ageing and Vitality
> Newcastle upon Tyne
> NE4 5PL
> UK
>
> tel: +44 (0)191 248 1218

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list