Neither examples nor demos are required to build a package.
The example()
function can be run on any other function, and it just runs the commands in the "Examples:" section of the help file (excluding ones that have ## Not run:). Also see this related stackoverflow question.
For instance, look at ?example and then call example(example).
Regarding the idea of finding all functions that have examples: that's possible, although I'm not aware of any particularly easy way of doing it. I would probably use the existing examples function but alter it so that it doesn't execute the example functions and then run it across all functions in my installed packages. But that's probably not worth the effort because it will return a HUGE list of functions (most R documentation has an example). You're better of just trying example(function.name) whenever you're curious about a specific task.
You've already answered your own question about demo()
: demo(package=.packages(all.available = TRUE)).