Just quickly some ideas that work with v14
or earlier. I note that upon calling ResourceFunction[<resfunc>]
that function seems to be stored as a local object in $LocalBase
and you can check this with LocalObjects[]
. Below is a more controlled approach.
Embedding cached resource functions within a paclet
While Lukas’ solution is very nice, I often find myself wanting to embedd certain resource functions within some paclet, e.g., some utilities I am using on a day to day basis.
For this purpose, I am currently using the following approach, which I will demonstrate for the resource function DatasetForm
:
- Set
$LocalBase = <path to PacletMainDirectory/ResourceFunctions/>
.
- Cache a resource function there using
LocalCache[ ResourceFunction[“DatasetForm”]]
.
- Register the directory name for the cached resource function as an
”Asset”
in the PacletObject
in PacletInfo.wl
. The following is an example as the directory name will, of course, differ:
“Extensions” -> {
… ,
{ "Asset",
"Root" -> "ResourceFunctions",
"Assets" -> {
{ "DatasetForm", "6694cdf9-f621-4bd4-926f8e7a5384592e/" },
…
}
}
}
- In the public context of your paclet do:
DatasetForm::usage = ResourceFunction[
PacletObject[“<pacletname>”][“AssetLocation”, “DatasetForm”], “Usage”
]
- In the private context of your paclet do:
DatasetForm = ResourceFunction[
PacletObject[“<pacletname”][“AssetLocation”, “DatasetForm”], “Function”]
]
- Repeat steps 2-5 for other resource functions if needed. Do not forget to reset
$LocalBase = $DefaultLocalBase
(haven’t checked whether a simple $LocalBase =.
will also work).
You are all set and the paclet can now provide the resource function as an embedded local object via your paclet server.
ResourceFunction["PacletizeResourceFunction"]
, which will attempt to automatically bundle resource functions into a paclet. If you specify a file path, the paclet will be saved to that path instead of being automatically installed, allowing you to copy it to another computer. $\endgroup$PacletInstall["path/to/file.paclet"]
once to install it, and then use the functions like normal functions (as shown in the documentation). Let me know if there are issues with the pacletized functions, then I can try to fixPacletizeResourceFunction
if possible $\endgroup$