15
$\begingroup$

I would like to be able to use ResourceFunction's as top-level symbols:

enter image description here

The reason being that some of them are so useful it would be really great not to have to type out ResourceFunction["FunctionName..."] each time.

Is there some way to load them all into System context once? For a bonus: add documentation locally.

The first issue is that I don't know how to find them all:

l

$\endgroup$

5 Answers 5

10
$\begingroup$

There is a helpful function named PersistResourceFunction that permanently stores a function.

Here is what I did:

<< ResourceSystemClient`;
ResourceFunction["PersistResourceFunction"]["PersistResourceFunction"];
names = ResourceSystemClient`Private`publicResourceInformation["Names"]["Function"];
PersistResourceFunction /@ names;

Update. Here is my code to prevent scope conflicts between functions in the repository that later became reserved:

<<ResourceSystemClient`;
ResourceFunction["PersistResourceFunction"]["PersistResourceFunction"];
reservednames=Names[];
resourcefunctionnames=ResourceSystemClient`Private`publicResourceInformation["Names"]["Function"];
distinctresourcefunctionnames=Complement[names,Intersection[names,reservednames]];
PersistResourceFunction /@ distinctresourcefunctionsnames;
$\endgroup$
8
+25
$\begingroup$

I dug and found where the names for the autocomplete are cached:

<<ResourceSystemClient`;
names = ResourceSystemClient`Private`publicResourceInformation["Names"]["Function"];

If that doesn't work do this:

names =
  ResourceSearch[{"ResourceType" -> "Function", "Name" -> "*"}, MaxItems -> 1000][[All, "Name"]] // Normal;

Now you can do something like:

ToExpression[
 "System`" <> # & /@ names, 
 StandardForm,
 Function[
  Null,
  With[{sn = SymbolName[Unevaluated[#]]},
   SetDelayed[#, # = ResourceFunction[sn]]
   ],
  HoldAllComplete
  ]
 ]

And all the resource functions are dynamically loaded into the "System`" context

$\endgroup$
8
  • $\begingroup$ Looks like names has only 62 of the 447... $\endgroup$
    – M.R.
    Commented Apr 28, 2019 at 22:28
  • $\begingroup$ And wouldn't With[{u = ToExpression[#]}, u := ResourceFunction[#]] & /@ names be simpler... $\endgroup$
    – M.R.
    Commented Apr 28, 2019 at 22:49
  • $\begingroup$ @M.R. with all that I'm making sure a) the symbol doesn't already have an OwnValue and b) that ResourceFunction isn't evaluated multiple times. b) only covers a small bit of overhead, but it's a harmless little efficiency. As for names not having everything, you might need to reload the paclet? I have 485 entries in it. $\endgroup$
    – b3m2a1
    Commented Apr 29, 2019 at 16:26
  • $\begingroup$ That makes sense. But after running PacletUpdate["ResourceSystemClient"] I have Paclet["ResourceSystemClient", "1.12.0", <> ], and it's only showing 69 names... $\endgroup$
    – M.R.
    Commented Apr 29, 2019 at 17:45
  • 1
    $\begingroup$ Right, ok so we get this behavior for free it seems. $\endgroup$
    – M.R.
    Commented May 1, 2019 at 18:31
3
$\begingroup$

Just do

DynamicMap = ResourceFunction["DynamicMap"]

and now you can use

DynamicMap[# + 1 &, Range[100]]

as expected.

$\endgroup$
3
  • $\begingroup$ Right, but see the updates... how to do for all programmatically? That's the tricky part. $\endgroup$
    – M.R.
    Commented Apr 23, 2019 at 17:22
  • $\begingroup$ that is the first thing I thought of, but there might be a bug in ResourceSearch... $\endgroup$
    – M.R.
    Commented Apr 23, 2019 at 17:44
  • $\begingroup$ Ah, my apologies, I didn't see your edit before answering. $\endgroup$
    – Carl Lange
    Commented Apr 23, 2019 at 17:57
3
$\begingroup$

I'll post how I did it by scraping, but it's not a great solution:

html = Import[
   "https://resources.wolframcloud.com/FunctionRepository/all/", 
   "String"];
names = StringCases[html, 
   "<h3>" ~~ Whitespace ~~ "<a " ~~ Shortest[__] ~~ ">" ~~ 
     x : Shortest[__] ~~ "</a>" :> x];
With[{u = ToExpression[#]}, u := ResourceFunction[#]] & /@ names

Then we have all of them

enter image description here

In the system context

enter image description here

Then they load on demand, but trying to load all at once takes 16 minutes:

enter image description here

I haven't found a way to cache them and or to load the docs locally yet...

$\endgroup$
3
$\begingroup$

We can install, group, use, and uninstall resource functions with

PacletizeResourceFunction

list = {"AppendColumn", "ColumnMap", "PrependColumn"};

ResourceFunction["PacletizeResourceFunction"][Evaluate @ list, 
 "PacletName" -> "MatrixFunctions"]

enter image description here

ColumnMap[0 &, {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}}, {3}]

{{1, 1, 0}, {2, 2, 0}, {3, 3, 0}}

We can use Information and get the function documentation by clicking the i-symbol in the upper right corner.

?ColumnMap

enter image description here

$\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.