Function Repository Resource:

DataResourceFromDirectory

Source Notebook

Create a data resource definition notebook from data in a directory

Contributed by: Bob Sandheinrich

ResourceFunction["DataResourceFromDirectory"][dir]

opens a data resource definition notebook prefilled using data from the directory dir.

Details and Options

The resulting notebook will have the following fields filled:
"Name"derived from the directory
"Description"derived from the directory
"Data Definitions"element created from each data file
All filled and unfilled fields in the created notebook are fully editable.
The name is created from the path of the directory relative to Directory[] by replacing camel casing and path seperators with spaces.
The description is text including the directory and all element names.

Examples

Basic Examples (2) 

Build a directory with data files in it:

In[1]:=
dir = ResourceFunction["EnsureDirectory"]["NumbersBobKnows"];
Export[FileNameJoin[{dir, "RandomNumbers.mx"}], RandomReal[1, 10^5]];
Put[Prime /@ Range[100], FileNameJoin[{dir, "PrimeNumbers"}]];

Create a data resource definition notebook prefilled by the directory:

In[2]:=
ResourceFunction["DataResourceFromDirectory"][dir]
Out[2]=

Scope (1) 

Create a (possibly large) data resource definition notebook from ExampleData content:

In[3]:=
ResourceFunction["DataResourceFromDirectory"][
 FileNameDrop[FindFile["ExampleData/spikey2.png"]]]
Out[3]=

Possible Issues (3) 

When multiple files have the same FileBaseName, the notebook will assign the same name to all the content elements:

In[4]:=
dir = ResourceFunction["EnsureDirectory"]["DifferentFileExtensions"];
Export[FileNameJoin[{dir, "RandomNumbers.mx"}], RandomReal[1, 10^5]];
Export[FileNameJoin[{dir, "RandomNumbers.json"}], RandomReal[1, 10^5]];
Export[FileNameJoin[{dir, "RandomNumbers.wxf"}], RandomReal[1, 10^5]];

Create a data resource definition notebook:

In[5]:=
ResourceFunction["DataResourceFromDirectory"][dir]
Out[5]=

Manually modify the element names to make a valid resource:

Neat Examples (3) 

Build a directory with data files in it:

In[6]:=
dir = ResourceFunction["EnsureDirectory"]["FunImages"];
Export[FileNameJoin[{dir, "WiggleBird.mx"}], ResourceFunction["Wiggled"][
   ResourceFunction["BirdSay"]["I am data?"]]];
Export[FileNameJoin[{dir, "WiggleWolf.mx"}], ResourceFunction["Wiggled"][
   ResourceFunction["WolfieSay"]["Most Certainly."]]];

Create a data resource definition notebook:

In[7]:=
defnotebook = ResourceFunction["DataResourceFromDirectory"][dir]
Out[7]=

Create a ResourceObject and retrieve the data using ResourceData:

In[8]:=
ResourceData[ResourceObject@defnotebook, {"WiggleBird", "WiggleWolf"}]
Out[8]=

Version History

  • 1.0.0 – 18 June 2020

Related Resources

License Information