evaluates all the evaluatable cells in notebook.
Details and Options
- NotebookEvaluate returns the value returned by the last evaluation in the specified notebook.
- NotebookEvaluate can take either a NotebookObject or a file name referencing a notebook file. If a file name references a notebook that is presently open, then evaluation proceeds on the open notebook.
- The following options can be given:
InsertResults False whether to insert results into notebook EvaluationElements All which cells to evaluate
- By default, NotebookEvaluate displays the side effects of evaluation similarly to how a call to Get would. Messages, print output, and other side effects will be placed as output to the cell that called NotebookEvaluate rather than in notebook. Existing output cells in notebook will not be updated or deleted.
- NotebookEvaluate[notebook,InsertResults->True] handles side effects and outputs as they would be handled in a evaluation. Messages, print output, and other side effects are placed in notebook along with outputs, and will replace any existing output or side effect cells.
- When NotebookEvaluate[notebook,InsertResults->True] is used on a file that is not open, the Wolfram System will invisibly open the file, evaluate it entirely, save, and close the file.
- NotebookEvaluate[notebook,InsertResults->False] will leave notebook completely unmodified.
- The cells of notebook are evaluated in a dialog subsession.
- Using NotebookEvaluate on an open notebook will cause the visible artifacts of subsession evaluation to occur in that notebook. The notebook will continue to be updated on screen as necessary while its cells are being evaluated.
- Unlike Get, the presence of a syntax error in an evaluatable cell will not prevent NotebookEvaluate from evaluating other inputs.
- NotebookEvaluate[notebook,EvaluationElements->Automatic] evaluates only the initialization cells. This is equivalent to saving the notebook as a package file, or with an automatically generated package file, and using Get on the resulting package file.
- When run on a package file, NotebookEvaluate is equivalent to Get. The InsertResults option will be ignored.
Examplesopen allclose all
Generalizations & Extensions (1)
NotebookEvaluate can be nested:
Insert results in the target notebook:
By default, messages go into the output:
With InsertResults->True, the messages go to the target notebook instead:
Properties & Relations (2)
% works in notebooks targeted by NotebookEvaluate:
NotebookEvaluate works with session history, and the return value is not suppressed by ;:
Possible Issues (2)
Notebooks evaluate in their default context, which may be different from the context used by NotebookEvaluate:
If the contexts need to be the same, it may be necessary to set the CellContext option of the notebook:
Evaluation history is scoped to the notebook being evaluated:
Wolfram Research (2010), NotebookEvaluate, Wolfram Language function, https://reference.wolfram.com/language/ref/NotebookEvaluate.html.
Wolfram Language. 2010. "NotebookEvaluate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NotebookEvaluate.html.
Wolfram Language. (2010). NotebookEvaluate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NotebookEvaluate.html