2
$\begingroup$

I have a Workbench project in which I have created two packages: PackageA.m and PackageB.m. In the same project, there is a notebook called Test.nb.

When I right-click Test.nb in the navigator and select Run As -> Mathematica, I find that all of the symbols in the two packages are loaded even though I have not actually executed

(* These lines have not been executed! *)
<<"PackageA`";
<<"PackageB`";

For instance, when I run

(* DemoSum is a function defined in PackageA *)
DemoSum[2, 3]

I get the answer 5.

Is there a way to prevent all the packages from loading automatically when I right-click a notebook and select "Run As -> Mathematica"?

$\endgroup$
  • $\begingroup$ May I ask why you would want to do that rather than simply opening your notebook outside the Workbench ? $\endgroup$ – b.gates.you.know.what Jan 23 '15 at 9:20
  • $\begingroup$ @b.gatessucks It is a pretty big code base, and there is a lot of code that I would have to copy over if I were to open the notebook outside of Workbench. (But I am headed in that direction since I am refactoring everything.) $\endgroup$ – Shredderroy Jan 23 '15 at 20:32
  • $\begingroup$ Thank you for your explanation. $\endgroup$ – b.gates.you.know.what Jan 23 '15 at 23:07
2
$\begingroup$

File Loading in Workbench is controlled by couple of properties.

First there's Execution Build Command that is part of project properties. If "Execution Build Command" is set it is evaluated when you start Mathematica session using "Run As -> Mathematica". If during such session you save changes to any source file, "Execution Build Command" is evaluated again.

If there's no "Execution Build Command" in a project, then automatic file loading occurs. Whether source files, will be loaded when working in particular notebook is controlled by notebook properties. Which source files will be loaded (if any) is controlled by source file properties.

So you have three options.

  1. Disable automatic package loading completely, in a project, by setting "Execution Build Command" to something that doesn't load packages e.g. None.
  2. Disable automatic package loading for particular notebook, by removing "Execution Build Command" and choosing "No" in "Load all source files on startup" section of notebook properties.
  3. Disable automatic loading of specific packages, by removing "Execution Build Command" and choosing "No" in "Automatic load on startup:" section of source file properties.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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