Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

  1. Is there a hook into the system's ExampleData function for providing your own example data? I'm thinking along the lines of the ImportExport`RegisterImport[] function that provides seamless integration of a custom import converter to the Import[] command.

  2. 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"].

share|improve this question
question 1: no. There is no such way. Concerning 2 note that one point of ExmapleData is that it is distributed withouth getting a new copy of Mathematica. If you'd like to store the data with your package why not make a myData[stuff], add a Format rule and some selectors? –  user21 Aug 16 '12 at 18:04
I'm not sure if I fully understand this. 1) You want to deliver test data for your package 2) You want to package it with your package code. So, why don't you put this data in the same directory and Import it from there? Import[FileNameJoin[{NotebookDirectory[], "testfile.xls"}]] or so. What would an ExampleData version do more than that? –  Sjoerd C. de Vries Aug 16 '12 at 21:12
@SjoerdC.deVries Well, with ExampleData, one does not need to know the location of the data, as in jVincent's answer below. With Import, you need to know the location of the data file... –  JxB Aug 17 '12 at 1:52
...and that can be inconvenient when you want to access a canonical or standard example of data associated with your package. When I'm learning a new function from the docs, I often open a new (unsaved) notebook, get some data with ExampleData, and start playing. Is there a standard directory for storing data in a package, where Mma does not need to know the path? (I see $UserBaseDirectory<>"/ApplicationData", perhaps there?) –  JxB Aug 17 '12 at 2:02
As long as you put your data in the same folder as your notebook the above code would work wherever you would place that directory. jVincent's solution stores all the examples in your package code and they will all be in main memory after loading the package. Doesn't sound ideal to me, particularly if it would involve large data sets such as 3D objects. –  Sjoerd C. de Vries Aug 17 '12 at 6:01
add comment

1 Answer

up vote 9 down vote accepted

You could simply add new definitions for ExampleData in your package:

ExampleData[{"JxBs Package", "RandomNumberSequence"}] := {7, 5, 8, 2, 1, 5, 3, 7, 9, 1};

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.

share|improve this answer
why is it cheating? I think this is perfectly fine way to do it, except that some commands like ExampleData[] won't list your custom data, because it gets the list directly from DataPaclets`ExampleDataDump`Collections. Of course, one could easily modify it to handle these too. If the OP doesn't want to use a custom example data function, then this is a reasonable way out (although, standard warnings about modifying built-ins in a package apply and should probably be mentioned) –  rm -rf Aug 16 '12 at 18:24
@R.M I called it cheating because you end up with functionality which appears like ExampleData fully handles the new data, which it of cause doesn't, maybe a different term would be more appropriate. –  jVincent Aug 16 '12 at 19:16
Well, it depends on to what extents the OP is willing to go to mimic the built-in feature. For example, the no argument definition could be modified to, say, ExampleData[] := DataPaclets`ExampleDataDump`Collections ~Join~ {"JxBs Package"} // Sort and so on... Anyway, I think we both agree that this is a reasonable way to go for the OP :) –  rm -rf Aug 16 '12 at 19:20
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.