Is it possible to have private folders in packages?
Show older comments
I have organized my code in packages and would like to save some small helper functions in a private directory. However, if I save my functions in +package/private/*.m, I can't get my code to "see" them.
Is this somehow possible?
I am using R2015b.
1 Comment
Adam
on 7 Dec 2017
I also found the same problem when trying to put subfolders in a package (I can't remember off-hand if it was the private folder, but I think I did try this once), but it did not work because there is no option to add subfolders of a package to the path, which is required, even for private folders, as far as I am aware, in order for the functions to be seen even in the folder containing the private folder
Answers (2)
Jan
on 7 Dec 2017
2 votes
Functions stored inside folder/+package/private/ should be visible for M-files in folder/+package/, but for no other functions. If you observe something else, consider, that there might be a different problem. How did you try to make you code seeing the files in the private folder?
6 Comments
Jette
on 8 Dec 2017
Jan
on 8 Dec 2017
What exactly does "call it from a class-file within +package" mean? From where did you try to run "funcname" and "package.funcname"? How did you include the package into your path? If both versions produce the same error message, it would be useful, if you post a copy of the complete message.
Please provide more details. Remember, that the readers in the forum do not have the faintest idea about what you are doing, except if you explain it.
Adam
on 8 Dec 2017
Package folders cannot be added to the path and subfolders also can't be. The packages get picked up by the parent being on the path
Michael Häußler
on 31 Jul 2018
Thanks to Jan! For me having:
+package/private/helperFunction.m
and calling it within the
+package/myClass.m
file via:
helperFunction();
Works perfectly
Timothy Stewart
on 1 Aug 2018
Edited: Timothy Stewart
on 1 Aug 2018
@Jan I'm trying to use private folders within /+package/@class/private to organize my directory of class methods.
Is this supported?
Furthermore, perhaps /+package/@class/protected and/or /+package/@class/public would be useful too.
V.R.
Tim
Jan
on 2 Aug 2018
@Thimothy: I'm not sure about this, but I'd simply try it.
Lockywolf
on 8 May 2018
1 vote
A private folder in a package works fine in my Matlab 2013a.
What doesn't work, however is non-private package subfolders.
That is, I have a package +pack and inside this package I have a function 'packfun.n' and two folders: 'private' and 'notprivate'.
The function 'privfun.m' from the 'private' folder is accessible. Whereas the function 'nonpriv.m' from the 'nonprivate' folder I didn't manage to run no matter how I tried.
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!