help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Distribute "data files" with a package


From: Philip Nienhuis
Subject: Re: Distribute "data files" with a package
Date: Mon, 31 Mar 2014 08:31:59 -0700 (PDT)

Daniel Kraft-2 wrote
> Hi!
> 
> I'm currently working on an Octave package, and want to distribute
> certain "data files" with it.  (In my particular case, it is an image
> file to be used by one of the package's "demo" functions.)
> 
> When I include the file in the package's "inst/" directory, it gets
> installed correctly to the package installation folder.  However, now
> I'm wondering how I can access it from within a demo function.  I tried
> without an explicit directory specification, but that fails (since it
> looks in the current working directory as opposed to the .m file's
> directory).
> 
> This must be something others have already stumbled upon -- how can one
> access such "data files" distributed with a package?  Is there a
> function that can be called from within an .m file and that returns the
> directory that contains the .m file?
> 
> The best I could find so far is "pkg list", and then sifting through the
> list of packages looking for my package's name and then using the
> installation directory.  But that seems to be too complicated for such a
> "seemingly easy" task.  Is there no better way to query for the
> installation directory of a particular package, for instance?  Or even
> of "this package" from within a package's functions?

I think it is better to put data files, templates, etc. in a separate
subdir, and not mix them with function .m files.
You can add any subdir to a package (I'd suggest in the same level as e.g.,
inst), and after installation that subdir + its contents gets installed in
share/octave/..../<package>/<subdir>

How to find out the path to that subdir?
Easy, if the package is loaded, you can ask where a function from your
package is, using 'which':

loc = which ('<function>);

and the answer is the full path to that function in your package. Just
replace the last entry (the function file name) by <subdir>/<datafilename>
and you're all set.

Philip




--
View this message in context: 
http://octave.1599824.n4.nabble.com/Distribute-data-files-with-a-package-tp4663406p4663411.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]