Skip to content
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

provide implementation of 'eng_stan' for knitr #555

Open
kevinushey opened this issue Aug 31, 2018 · 13 comments
Open

provide implementation of 'eng_stan' for knitr #555

kevinushey opened this issue Aug 31, 2018 · 13 comments

Comments

@kevinushey
Copy link

The intention is to move the implementation of eng_stan() to the rstan package, so that the engine implementation can evolve as the rstan package evolves.

As an example, we do this with the reticulate package here:

https://github.com/rstudio/reticulate/blob/master/R/knitr-engine.R

See also: yihui/knitr#1602.

@sakrejda
Copy link
Contributor

The flow-of-control by itself in this stuff makes me want to run away screaming. I mean I like that it's possible but sometimes you just want to close that sarcophagus right back up.

@bob-carpenter
Copy link

@sakrejda --- please keep the discussions constructive on our users' lists.

@bob-carpenter
Copy link

@kevinushey What is eng_stan()? Could you be more specific about what you're proposing? We want to avoid having people open issues then spend a lot of time on them if we're not going to accept them in the end. The best defense against that is to be specific about what you're proposing to add and get buy-in from the RStan devs up front. Thanks.

@sakrejda
Copy link
Contributor

sakrejda commented Sep 3, 2018

@bob-carpenter knitr allows inline Stan code, eng_stan() is part of processing that, that should explain why my comment, while slightly off topic, was constructive. This would be fun to support but yikes.

@bob-carpenter
Copy link

I don't like that they auto compile Stan code. I prefer to manage all that myself in my knitr docs, but would also like Stan code highlighting.

I think you may need to translate that comment for the rest of us if it was meant to be constructive rather than dismissive.

@bgoodri
Copy link
Contributor

bgoodri commented Sep 3, 2018 via email

@bob-carpenter
Copy link

bob-carpenter commented Sep 3, 2018 via email

@sakrejda
Copy link
Contributor

sakrejda commented Sep 3, 2018

Re: translating: I think @kevinushey was suggesting that we should take control (and therefore reponsibility) for the rstan code. I think it would be cool but daunting, that's all.

Overall I don't think the knitr-compatible engine for processing Stan code chunks (eng_stain()) is an rstan-specific thing (unless we want rstan to become the dumping ground for all things Stan-related in R). With maintenance burden and all I don't think we want that. It probably would make sense as a separate small package.

@bgoodri
Copy link
Contributor

bgoodri commented Sep 3, 2018 via email

@bob-carpenter
Copy link

bob-carpenter commented Sep 3, 2018 via email

@bgoodri
Copy link
Contributor

bgoodri commented Sep 3, 2018 via email

@sakrejda
Copy link
Contributor

sakrejda commented Sep 3, 2018

I definitely don't use RStudio but do use RMarkdown, they're unrelated, a separate package is the place to implement something like this. The key question is what @bgoodri raised: how do you really want this to look in RMarkdown output. This is a pretty general problem in knitr/RMarkdown where it's not obvious from the UI when output is available across chunks (esp. when you get into multiple languages).

@kevinushey
Copy link
Author

Just to be clear what I'm proposing: knitr already defines an chunk engine for Stan code, called eng_stan(). That implementation currently lives here:

https://github.com/yihui/knitr/blob/4cf7a6f1ef3e083464823a15921385a452177412/R/engine.R#L248-L273

Having the engine implementation live in knitr means it's somewhat more difficult for that engine to evolve, as changes must then be accepted as a PR to knitr, and access to the new engine will only occur with the next CRAN update of knitr. My proposal is to instead move that definition back to the rstan package, and teach knitr how to call + use that engine instead (so that eng_stan() could evolve as part of the rstan package as needed).

We could of course do some extra magic in RStudio to tweak how Stan chunks are run / displayed, but I imagine that in general it would be best if Stan engine output in R Markdown documents was universal and did not depend on the environment from which it was run.

In the context of what might change in the engine, it seems like a change as simple as having eng_stan() emit a message after successful compilation of the form:

[Stan model successfully compiled and assigned to variable 'model']

and I assume a message like that would almost always be appropriate, but could potentially be controlled with a chunk option if so desired.

That said, if this is output that we'd only ever want to see when compiling a Stan chunk interactively then we can just make the requisite changes in RStudio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants