Function Repository Resource:

PacletizeResourceFunction

Source Notebook

Convert a resource function into a paclet with local documentation

Contributed by: Lukas Lang

ResourceFunction["PacletizeResourceFunction"][name]

converts the ResourceFunction with name name into a paclet and installs it locally.

ResourceFunction["PacletizeResourceFunction"][ResourceFunction[]]

pacletizes the ResourceFunction[].

ResourceFunction["PacletizeResourceFunction"][{rf1,rf2,}]

packs several functions into a single paclet.

ResourceFunction["PacletizeResourceFunction"][rf,file]

saves the paclet file to file instead of installing it.

ResourceFunction["PacletizeResourceFunction"][PacletUninstall,paclet]

uninstalls the paclet with name paclet.

Details and Options

ResourceFunction["PacletizeResourceFunction"] can be used to install a local version of resource functions as paclets, complete with local documentation.
Since ResourceFunction["PacletizeResourceFunction"] stores the code of the resource function in the created paclet, it can be used to ensure that a given version of a function will always be available.
Functions that have been pacletized can be used just like built-in functions, with the paclet automatically being loaded upon first use.
ResourceFunction["PacletizeResourceFunction"] accepts the following options:
"PacletName"Automaticthe name to use for the paclet created
"ShowProgress"Truewhether to show the progress of the paclet creation process
With the default setting "PacletName"Automatic, the paclet and context will be named after the resource function for single functions. If several functions are pacletized, a name of the form "PacletizedResourceFunction{id}" is chosen, where {id} is a number to avoid name-collisions with existing paclets.
When automatically installing the created paclet, ResourceFunction["PacletizeResourceFunction"] will attempt to uninstall existing versions of the paclet.
Calling ResourceFunction["PacletizeResourceFunction"] with the same arguments a second time effectively updates the resulting paclet to use the latest version of the pacletized functions.
ResourceFunction["PacletizeResourceFunction"] will fill the metadata fields of the generated paclet (such as version, author, …) with the appropriate information from the resource functions.
Some pacletized resource functions might not work as expected if they rely on precise details of the ResourceFunction loading and evaluation mechanism.
ResourceFunction["PacletizeResourceFunction"][PacletUninstall,paclet] effectively uses PacletUninstall to remove the paclet, but will attempt to gracefully unload the paclet documentation before doing so. This enables PacletUninstall to work without needing to restart Mathematica, assuming no other instances are open.

Examples

Basic Examples (5) 

Create a paclet from a ResourceFunction:

In[1]:=
ResourceFunction["PacletizeResourceFunction"]["BirdSay"]
Out[1]=

Use the pacletized function:

In[2]:=
BirdSay["Hello World!"]
Out[2]=

Look up basic usage cases of the function:

In[3]:=
?BirdSay
Out[3]=

Look at the documentation page for the function by by clicking on the or open the notebook directly:

In[4]:=
NotebookOpen["paclet:BirdSay/ReferencePages/Symbols/BirdSay"]
Out[4]=

Uninstall the paclet again:

In[5]:=
ResourceFunction[
 "PacletizeResourceFunction"][PacletUninstall, "BirdSay"]

Scope (3) 

Install several functions in a single paclet:

In[6]:=
ResourceFunction[
 "PacletizeResourceFunction"][{"ColorSearch", "ColorToHex"}, "PacletName" -> "ColorUtils"]
Out[6]=

Use the two functions together:

In[7]:=
AssociationMap[ColorToHex, ColorSearch["Red"]]
Out[7]=

Open the documentation page of the paclet:

In[8]:=
NotebookOpen["paclet:ColorUtils/ReferencePages/Guides/ColorUtils"]
Out[8]=

Uninstall the paclet:

In[9]:=
ResourceFunction[
 "PacletizeResourceFunction"][PacletUninstall, "ColorUtils"]

Save the paclet to a file instead of installing it directly:

In[10]:=
paclet = ResourceFunction[
  "PacletizeResourceFunction"][{"ColorSearch", "ColorToHex"}, "ColorUtils.paclet", "PacletName" -> "ColorUtils"]
Out[10]=

Install the paclet:

In[11]:=
PacletInstall@paclet
Out[11]=

Uninstall the paclet:

In[12]:=
ResourceFunction[
 "PacletizeResourceFunction"][PacletUninstall, "ColorUtils"]

See the installed paclets in the documentation center by going to guide/InstalledAddons, linked at the bottom of the main page:

Options (5) 

PacletName (3) 

With the default setting "PacletName"Automatic, the paclet and context name will be based on the name of the resource function:

In[13]:=
ResourceFunction["PacletizeResourceFunction"]["ColorSearch"]
Out[13]=
In[14]:=
Context@ColorSearch
Out[14]=

When pacletizing several functions, the default name is "PacletizedResourceFunctions":

In[15]:=
ResourceFunction[
 "PacletizeResourceFunction"][{"ColorSearch", "ColorToHex"}]
Out[15]=

Specify an alternative name:

In[16]:=
ResourceFunction["PacletizeResourceFunction"]["ColorSearch", "PacletName" -> "MyPaclet"]
Out[16]=
In[17]:=
Context@ColorSearch
Out[17]=

ShowProgress (2) 

With the default setting "ShowProgress"True, the current stage of the process is displayed:

In[18]:=
ResourceFunction["PacletizeResourceFunction"]["ColorSearch"]
Out[18]=

Disable the progress display:

In[19]:=
ResourceFunction["PacletizeResourceFunction"]["ColorSearch", "ShowProgress" -> False]
Out[19]=

Possible Issues (3) 

Locally created resource functions cannot be pacletized since the definition notebook cannot be accessed:

In[20]:=
rf = DefineResourceFunction[# &, "LocalRF"]
Out[20]=
In[21]:=
ResourceFunction["PacletizeResourceFunction"][rf]
Out[21]=

If multiple instances of Mathematica are running, removal of the paclet might be delayed until the next restart:

In[22]:=
ResourceFunction[
 "PacletizeResourceFunction"][PacletUninstall, "AbundantNumber"]

Similarly, attempting to update an existing paclet might fail in such cases:

Out[23]=

Publisher

Lukas Lang

Version History

  • 1.0.0 – 11 December 2020

Related Resources

License Information