Message Boards Message Boards


Function to access paclet resources?

Posted 4 days ago
4 Replies
4 Total Likes

Hello all,

So I have a sizeable paclet built. In my PacletInfo.m, I have created a Resource that points to a file in the Resources directory of my paclet. The resource extension looks like this:

Extensions -> 

I've seen various places on-line that I should be able to use a function called PacletResource["PacletName","FilePaths"] to access and open that file. However, that function seems to be missing. Mathematica doesn't recognize it and I can't find anything like it in the help system.

I have Mathematica 12.1 and the Paclet is installed in my user specific Paclets\Repository. I can use the Paclet and it works fine. I've tried loading "PacletManager'" and that function doesn't seem to be in there.

What am I missing?


4 Replies

You can use

PacletManager`PacleResource["PacletName", "FilePaths"]

or the newer form

pObj["AssetLocation", "FilePaths"]

where pObj is the appropriate PacletObject representing the paclet.

@Ilian Gachevski Thanks for that.

However, although the first form gives me no errors (that's better than I've been able to do on my own!), but it also gives no output.

In[6]:= PacletManager`PacletResource["PackletName", "FilePaths"]
(* No output here*)

In[7]:= FileExistsQ[PacletManager`PacletResource["PacletName", "FilePaths"]]

Out[7]= False

The second option doesn't do any better. I can correctly create the PacletObject, and get its information, but getting "AssetLocation" just repeats the command, like it is an unknown command.

In[7]:= PObj["AssetLocation", "FilePaths"]

Out[7]= PObj["AssetLocation", "FilePaths"]

Is this documented somewhere, or have I stepped into the outer limits? I can't find any documentation on PacletManager or it's functions.

I did manage to get this to work:

In[94]:= hString = Quiet@Import["PacletName\\Resources\\Filepaths.txt"]

Out[94]= "Contents of Filespatths.txt"

As long as

hString != $Failed

I think this will work. Would be nice to know why that paclet resource isn't working, though.


To clarify, by pObj, I meant the result of pObj = PacletObject["PacletName"] or, equivalently pObj = First[PacletFind["PacletName"]].

Getting Null for the PacletResource / AssetLocation means the asset does not exist in the paclet.

A possible reason for that is that the default asset Root is ., but in your case the file is placed in a subdirectory called Resources.

@Ilian Gachevski

Got it. I was trying everything you said and it still wasn't working. Mathematica simply couldn't find my resource.

Turns out that Workbench (the latest version available to us mere mortals) is not keeping up with the current Mathematica paclet technology and wasn't properly installing the paclet (or registering the resources?).

I created a paclet archive and then did an "official" PacletInstall. Now both methods you gave me work perfectly.

Thank you!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract