Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way/site/place/state of mind that lets you see the results of example code in a package's help

Tags:

r

R's help system is great, and I love that almost all help pages for a function include an example, but sometimes I wish there was a way to see the results of the example code without copying and pasting into my current session. This goes doubly for graphic functions.

Is there a way to do one of the following;

  1. Compile my help files with the results of the example code inline
  2. Generate pdf's of the help file with the results
  3. Have a web site with the help files and the results of the examples.
like image 589
PaulHurleyuk Avatar asked Aug 08 '11 14:08

PaulHurleyuk


People also ask

Can a Python programmer do anything to ensure that a variable's value can never be changed after its initial assignment?

Some values in python can be modified, and some cannot. This does not ever mean that we can't change the value of a variable – but if a variable contains a value of an immutable type, we can only assign it a new value. We cannot alter the existing value in any way.

Which is the correct location to place a docstring for a function?

Module docstrings are placed at the top of the file even before any imports. Module docstrings should include the following: A brief description of the module and its purpose. A list of any classes, exception, functions, and any other objects exported by the module.

What does the statement a foolish consistency is the hobgoblin of little minds mean in the context of coding in Python?

A Foolish Consistency is the Hobgoblin of Little Minds One of Guido's key insights is that code is read much more often than it is written. The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code.

What is PEP 8 and why is it important?

PEP 8, sometimes spelled PEP8 or PEP-8, is a document that provides guidelines and best practices on how to write Python code. It was written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan. The primary focus of PEP 8 is to improve the readability and consistency of Python code.


2 Answers

example(foo) is the usual interface to function foo. It will echo the example code to the console a line/chunk at a time, and pause between plots.

R's help system will soon be more fully dynamic, but this will only (IIRC) help matters if the package author rewrites all or parts of the man pages to include dynamic content. I'm not aware of a proposal to include output from examples in the new dynamic help, but it could potentially be done. If you have the standard R toolchain installed, you could grab package sources and check them - that creates an R file with the concatenated example code used for checking that the examples work.

(2) is getting a bit close to a vignette.

like image 115
Gavin Simpson Avatar answered Jan 08 '23 01:01

Gavin Simpson


Use example, eg:

example(hist)

Or see the R Graphical Manual.

like image 22
James Avatar answered Jan 08 '23 03:01

James