({{, (RefLink[LocalObject, paclet:ref/LocalObject])[] 
represents a new anonymous local object.}, {, (RefLink[LocalObject, paclet:ref/LocalObject])["file:/// …"]
represents a local object with a given file path.}, {, (RefLink[LocalObject, paclet:ref/LocalObject])["relpath"]
represents a local object with the given relative path.}, {, (RefLink[LocalObject, paclet:ref/LocalObject])["relpath","lbase"]
represents a local object relative to the base lbase.}})

OpenersNotesSection(Spacer1)Details

Relative paths are resolved with respect to (RefLink[$LocalBase, paclet:ref/$LocalBase]).

(RefLink[LocalObject, paclet:ref/LocalObject])[(RefLink[File, paclet:ref/File])["path"]] and (RefLink[LocalObject, paclet:ref/LocalObject])[relpath,(RefLink[File, paclet:ref/File])["path"]] are also supported.

(RefLink[DeleteObject, paclet:ref/DeleteObject])[LocalObject[…]] removes a local object.

OpenersPrimaryExamplesSection(Spacer1)Examples  (18)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

An unnamed local object:

LocalObject[]

A named local object in the user's local base directory:

LocalObject["myobject"]

A named local object in a subdirectory of the user's local base directory:

LocalObject["mydir/myfile"]

Remove a local object:

Put[0,LocalObject["zero"]]

DeleteObject[LocalObject["zero"]]

OpenersExampleSection1(Spacer1)Scope  (7)

Local objects can be used with (RefLink[Put, paclet:ref/Put]) and (RefLink[Get, paclet:ref/Get]) to store expressions persistently:

Put[10!,LocalObject["myval"]]

Get[%]

Local objects can be used with (RefLink[Export, paclet:ref/Export]) and (RefLink[Import, paclet:ref/Import]) to store data persistently:

Export[LocalObject["plot"],Plot[Sin[x],{x,0,10}],"PNG"]

Import[%]

Local objects can be used with (RefLink[CopyFile, paclet:ref/CopyFile]) to store files persistently:

file = $InstallationDirectory<> "/Documentation/English/System/ExampleData/coneflower.jpg";

CopyFile[file,LocalObject["flower"]]

Import the file stored in the local object:

Import[%]

Local objects can be used with (RefLink[Save, paclet:ref/Save]) to save definitions persistently:

a=5;
f[x_]:=x^2

Save[LocalObject["definitions"],{a,f}]

Definitions saved can be read into the Wolfram Language using (RefLink[Get, paclet:ref/Get]):

Clear[a,f];

Get[LocalObject["definitions"]]

f[a]

Local objects can be used with (RefLink[DumpSave, paclet:ref/DumpSave]) to save definitions persistently:

f[x_Real]:=x^2+1;
f[x_?NumericQ]:=N[x^2+1]

DumpSave[LocalObject["f"],f]

Clear definitions for f:

Clear[f]

Restore the definitions for f from the local object:

Get[LocalObject["f"]]

??f

Local objects can be deleted with (RefLink[DeleteObject, paclet:ref/DeleteObject]):

DeleteObject[LocalObject["definitions"]]

Local objects can be listed with (RefLink[LocalObjects, paclet:ref/LocalObjects]):

LocalObjects[]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (2)

Local objects can be created in any file:

LocalObject["/tmp/myob"]

The base for resolving relative paths can be given as the second argument:

tempbase="file:///tmp/testbase";

LocalObject["obj",tempbase]

File paths can also be specified with (RefLink[File, paclet:ref/File]):

LocalObject[File["name"]]

LocalObject["name",File["/tmp/path"]]

OpenersExampleSection4(Spacer1)Applications  (1)

Delete all existing local objects:

DeleteObject[LocalObjects[]]

OpenersExampleSection5(Spacer1)Properties & Relations  (4)

Relative paths are resolved with respect to (RefLink[$LocalBase, paclet:ref/$LocalBase]):

$LocalBase

LocalObject["obj"]

Local symbols are local objects stored in the directory (RefLink[$LocalSymbolBase, paclet:ref/$LocalSymbolBase]):

LocalObjects[$LocalSymbolBase]

(RefLink[CloudObject, paclet:ref/CloudObject]) provides for persistent storage in the cloud:

Put[10!,CloudObject[]]

Find all local objects used as caches:

LocalObjects[$CacheBaseDirectory]

OpenersExampleSection6(Spacer1)Possible Issues  (1)

Applying (RefLink[LocalObject, paclet:ref/LocalObject]) by itself does not create the referenced file:

tmpfile=FileNameJoin[{$TemporaryDirectory,"newobj"}]

obj=LocalObject[tmpfile]

FileExistsQ[tmpfile]

Only by writing content is it actually created:

Put[10!,obj]

FileExistsQ[tmpfile]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[LocalSymbol, paclet:ref/LocalSymbol])  ▪  (RefLink[$LocalBase, paclet:ref/$LocalBase])  ▪  (RefLink[LocalObjects, paclet:ref/LocalObjects])  ▪  (RefLink[Put, paclet:ref/Put])  ▪  (RefLink[Get, paclet:ref/Get])  ▪  (RefLink[Export, paclet:ref/Export])  ▪  (RefLink[CloudObject, paclet:ref/CloudObject])  ▪  (RefLink[LocalCache, paclet:ref/LocalCache])}, {Related Front End Tokens:  (StringTypeLink[Save, paclet:ref/frontendobject/Save])  ▪  (StringTypeLink[Import, paclet:ref/frontendobject/Import])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Local Objects, paclet:guide/LocalObjects])}, {▪(RefLinkPlain[Persistent Storage, paclet:guide/PersistentStorage])}, {▪(RefLinkPlain[File Operations, paclet:guide/FileOperations])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/43-storing-things.html])(WebLink[: Storing Things, https://www.wolfram.com/language/elementary-introduction/43-storing-things.html])}})}})