4
$\begingroup$

I create data table in my notebook by importing a excel spreadsheet using:

s0 = Import["G:\\Meu Drive\\Planilhas\\resultados_analises.\xlsx",{"Data", 3, Range[5, 54], Range[1, 11]}]

Then I create others tables subselecting s0 and make a bunch of analysis, plots etc.

I used

PersistentValue["s0"] = s0

and then delete (or comment) the Import command and the PersistentValue above. Then I saved the notebook, open it again and type:

s0 = PersistentValue["s0"]

Then save the notebook again such that every time I load the notebook I work with the same s0 that was imported before instead of Importing again.

My question is: The values associated with s0 is persisted in the notebook forever? Can I move the notebook to another computer, por example?

Or there is a better way to persist my data in the notebook such that I can delete (or comment) the import command?

Thank in advance

$\endgroup$
0

1 Answer 1

3
$\begingroup$

My usual way of handling this sort of thing is to use Iconize. So I would write:

s0 = Iconize[
  Import[
    "G:\\Meu Drive\\Planilhas\\resultados_analises.\xlsx",
    {"Data", 3, Range[5, 54], Range[1, 11]}
  ],
  "My Spreadsheet 2021-12-29"
];

Then I would highlight everything after the = and before ; and select Evaluation > Evaluate in Place (CMD + ENTER on Mac). Then, I would run the entire cell normally to assign the spreadsheet to s0. The second argument ("My Spreadsheet 2021-12-29" here) is optional but useful for giving it a name that you'll recognize in the future.

This creates a small little icon that represents the imported spreadsheet. This icon can be copied and pasted to new notebooks, and after running the above code, either s0 or the icon itself can be used exactly as you would use s0 from your original code. The icon is persistent between notebooks, and there's no risk of accidentally re-importing when running, because the import only happens when you first use Evaluate in Place.

$\endgroup$

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