This is partly in response to something Ignacio asked for a
while ago, namely the ability to produce within a function
package, plots that are usually only available via GUI means.
What I have in CVS is just at the proof of concept stage, but
here's the concept:
1) Parallel to certain commands, we offer a function that
returns the information needed to produce a plot, in the form
of a bundle. In this bundle we record the name of the built-in
function that produced it.
2) We provide a built-in function (or maybe eventually a
command) that produces a plot from such a bundle: it checks
for the creator of the bundle and hands off to the appropriate
specialized plotting function.
Right now this is (partially) implemented for the irf()
function. Until now this function has returned a matrix, but
in CVS it returns a bundle which contains the matrix along
with the additional info needed for the plot (e.g. the names
of the target and shock variables and the "alpha" for the
confidence interval, if any).
Isn't this backward incompatible? Actually, no. You can still
assign from the irf() function to a matrix. That's because
I've added a special bundle key: if you add a matrix to a
bundle under the name "payload_matrix", then the following
sort of thing (a "cast" from bundle to matrix) will work:
<hansl>
bundle b
b["payload_matrix"] = I(3)
b["otherthing"] = "hello"
matrix m = b
</hansl>
Here's an example of the whole deal:
<hansl>
open data9-7
var 4 UNEMP PRIME
# assign from irf() to bundle
bundle b = irf(1, 2, 0.2)
bplot(b, "display")
# we can still assign from irf() to matrix
matrix m = irf(1, 2, 0.2)
m
</hansl>
The second (string) argument to bplot() is currently just a
dummy and is ignored. The idea is that you should be able to
use it to specify the format/destination of the plot but
that's not wired up yet.
The reason I say "bplot" (or whatever we decide to name it)
should perhaps be a command rather than a function is that
then one could direct it to a GUI object if desired, as in
graph1 <- bplot bundle
(Or I guess we could use a --bundle=foo option with the
existing "gnuplot" command, though maybe it's already
overburdened with options.)
In relation to Ignacio's request, we could add corrgm() and
pergm() functions that return bundles, and add support for
plotting from such bundles.
Allin
_______________________________________________
Gretl-devel mailing list
Gretl-devel@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-devel