Re: Best way to save data in notebooks

*To*: mathgroup at smc.vnet.net*Subject*: [mg81920] Re: [mg81864] Best way to save data in notebooks*From*: John Fultz <jfultz at wolfram.com>*Date*: Sat, 6 Oct 2007 04:48:36 -0400 (EDT)*Reply-to*: jfultz at wolfram.com

On Fri, 5 Oct 2007 04:51:15 -0400 (EDT), Yaroslav Bulatov wrote: > What is the recommended way of removing dependence on external files? > > Consider the following code > > data=Import["largedatafile.csv"]; > ListPlot[data] > > I'd like to have "data" saved in the notebook, so that when I open it, > I can replot the data. My current solution is to copy and paste the > data manually into a separate mathematica cell (ie, data={1,2,3...}), > but that causes the front-end to freeze when largedatafile.csv is too > large. > > Yaroslav Assuming you're using version 6, you could get a compressed form by doing... Compress[data] ...then modify the output cell by putting the caret at the beginning and typing data=Uncompress@ which will convert the Output cell into an Input cell you can evaluate in the future. It's not quite as fast and convenient as DumpSave, of course, but if you really insist on keeping the data in the notebook, it'll work. Now it turns out that the graphic resulting from the ListPlot[] has all of the data you passed into it, in the aforementioned compressed form embedded in it. You can easily send that graphic back to the kernel to pick apart the expression (which is automatically uncompressed...no Uncompress[] command is required) and pull the data back out of it, without requiring the additional copy of the data my above procedure would create. Assuming you haven't used any exotic options to ListPlot (most noticeably, PlotMarkers, which will considerably change how the data are represented in the graphic), then typing the following input around the graphic (i.e. place the caret before the graphic and type, then after, and type, or using copy/paste to insert a copy of the graphic into a new Input cell) will get what you want... Cases[ <graphic> , Point[{x__}]:>x, 2] Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc.