22
$\begingroup$

So I want to use "ResourceFunction" commands, but that requires internet, as it needs to retrieve it from the wolfram cloud. However, I want to access a number of them (such as, ResourceFunction["TangentLine"], ResourceFunction["StationaryPoints"] etc.) on a different computer at work (which doesn't have access to internet). Is there a way I can retrieve the commands from the Wolfram cloud on my laptop at home, and copy that notebook onto a USB and plug that USB into the work computer and get the commands to work there, without internet?

Please assist. Thanks :)

$\endgroup$
16
  • 3
    $\begingroup$ Go to this site: resources.wolframcloud.com/FunctionRepository, find whichever resources you want, and then look at the top right of the page - to code is there for downloading. For example, look at the top right of resources.wolframcloud.com/FunctionRepository/resources/…, see "Source Notebook" - that is the actual code. Clear? $\endgroup$
    – Moo
    Commented May 27, 2021 at 20:27
  • 4
    $\begingroup$ You might be interested in 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$
    – Lukas Lang
    Commented May 27, 2021 at 22:20
  • 2
    $\begingroup$ I have seen some ResourceFuntions that don't have a ResourceNotebook link at the top right corner. When that happened I let Wolfram Research know via the Feedback link at the bottom and they fix it the next day. $\endgroup$
    – Ted Ersek
    Commented May 28, 2021 at 0:20
  • 2
    $\begingroup$ @blacke23 You should be able to just call 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 fix PacletizeResourceFunction if possible $\endgroup$
    – Lukas Lang
    Commented May 28, 2021 at 9:45
  • 2
    $\begingroup$ @blacke23 I have put all my comments into an answer, including info on how to find the documentation - feel free to ask for clarifications! $\endgroup$
    – Lukas Lang
    Commented May 29, 2021 at 17:40

2 Answers 2

25
$\begingroup$

Putting my comment into an answer, since it seems to have solved the question

You can use ResourceFunction["PacletizeResourceFunction"] to package a collection of resource functions into a paclet, which can then be installed on another computer.

The process works like this: Let's say you want the resource functions LensManipulate and AncientNumberRepresentation on a computer without internet.

  1. Create the paclet on the computer with internet:

    ResourceFunction["PacletizeResourceFunction"][
      {
        "LensManipulate",
        "AncientNumberRepresentation"
      },
      "useful.paclet",
      "PacletName"->"MyPaclet"
    ]
    (* "C:\\Users\\lukas\\Documents\\useful.paclet" *)
    
  2. Copy the file to your other computer

  3. Install the paclet:

    PacletInstall["C:\\Users\\lukas\\Documents\\useful.paclet"]
    

    enter image description here

  4. Use the functions as you would otherwise (note that the function is not wrapped in ResourceFunction[...]):

    AncientNumberRepresentation[13, "Babylonian"]
    

    enter image description here

  5. To look at the documentation, use the same methods as for normal functions:

    • With the cursor in the function name, press F1 (or whatever the shortcut is on your system)
    • Use the info popup button
    • Use the search in the documentation center
    • Navigate to it via the paclet guide page (see next point)

    enter image description here

  6. You can manage the paclet & go to the main overview page via the documentation center: Go to the home page, and scroll to the very bottom. Click on the "Add-ons and packages" link, and you should see an overview of the installed paclets: enter image description here The overview guide page looks like this (reached by clicking the "Documentation" button or the paclet name): enter image description here You can also reach the paclet overview page by searching the documentation for the name of the paclet: enter image description here

  7. In the latest version of PacletizeResourceFunction (this is not yet accepted to the function repository, for now it can be accessed via ResourceFunction[CloudObject["https://www.wolframcloud.com/obj/langl/DeployedResources/Function/PacletizeResourceFunction"]]), it is also possible to update an existing paclet with new/updated functions without having to reprocess all the existing ones. The workflow would go something like this:

    PacletizeResourceFunction=
     ResourceFunction[CloudObject["https://www.wolframcloud.com/obj/langl/DeployedResources/Function/PacletizeResourceFunction"]];
    
    (* create a first version of the paclet *)
    PacletizeResourceFunction[{"AreaBetweenCurves"}, "CodeFinal.paclet", "PacletName" -> "Codes"]
    (* "D:\\lukas\\Documents\\CodeFinal.paclet" *)
    
    (* install the paclet file, possibly on another computer *)
    PacletInstall@"CodeFinal.paclet"
    (* PacletObject["Codes"] *)
    
    (* load the paclet *)
    << Codes`
    
    (* it contains the following functions: *)
    Names["Codes`*"]
    (* {"AreaBetweenCurves"} *)
    

    To update the paclet, run the command again, but with a different list of functions. Make sure that the old paclet file is at the target location of the command. This way, PacletizeResourceFunction will see the paclet file and update it, rather than generating a new one from scatch

    PacletizeResourceFunction[{"ColorSearch"}, "CodeFinal.paclet",  "PacletName" -> "Codes"]
    (* "D:\\lukas\\Documents\\CodeFinal.paclet" *)
    
    (* again on the other computer, uninstall the old version (this might need a restart of Mathematica to complete fully) *)
    PacletUninstall@"Codes"
    
    (* install the new version *)
    PacletInstall@"CodeFinal.paclet"
    (* PacletObject["Codes"] *)
    
    (* load it *)
    << Codes`
    
    (* now, both functions are available from the paclet: *)
    Names["Codes`*"]
    (* {"AreaBetweenCurves", "ColorSearch"} *)
    
$\endgroup$
22
  • 1
    $\begingroup$ This is really nice - local documentation is a great bonus on top of all of this. It makes me wonder if you could just download all of the resource functions to a paclet and sync them every once in a while... $\endgroup$
    – Carl Lange
    Commented May 29, 2021 at 18:58
  • $\begingroup$ @CarlLange you'd probably need to be very patient if you tried that :) (the notebook-manipulation tasks used for the documentation-extraction are unfortunately super slow) $\endgroup$
    – Lukas Lang
    Commented May 29, 2021 at 19:15
  • $\begingroup$ @LukasLang Hey, can you add more functions to a paclet once you have made it? Or do you have to make a new one each time you wish to add more functions onto it? $\endgroup$
    – blacke23
    Commented May 29, 2021 at 23:14
  • $\begingroup$ @blacke23 Sorry for the delayed reply - I thought I could "quickly" implement something, but as it goes, it took a lot longer than expected... Anyway: In the current version, you'll have to regenerate the full paclet each time, yes. However, I have just submitted an updated version that includes the ability to add functions to an existing paclet without having to reprocess the rest. Until it is submitted, you can access it as ResourceFunction[ CloudObject["https://www.wolframcloud.com/obj/langl/DeployedResources/Function/PacletizeResourceFunction"]]. If you find any issues, let me know! $\endgroup$
    – Lukas Lang
    Commented Jun 4, 2021 at 9:09
  • $\begingroup$ @LukasLang Im a bit confused, so I copied the command into my notebook and it came with the with square brackets and a circle in the middle, with "PacletResourceFunction" eg. something like this [*]PacletResourceFunction I'm lost as to what to do from here onwards. thanks $\endgroup$
    – blacke23
    Commented Jun 5, 2021 at 3:36
1
$\begingroup$

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:

  1. Set $LocalBase = <path to PacletMainDirectory/ResourceFunctions/>.
  2. Cache a resource function there using LocalCache[ ResourceFunction[“DatasetForm”]].
  3. 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/" },
            …
       }
   }
}
  1. In the public context of your paclet do:
DatasetForm::usage = ResourceFunction[
    PacletObject[“<pacletname>”][“AssetLocation”, “DatasetForm”], “Usage”
]
  1. In the private context of your paclet do:
DatasetForm = ResourceFunction[
    PacletObject[“<pacletname”][“AssetLocation”, “DatasetForm”], “Function”]
]
  1. 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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.