({{, (RefLink[InitializationValue, paclet:ref/InitializationValue])[sym]
represents the settable persistent value with which the symbol sym will be initialized.}, {, (RefLink[InitializationValue, paclet:ref/InitializationValue])["context`name"]
represents the settable initialization value for the symbol with the specified complete name.}, {, (RefLink[InitializationValue, paclet:ref/InitializationValue])[sym,{(Subscript[loc, 1]),…}]
specifies the persistence locations to search for a possible initialization value.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[InitializationValue, paclet:ref/InitializationValue])[sym] is equivalent to (RefLink[InitializationValue, paclet:ref/InitializationValue])[sym,(RefLink[$PersistencePath, paclet:ref/$PersistencePath])].

(RefLink[InitializationValue, paclet:ref/InitializationValue])[sym]=value sets an initialization value for sym.

(RefLink[InitializationValue, paclet:ref/InitializationValue])[sym]=value is equivalent to (RefLink[InitializationValue, paclet:ref/InitializationValue])[sym,(RefLink[$PersistenceBase, paclet:ref/$PersistenceBase])]=value.

The following options can be given:

In (RefLink[InitializationValue, paclet:ref/InitializationValue])[sym,loc], possible forms for the persistence location loc include:

Supported location types include:

(RefLink[InitializationValue, paclet:ref/InitializationValue])[sym]=(RefLink[$NoValue, paclet:ref/$NoValue]) specifies that the symbol sym should be unset on initialization.

Before a new value is assigned in (RefLink[InitializationValue, paclet:ref/InitializationValue])[sym]=value, any specified value preprocessing function is applied to value before the value is assigned.

If the preprocessing function returns (RefLink[$Failed, paclet:ref/$Failed]), the assignment is not performed.

If no explicit setting for (RefLink[ValuePreprocessingFunction, paclet:ref/ValuePreprocessingFunction]) is given, the setting to use is looked up on (RefLink[$PersistencePath, paclet:ref/$PersistencePath]).

An expired initialization value is treated as nonexistent, and the underlying persistent object may be removed.

Initialization values can be removed with (RefLink[Remove, paclet:ref/Remove]). (RefLink[Remove, paclet:ref/Remove])[InitializationValue[name]] is equivalent to (RefLink[Remove, paclet:ref/Remove])[InitializationValue[name,(RefLink[$PersistenceBase, paclet:ref/$PersistenceBase])]].

OpenersPrimaryExamplesSection(Spacer1)Examples  (13)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Set a value to be evaluated every time the kernel starts:

InitializationValue[$Initialization]=Hold[data=Get["mydata.m"]]

Set an initialization value for a variable:

InitializationValue[myvar,"KernelSession"]=42

Initialize the variable from the persistent value in the current kernel session:

Initialize[myvar];

myvar

OpenersExampleSection1(Spacer1)Generalizations & Extensions  (1)

Set an initialization value for parallel subkernels:

InitializationValue[$TimeZone,"Local",EvaluationEnvironment->"Subkernel"]=0;

All newly launched parallel subkernels use the given value:

LaunchKernels[2];

ParallelEvaluate[$TimeZone]

Remove the initialization value:

Remove[InitializationValue[$TimeZone,"Local",EvaluationEnvironment->"Subkernel"]]

OpenersExampleSection2(Spacer1)Options  (5)

OpenersExampleSubsection0(Spacer1)EvaluationEnvironment  (1)

Set an initialization value for parallel subkernels:

InitializationValue[$TimeZone,"Local",EvaluationEnvironment->"Subkernel"]=0;

OpenersExampleSubsection1(Spacer1)MergingFunction  (1)

Establish a default value and merging function for an initialization value:

InitializationValue[ivar,"Local",MergingFunction->Flatten]={};

Add an initialization value at the front end persistence location:

InitializationValue[ivar,"FrontEndSession"]={ival1};

The resulting initialization value now uses the default merging function:

InitializationValue[ivar]

When the variable is initialized, the default merging function is used:

Initialize[ivar];
ivar

OpenersExampleSubsection2(Spacer1)ValuePreprocessingFunction  (1)

Define a value preprocessing function for a particular initialization value that accepts only integers:

validateInteger[x_]:=If[IntegerQ[x],x,$Failed]

InitializationValue[var3,"Local",ValuePreprocessingFunction->validateInteger]=0;

Assign an integer at any persistence location:

InitializationValue[var3,"FrontEndSession"]=2;

Assigning anything else generates an error, and the assignment is not performed:

InitializationValue[var3,"Local"]=1.5;

OpenersExampleSubsection3(Spacer1)PersistenceTime  (1)

Define an initialization that will expire in 5 seconds:

InitializationValue[var1,"Local",PersistenceTime->5]=42;

Initialize[var1];
var1

Clear[var1];
Pause[5];
Initialize[var1];
var1

OpenersExampleSubsection4(Spacer1)ExpirationDate  (1)

Define an initialization value that expires at the beginning of next year:

InitializationValue[var2,ExpirationDate->NextDate["Year"]]=2;

OpenersExampleSection3(Spacer1)Applications  (2)

Override the default persistence base in all kernels started under the current front end session:

InitializationValue[$PersistenceBase,"FrontEndSession"]="KernelSession";

Quit and restart the kernel:

Quit[]

$PersistenceBase

Set a value for (RefLink[$GeoLocation, paclet:ref/$GeoLocation]) tied to your login account:

InitializationValue[$GeoLocation,"Local"]={47.190,8.7048,600.};

OpenersExampleSection4(Spacer1)Properties & Relations  (2)

Initialization values are stored in persistent objects:

InitializationValue[Global`myvar]=42;

PersistentObjects["*myvar"]

List the existing initialization values in all editable persistence locations:

InitializationObjects[All,{"FrontEndSession","Local","Notebook","Cloud"}]

Remove them:

DeleteObject[%[[All,2]]]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

Create two initialization values for a symbol in different locations:

InitializationValue[myvar,"KernelSession"]=42;
InitializationValue[myvar]=43;

(RefLink[Remove, paclet:ref/Remove]) by default removes only the value in the location given by (RefLink[$PersistenceBase, paclet:ref/$PersistenceBase]):

Remove[InitializationValue[myvar]]

InitializationValue[myvar]

Remove all values that might exist anywhere in the locations given by (RefLink[$PersistencePath, paclet:ref/$PersistencePath]):

Remove[InitializationValue[myvar,$PersistencePath]]

InitializationValue[myvar]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Initialize, paclet:ref/Initialize])  ▪  (RefLink[InitializationObjects, paclet:ref/InitializationObjects])  ▪  (RefLink[$Initialization, paclet:ref/$Initialization])  ▪  (RefLink[PersistentValue, paclet:ref/PersistentValue])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Wolfram System Setup, paclet:guide/WolframSystemSetup])}, {▪(RefLinkPlain[Initialization & Provisioning, paclet:guide/InitializationAndProvisioning])}, {▪(RefLinkPlain[Setting Persistent Values, paclet:guide/SettingPersistentValues])}, {▪(RefLinkPlain[Session Customization, paclet:guide/SessionCustomization])}, {▪(RefLinkPlain[Persistent Storage, paclet:guide/PersistentStorage])}})}})