I recently noticed that when dealing with notebooks with local context, I cannot successfully DumpSave variables, or, rather, when I call Get on the non-empty .mx files, the notebook does not recognize the variables.
As a test, I created two notebooks, one with a global context and the other with a local context, that is, for the latter notebook, I ran the command:
SetOptions[EvaluationNotebook[], CellContext->Notebook];
In both notebooks, I defined variables that contained a list of points from a standard NormalDistribution and plotted them using ListPlot. I used
DumpSave["filename.mx", {datavariable,plotvariable}];
to preserve both the data and plot. Long story short, after I save and close both notebooks and restart Mathematica , neither notebook recognizes the variables used for the data or plot, but after using Get in the global notebook, the notebook does recognize the old variables.
Furthermore, when I run a DumpSave command from the 'local' notebook that saves the entire context, i.e. DumpSave["filename.mx", Evaluate@Context[]], I do get back the definitions. This doesn't solve my problem though, as I want to preserve only a few variables in the code that I am working on: saving the entire context, or, more specifically, all of the definitions associated with the context, would require too much memory for an application I have in mind.
Are there any solutions using DumpSave or should I resort to other methods?
Update, I've pasted the exact code below:
SetOptions[EvaluationNotebook[], CellContext -> Notebook];
distribution = NormalDistribution[];
thedata = RandomVariate[distribution, 1000];
theplot = ListPlot@thedata;
DumpSave["test2.mx", {thedata, theplot}];
`SetOptions[EvaluationNotebook[], CellContext -> Notebook];
distribution = NormalDistribution[]; thedata = RandomVariate[distribution, 1000]; theplot = ListPlot@thedata;
DumpSave["test2.mx", {thedata, theplot}];`
When I close the notebook, and Mathematica, then relaunch everything and call
– shdrums9 Apr 09 '13 at 21:21Geton the test2.mx file, it doesn't recognizethedataortheplot