I’m creating my second real R package, the first that uses any Stan functionality. For now, it’s proprietary, so I can’t upload it to GitHub.
I’m running R 3.6.1 on Windows 10, and all my packages are current as of yesterday. In particular, I’m running brms 2.9.0. My normal IDE is ESS.
Since the last time I did a package,
usethis has come into the picture, so I’m trying to learn somewhat new processes, build on what I knew, and refer to Hadley’s book as much as I can.
My immediate question has to do with a model implemented in
brms. There are three ways that model is to be used:
- I want to save a fitted model in the package and then use it as the default model for prediction.
- I want to allow the user to fit the model to new data and save the fitted model for later reuse.
- I want to allow the user to use the model to predict outcomes in an optimization process using
I discovered “Guidelines for developers of R packages interfacing with Stan” today, which leads to my first question:
- Should I simply run
stan_package_skeletonover top of my fledgling package? I see that
usethis::create_packagesays it “can be called on an existing project”; I haven’t found any such statement in the
I also read “Step by step guide for creating a package that depends on RStan.” It seems focused on Stan models and Stan source. My second question:
- Is there corresponding information that points to where and how I deal with a
Given my three model uses,
- First, is there a preferred way to store the fitted model as part of the package and recall it later? I know a bit about the
data()function; I sorta want the same thing for a
brmsfitobject, I think.
- I think the second use is simple: if I export the function that fits the model, the user can fit the model to whatever data is appropriate, and the
fileargument can say where it should be stored.
- I think the third use case is similar to the first. It sounds easy to predict values from an existing model if I can pass the model to the function, which seems straightforward in the second case. I don’t think I know how to pass the default model (use case 1) properly.
- Is there an existing, perhaps not too complex package, that does much of what I’ve described so that I can look at it?
I welcome any and all insights; I realize I’m at the front of this learning curve.