I am trying to write an R Markdown document that includes a Cmdstan object. If I knit the whole document it runs, but if I try to execute it chunk by chunk I get the error message " /bin/sh: cmdstan: command not found" when I execute the chunk containing the Stan code.
When you call register_knitr_engine() with no arguments, the default behaviour is to only register cmdstanr for processing stan blocks. If you want to use cmdstanr for cmdstan blocks (like in your notebook), you need to instead call:
Ah! Many thanks. I misread the first paragraph of the section on using rstan and cmdstanr together as implying that the override statement was needed only if both rstan and cmdstanr were being used.
@jonah I’d be glad to do so. Give me a day or two to work something out.
Are you aware of the two rules about dealing with comments on a draft?
Rule 1: no comment, however daft, should be ignored or dismissed. I have spent many years dealing with authors who do not behave in that way.
Rule 2: no specific drafting change put forward by someone outside the team, however convincing it seems to be, should ever be accepted without the most critical analysis. I have spent many years dealing with authors who have accepted specific drafting that makes a nonsense of something else in the document.
So, you have very wisely observed Rule1. I shall be very happy if you treat my suggestions under Rule 2.
Sounds good, thanks for being willing to help out. I was not aware of those rules specifically, but I like them quite a bit. Thanks for sharing.
And no rush if you need more than a few days, I don’t think we’ll do another release for at least a few weeks (although we could still update the website version of the vignette between releases). In the meantime we now at least have a solution on the forum in case anyone else runs into this issue.
I’d like to amend the document in a way that you can track the changes. I don’t know how to do that using Github: I have only ever amended my own documents on Github and I am not a heavy user of it.
Can you point me to simple instructions?
Since you’re only editing that single file this is a bit simpler than it would be if you were going to update many files (you can do this all from within the web browser).
That should take you to a page where you can click on a button to “fork” the repository (unless you already have a fork, in which case let me know).
After that it should let you edit the file and when you’re done click the green “Commit changes” button followed by the “Propose changes” button that comes up after that.
That process will let you submit a “pull request” proposing your edits and we’ll be able to see and comment on the specific changes you made. Let me know if you run into any trouble when trying that.
At this stage you might see something about running the unit tests, but that will happen automatically when one of us reviews it so don’t worry about that.
Thanks. Now that I have started working on this I have a further query about the text. In the section about using both RStan and CmdStanR an example is given in which the CmdStanR chunk is:
```{cmdstan, output.var="model_obj2"}
// Results in a CmdStanModel object from CmdStanR
```
and that seems logical to me, but earlier in the document we see presented as an example of the CmdStanR option:
```{stan, output.var="model"}
// Stan model code
```{r}
model$sample()
```
Is that right? Why stan and not cmdstan as in the later example?
I think this depends on whether you set override to TRUE (the default) or FALSE when calling register_knitr_engine(). If override=TRUE then that makes stan chunks use CmdStanR instead of RStan (this is what you see earlier in the document). If override=FALSE then stan chunks still use RStan and cmdstan chunks use CmdStanR. It’s rare to need to use RStan and CmdStanR in the same document, but this option is provided for those cases when someone wants to do that (e.g. educational materials showing how to use both interfaces to Stan).
I have just submitted my proposed redraft. I hope it is clear but I think I might still have become confused about when override=TRUE or override=FALSE is to be used.
Can you share the url to where this is? I think something went wrong because it doesn’t show up at Pull requests · stan-dev/cmdstanr · GitHub. Maybe it created the pull request in your own fork of the repository instead of from your fork to our master branch. I thought my instructions should have handled that ok, but I might have overlooked something (sorry if that’s the case!). I should be able to tell based on the url to where the request was created.
Ok great. At this url do you see a “Create pull request” button? If so go ahead and click that and then potentially you’ll have to click “Create pull request” again on the next page.