I have a very simple question really. There's a demo function demo()
i.e. demo(scoping)
which runs a demo of the topic. How do I write something like this for my own package? Its crazy but I have tried googling for any documentation related to it but there is none available (either that or my googling skills suck big time). I tried the documentation for devtools and roxygen too but maybe I missed it.
Can anyone point me in a right direction? Are there any packages which can generate it during the package installation? Or do I have to write it manually (I'm totally fine with that but right now I have zero information on this).
And yes, I would want to be able to do it in R console (not rstudio).
While roxygen2
does not allow you to create demos, it does allow you to include special @examples
within the documentation[1]. These showup in your function or object help pages and can even be run automatically upon loading the package to test for functioning dependencies, or they can just serve as examples to your end users.
devtools
on the other hand offers vignettes which is a "long-form guide to your package"[2]. These can be accessed through your overall package documentation and actually linked to anywhere within your documentation. You can make multiple vignettes and make them function or work-flow specific, organized by function family or something similar.
If you are adamant about using demos, you'll have to manually go through the trouble of establishing the proper directories, formatting and testing the demo files. If you do intend to go down this path, Hadley Wickham has some very sparse documentation on the subject here: [3].