I have a structure of folders.
- Main Directory( has init.m, and name.m files)
- Subfolders under Main directory
- library ( has the packages, pacakge1.m, package2.m)
- Data (some xcel sheets and other data files)
The init.m has the following commands
Get[FileNameJoin[{NotebookDirectory[],"library", "Package1.m"}]]; Get[FileNameJoin[{NotebookDirectory[],"library", "Package2.m"}]];
Package1 has function1
and function2
definitions. Package2 has function3
and function4
definitions.
The Names.m file has the following the commands
Get[FileNameJoin[{NotebookDirectory[],"init.m"}]];
DeclarePackage["Package1`",{"function1", "function2"}];
DeclarePackage["Package2`",{"function3", "function4"}]
After evaluating the name.m file, I was expecting that calling function1
should execute the Package1`function1
. However it is not happening. This is what I understand of Mathematica so far. I don't want to touch the init.m file in the Autoload folder of the userbase directory as I don't want to modify the contents. I just want my init.m in the local folder to run.
Workarounds anyone?
BeginPackage
you can specify additional contexts/packages that are needed. Is that what you want? $\endgroup$FindFile
until you get the relationship between context name and folder structure. Both\\package\\init.m
, or\\package.m
are found with"package`"
, as long as the base directory is in the path, no need to specify the full file name. Subcontexts are interpreted as subfolders. $\endgroup$$InputFileName
instead ofNotebookDirectory[]
to refer to the filename of the currently evaluating .m file. $\endgroup$