New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pass stan code from CmdStanArgs -> RunSet -> CmdStanFit #575
Conversation
warning("'$code()' will return NULL because the 'CmdStanModel' was not created with a Stan file.", call. = FALSE) | ||
return(NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this from an error to a warning and returning NULL. This makes it easier to pass around the Stan code without having to use try()
to avoid errors.
advances #574
#' cat(fit$code(), sep = "\n") # pretty print | ||
#' } | ||
#' | ||
code <- function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I named the method code()
because that's the same name as the CmdStanModel method for returning the code. Alternatively we could use fit$stan_code()
instead of fit$code()
, but then I would want to do the same for CmdStanModel and deprecate mod$code()
in favor of mod$stan_code()
. Any preference? I'm open to either (or some other name).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stan_code is unambiguous,. would anyone expect to get c++ code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think anyone would expect c++ code, so code()
is probably fine. That said, stan_code()
is definitely unambiguous so I'm open to that too. @rok-cesnovar do you have a preference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No preference. I dont think anyone would expect C++ honestly, maybe no need to change atm.
code <- function() { | ||
stan_code <- self$runset$stan_code() | ||
if (is.null(stan_code)) { | ||
warning("'$code()' will return NULL because the 'CmdStanModel' was not created with a Stan file.", call. = FALSE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you reconstitute fit object from CSV files, will also not get Stan code, unless you get fancy w/ saving the stan file along with the CSV files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I don't think we should get too fancy and store the Stan file with the CSV files. I can just add an error message for that case saying that this method isn't available (there are already a few other methods unavailable when recreating from CSV files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (note, not really fluent in R)
Codecov Report
@@ Coverage Diff @@
## master #575 +/- ##
==========================================
+ Coverage 91.93% 93.10% +1.16%
==========================================
Files 12 12
Lines 3163 3233 +70
==========================================
+ Hits 2908 3010 +102
+ Misses 255 223 -32
Continue to review full report at Codecov.
|
Looks good to me. |
Ok I think we can go ahead and merge this. Will do that now. |
Submission Checklist
Summary
closes #175
Adds
$code()
method to fitted model objects for returning Stan code. This is accomplished by first passing the Stan code via CmdStanArgs to RunSet and then from RunSet to CmdStanFit.Copyright and Licensing
Please list the copyright holder for the work you are submitting
(this will be you or your assignee, such as a university or company):
Columbia University
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses: