A nice feature of the mathematica documentation is the copious use of ExampleData in illustrating functionality. I would like to provide some example data for a package I have written, but there is apparently no guidance in the docs or on the net on how to do this. Consequently, I have two related questions:
Is there a hook into the system's
ExampleDatafunction for providing your own example data? I'm thinking along the lines of theImportExport`RegisterImport[]function that provides seamless integration of a custom import converter to theImport[]command.If not, what is a good way to provide example data from a custom package? Ideally, the data would be available from the documentation browser when someone tries one of the examples.
I would prefer to package the data together with the package code, rather than store it on a remote server and access it with Import["http://myserver.com/exampledata.zip"].
Answer
You could simply add new definitions for ExampleData in your package:
Unprotect[ExampleData];
ExampleData[{"JxBs Package", "RandomNumberSequence"}] := {7, 5, 8, 2, 1, 5, 3, 7, 9, 1};
Protect[ExampleData];
Which would make it available after loading your package
ExampleData[{"JxBs Package", "RandomNumberSequence"}]
{7, 5, 8, 2, 1, 5, 3, 7, 9, 1}
This is sort of cheating, but It will work for your code, just not with with ExampleData's listing of types, and properties.
Comments
Post a Comment