开发者

R demo() and example() methods?

Is there a simple way to check if R functions and packages have demo() and example() methods?

When building a package, does the package need to have the necessary objects so that demo() and example() can be called on it?

Edit: In trying to answer this, I checked the source code of d开发者_开发技巧emo()

demo(package = .packages(all.available = TRUE)) # check which packages have demo


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)).  


You can always look at the sources of package 'myPkg', or even run R CMD check myPkg over the sources as that will extract a file myPkg-Ex.R containing the examples.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜