Function Repository Resource:

PersistResourceFunction

Source Notebook

Install a resource function persistently so that it can be used like a built-in function

Contributed by: Jesse Friedman

ResourceFunction["PersistResourceFunction"][rf]

installs the resource function f persistently.

ResourceFunction["PersistResourceFunction"][rf,"Uninstall"]

uninstalls the resource function f.

ResourceFunction["PersistResourceFunction"]["List"]

lists the currently installed resource functions.

Details and Options

Resource function rf can be either a ResourceFunction object, a function name (resolved as described in ResourceFunction), or a list of ResourceFunction objects or function names.
ResourceFunction["PersistResourceFunction"]["name"] is equivalent to ResourceFunction["PersistResourceFunction"][ResourceFunction["name"]].
ResourceFunction["PersistResourceFunction"][rf] is equivalent to ResourceFunction["PersistResourceFunction"][rf,"Install"].
ResourceFunction["PersistResourceFunction"]["List"] returns a list of installed ResourceFunction objects.
ResourceFunction["PersistResourceFunction"]["UninstallAll"] uninstalls all installed resource functions.
ResourceFunction["PersistResourceFunction"]["UninstallAll"] is equivalent to ResourceFunction["PersistResourceFunction"][ResourceFunction["PersistResourceFunction"]["List"],"Uninstall"].
ResourceFunction["PersistResourceFunction"] persists resource functions by storing InitializationValue objects corresponding to their names.
Care should be taken using installed resource functions in code to be shared with or distributed to others, as recipients are unlikely to have the same set of dependent resource functions installed in their own respective environments.
ResourceFunction["PersistResourceFunction"] accepts the option "PersistenceLocation" with default value $PersistenceBase to specify the scope of the persistence.

Examples

Basic Examples (4) 

Store ResourceFunction["RainbowText"] persistently:

In[1]:=
ResourceFunction["PersistResourceFunction"]["RainbowText"]
Out[1]=

Use it like a built-in function:

In[2]:=
RainbowText["hello world"]
Out[2]=

The definition persists across kernel sessions:

In[3]:=
Quit
In[4]:=
RainbowText["hello world"]
Out[4]=

Uninstall the function:

In[5]:=
ResourceFunction[
 "PersistResourceFunction"]["RainbowText", "Uninstall"]
Out[5]=

Scope (2) 

Multiple resource functions can be installed or uninstalled by supplying a list of ResourceFunction objects or function names as the first argument to PersistResourceFunction:

In[6]:=
ResourceFunction[
 "PersistResourceFunction"][{"RainbowText", ResourceFunction[
ResourceObject[<|{"Name" -> "BirdSay", "ShortName" -> "BirdSay", "UUID" -> "a24858c8-45c5-4020-a8c2-c23bd5d26f04", "ResourceType" -> "Function", "Version" -> "3.0.0", "Description" -> "Have a bird say an expression", "RepositoryLocation" -> URL[
       "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"],
       "SymbolName" -> "FunctionRepository`$55711938e45341c08ca516066b27f30c`BirdSay", "FunctionLocation" -> CloudObject[
       "https://www.wolframcloud.com/obj/9d5d3776-baed-4a5d-bf38-e857d53825e1"]}|>, ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"]]}]
Out[6]=
In[7]:=
BirdSay[RainbowText["rainbow bird"]]
Out[7]=

The currently installed resource functions can be listed with PersistResourceFunction["List"]:

In[8]:=
ResourceFunction["PersistResourceFunction"]["List"]
Out[8]=
In[9]:=
ResourceFunction[
 "PersistResourceFunction"][{"RainbowText", ResourceFunction[
ResourceObject[<|{"Name" -> "BirdSay", "ShortName" -> "BirdSay", "UUID" -> "a24858c8-45c5-4020-a8c2-c23bd5d26f04", "ResourceType" -> "Function", "Version" -> "3.0.0", "Description" -> "Have a bird say an expression", "RepositoryLocation" -> URL[
       "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"],
       "SymbolName" -> "FunctionRepository`$55711938e45341c08ca516066b27f30c`BirdSay", "FunctionLocation" -> CloudObject[
       "https://www.wolframcloud.com/obj/9d5d3776-baed-4a5d-bf38-e857d53825e1"]}|>, ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"]]}, "Uninstall"]
Out[9]=

Options (1) 

The "PersistenceLocation" option allows for storing resource functions in a location other than $PersistenceBase:

In[10]:=
ResourceFunction["PersistResourceFunction"]["RainbowText", "PersistenceLocation" -> "Cloud"]
Out[10]=

Properties and Relations (1) 

The underlying PersistentObject storing a resource function can be found with InitializationObjects:

In[11]:=
ResourceFunction["PersistResourceFunction"]["RainbowText"]
Out[11]=
In[12]:=
InitializationObjects["Global`RainbowText"]
Out[12]=

Possible Issues (1) 

Installing a ResourceFunction will overwrite any values currently assigned to the function name:

In[13]:=
RainbowText[_] := "not a rainbow :(";
RainbowText["hello world"]
Out[13]=
In[14]:=
ResourceFunction["PersistResourceFunction"]["RainbowText"]
Out[14]=
In[15]:=
RainbowText["hello world"]
Out[15]=

Neat Examples (1) 

Install PersistResourceFunction as a persistent resource function:

In[16]:=
ResourceFunction["PersistResourceFunction"]["PersistResourceFunction"]
Out[16]=
In[17]:=
PersistResourceFunction["RainbowText"]
Out[17]=
In[18]:=
RainbowText["hello world"]
Out[18]=

Publisher

Jesse Friedman

Version History

  • 2.0.0 – 04 November 2019
  • 1.0.0 – 11 October 2019

Related Resources

License Information