Search code examples
rr-markdownstan

How to extract stan code from .stan file in R


I want to display the stan code in Rmarkdon not using {stan} chunk. Now I'm searching the way of extracting the stan code from stan file(.stan) but, I can only find the way extracting stan code from stanfit object.

Is there any function in Rstan package or other packages ? If there are some solution, please teach me how to do.


Solution

  • I'm slightly confused. The Stan file itself is the Stan code. Hence, displaying the Stan code in Rmarkdown is very straightforward, if you do not wish to use the Stan chunk:

    writeLines(readLines("filename.stan"))
    

    Let me know if this was not what you wanted.