[rkward-cvs] SF.net SVN: rkward:[3805] trunk/rkward/doc
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Tue Sep 20 15:19:15 UTC 2011
Revision: 3805
http://rkward.svn.sourceforge.net/rkward/?rev=3805&view=rev
Author: tfry
Date: 2011-09-20 15:19:14 +0000 (Tue, 20 Sep 2011)
Log Message:
-----------
Actually install the writing plugins handbook, locally.
For this to work, it had to be moved to a directory of its own.
Also, a bunch of DTD violations turned up, while creating the handbook. I fixed those, but did not do any actual changes in the docbook.
Modified Paths:
--------------
trunk/rkward/doc/CMakeLists.txt
trunk/rkward/doc/rkward/CMakeLists.txt
Added Paths:
-----------
trunk/rkward/doc/rkwardplugins/
trunk/rkward/doc/rkwardplugins/CMakeLists.txt
trunk/rkward/doc/rkwardplugins/index.docbook
trunk/rkward/doc/rkwardplugins/menu_hierarchy_example.png
trunk/rkward/doc/rkwardplugins/t_test_plugin_example.png
Removed Paths:
-------------
trunk/rkward/doc/rkward/menu_hierarchy_example.png
trunk/rkward/doc/rkward/t_test_plugin_example.png
trunk/rkward/doc/rkward/writing_plugins_introduction.docbook
Modified: trunk/rkward/doc/CMakeLists.txt
===================================================================
--- trunk/rkward/doc/CMakeLists.txt 2011-09-20 11:00:34 UTC (rev 3804)
+++ trunk/rkward/doc/CMakeLists.txt 2011-09-20 15:19:14 UTC (rev 3805)
@@ -1,2 +1,2 @@
ADD_SUBDIRECTORY (rkward)
-
+ADD_SUBDIRECTORY (rkwardplugins)
Modified: trunk/rkward/doc/rkward/CMakeLists.txt
===================================================================
--- trunk/rkward/doc/rkward/CMakeLists.txt 2011-09-20 11:00:34 UTC (rev 3804)
+++ trunk/rkward/doc/rkward/CMakeLists.txt 2011-09-20 15:19:14 UTC (rev 3805)
@@ -1,6 +1,2 @@
KDE4_CREATE_HANDBOOK (index.docbook INSTALL_DESTINATION ${HTML_INSTALL_DIR}/en)
KDE4_CREATE_MANPAGE (man-rkward.1.docbook 1 INSTALL_DESTINATION ${MAN_INSTALL_DIR})
-
-ADD_CUSTOM_TARGET (webdocs
- COMMAND meinproc4 --stylesheet ${DATA_INSTALL_DIR}/ksgmltools2/customization/kde-web.xsl ${CMAKE_CURRENT_SOURCE_DIR}/writing_plugins_introduction.docbook
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
Deleted: trunk/rkward/doc/rkward/menu_hierarchy_example.png
===================================================================
(Binary files differ)
Deleted: trunk/rkward/doc/rkward/t_test_plugin_example.png
===================================================================
(Binary files differ)
Deleted: trunk/rkward/doc/rkward/writing_plugins_introduction.docbook
===================================================================
--- trunk/rkward/doc/rkward/writing_plugins_introduction.docbook 2011-09-20 11:00:34 UTC (rev 3804)
+++ trunk/rkward/doc/rkward/writing_plugins_introduction.docbook 2011-09-20 15:19:14 UTC (rev 3805)
@@ -1,2731 +0,0 @@
-<?xml version="1.0" ?>
-<!DOCTYPE book PUBLIC "-//KDE//DTD DocBook XML V4.2-Based Variant V1.1//EN" "dtd/kdex.dtd" [
- <!ENTITY rkward '<application>RKWard</application>'>
- <!ENTITY kapp "&rkward;"><!-- replace rkward here -->
- <!ENTITY % addindex "IGNORE">
- <!ENTITY % English "INCLUDE"><!-- change language only here -->
-
-
- <!-- Do not define any other entities; instead, use the entities
- from kde-genent.entities and $LANG/user.entities. -->
-]>
-
-<book lang="&language;">
-
-<!-- This header contains all of the meta-information for the document such
-as Authors, publish date, the abstract, and Keywords -->
-
-<bookinfo>
-<title>Introduction to Writing Plugins for RKWard</title>
-
-<authorgroup>
-<author>
-<firstname>Thomas</firstname>
-<surname>Friedrichsmeier</surname>
-<affiliation>
-<address><email>rkward-devel AT lists DOT sourceforge DOT net</email></address>
-</affiliation>
-</author>
-
-<author>
-<firstname>Meik</firstname>
-<surname>Michalke</surname>
-<affiliation>
-<address><email>rkward-devel AT lists DOT sourceforge DOT net</email></address>
-</affiliation>
-</author>
-<!-- Additional authors go here -->
-</authorgroup>
-
-<!-- TRANS:ROLES_OF_TRANSLATORS -->
-
-<copyright>
-<year>2006</year>
-<year>2007</year>
-<year>2008</year>
-<year>2010</year>
-<year>2011</year>
-<holder>Thomas Friedrichsmeier</holder>
-</copyright>
-<!-- Translators: put here the copyright notice of the translation -->
-<!-- Put here the FDL notice. Read the explanation in fdl-notice.docbook
- and in the FDL itself on how to use it. -->
-<legalnotice>&FDLNotice;</legalnotice>
-
-<date>2011-06-06</date>
-<releaseinfo>0.5.7.00</releaseinfo>
-
-<abstract>
-<para>
-This is a guide to writing plugins for &rkward;.
-</para>
-</abstract>
-
-<keywordset>
-<keyword>KDE</keyword>
-<keyword>R</keyword>
-<keyword>rkward</keyword>
-<keyword>plugins</keyword>
-</keywordset>
-
-</bookinfo>
-
-<chapter id="introduction">
-<title>Introduction</title>
-
-<para>
-Documentation as of &kapp; release 0.5.7.
-</para>
-<para>
-This document describes how to write your own plugins. Note, that at the time of this writing, some of the concepts are not yet set it stone. Therefore, this document should be regarded as an introduction to the current approach, and as a basis for discussion. All sorts of comments are welcome.
-</para>
-<para>
-For questions and comments, please write to the &kapp; development mailing list.
-</para>
-<para>
-<emphasis>You do not need to read this in order to use &kapp;.</emphasis> This document is about extending &kapp;. It is targeted at advanced users, or people willing to help improve &kapp;.
-</para>
-<para>
-Writing a standard plugin is basically a four-step process:
-<itemizedlist>
-<listitem><link linkend="pluginmap">Placing a new Action in the menu-hierarchy</link></listitem>
-<listitem><link linkend="mainxml">Describing the looks and behavior of the plugin-GUI</link></listitem>
-<listitem><link linkend="jstemplate">Defining, how R-code is to be generated from the settings, the user makes in the GUI</link></listitem>
-<listitem><link linkend="pluginhelp">Adding a help page to your plugin</link></listitem>
-</itemizedlist>
-Those will be dealt with in turn.
-</para>
-<para>
-Some advanced concepts may be used in those four steps, but are dealt with in separate chapters, to keep things simple:
-<itemizedlist>
-<listitem><link linkend="logic">GUI logic</link></listitem>
-<listitem><link linkend="embedding">Embedding Plugins into Plugins</link></listitem>
-<listitem><link linkend="plugin_series">Useful concepts for creating many series of similar plugins</link></listitem>
-</itemizedlist>
-</para>
-<para>
-Also, none of the chapters shows all options, but rather only the basic concepts. A complete <link linkend="reference">reference</link> of options is provided separately.
-</para>
-</chapter>
-
-<chapter id="whatareplugins">
-<title>Preliminaries: What are plugins in &kapp;? How do they work?</title>
-<para>
-Of course the first question you might have is: What portions of &kapp; functionality is realized using plugins? Or: What can plugins do?
-</para>
-<para>
-One way to answer this is: Deselect all .pluginmap-files under Settings->Configure &kapp;->Plugins, and see what's missing. A slightly more helpful answer: Most actual statistics functions accessible via the GUI are realized using plugins. Also, you can create fairly flexible GUIs for all kinds of operations using plugins.
-</para>
-<para>
-The basic paradigm behind &kapp; plugins is the one we'll walk you through in this document: An xml-file describes what the GUI looks like. An additional Javascript-file is used to generate R syntax from the GUI settings. That is, plugins do not really have to perform any statistical calculations. Rather plugins generate the R syntax needed to run those calculations. The R syntax is then sent to the R backend for evaluation, and typically a result is shown in the output window.
-</para>
-<para>
-Read on in the next chapters to see how this is done.
-</para>
-</chapter>
-
-<chapter id="pluginmap">
-<title>Creating menu entries</title>
-<para>
-When you create a new plugin, you need to tell &kapp; about it. So the first thing to do, is to write a .pluginmap-file (or modify an existing one). The format of .pluginmap is XML. I'll walk you through an example (also of course, be sure you have &kapp; configured to load your pluginmap – Settings->Configure &kapp;->Plugins):
-</para>
-<programlisting>
-<!DOCTYPE rkpluginmap>
-</programlisting>
-<para>
-The doctype is not really interpreted, but set it to "rkpluginmap" anyway.
-</para>
-<programlisting>
-<document base_prefix="" namespace="rkward">
-</programlisting>
-<para>
-The "base_prefix"-attribute can be used, if all your plugins reside in a common directory. Basically, then, you can omit that directory from the filenames specified below. As you will see below, all plugins get a unique identifier. The "namespace" is a way to organize those ids, and make it less likely to create a duplicate identifier accidentally. Internally, basically the namespace and then a "::" gets prepended to all the identifiers you specify below. If unsure, leave these at "" and "rkward".
-</para>
-<programlisting>
- <components>
-</programlisting>
-<para>
-Components? Aren't we talking about plugins? Yes, but in the future, plugins will be no more than a special class of components. What we do here, then, is to register all components/plugins with &kapp;. Let's look at an example entry:
-</para>
-<programlisting>
- <component type="standard" id="independent_samples_t_test" file="means/ttests/independent_samples.xml" label="Independent Samples" />
-</programlisting>
-<para>
-First the "type"-attribute: Leave this to "standard" for now. Further types are not yet implemented. The "id" I've already hinted at. Each component has to be given a unique (in its namespace) identifier. Pick one that is easily recognizable. Avoid spaces and any special characters. Those are not banned, so far, but might have special meanings. With the "file" attribute, you specify where the <link linkend="mainxml">description of the actual plugin itself</link> is located. This is relative to the directory the .pluginmap-file is in, and the "base_prefix" above. Finally, give the component a label. This label will be shown whereever the plugin is placed in the menu (or in the future perhaps in other places as well).
-</para>
-<para>
-Typically a .pluginmap-file will contain several components, so here are a few more:
-</para>
-<programlisting>
- <component type="standard" id="unimplemented_test" file="means/unimplemented.xml" />
- <component type="standard" id="fictional_t_test" file="means/ttests/fictional.xml" label="This is a fictional t-test" />
- <component type="standard" id="descriptive" file="descriptive.xml" label="Descriptive Statistics" />
- <component type="standard" id="corr_matrix" file="corr_matrix.xml" label="Correlation Matrix" />
- <component type="standard" id="simple_anova" file="simple_anova.xml" label="Simple Anova" />
- </components>
-</programlisting>
-<para>
-Ok, this was the first step. &kapp; now knows those plugins exist. But how to invoke them? They need to be placed in a menu-hierarchy:
-</para>
-<programlisting>
- <hierarchy>
- <menu id="analysis" label="Analysis" index="4">
-</programlisting>
-<para>
-Right below the <hierarchy>-tag, you start describing, in which menu, your plugins should go. With the above line, you basically say, that your plugin should be in the "Analysis" menu (not necessarily directly there, but in a submenu). The "Analysis" menu is standard in &kapp;, so it does not actually have to be created from scratch. However, if it did not exist yet, using the "label"-attribute you'd give it its name. The "index" attribute says, that the menu (if newly created) should be placed at the fourth position in the menubar.
-Finally, the "id" once again identifies this menu. This is needed, so several .pluginmap-files can place their plugins in the same menus. They do this by looking for a menu with the given "id". If the id does not yet exist, a new menu will be created. Otherwise the entries will be added to the existing menu.
-</para>
-<programlisting>
- <menu id="means" label="Means" index="1">
-</programlisting>
-<para>
-Basically the same thing here: Now we define a submenu to the "Analysis"-menu. It is to be called "Means".
-</para>
-<programlisting>
- <menu id="ttests" label="T-Tests">
-</programlisting>
-<para>
-And a final level in the menu-hierarchy: A sub-menu of the sub-menu "Means". Note, that if you omit the "index" parameter, the new entry will be placed below any already existing ones.
-</para>
-<programlisting>
- <entry component="independent_samples_t_test" />
-</programlisting>
-<para>
-Now, finally, this is the menu, we want to place the plugin in. The <entry>-tag signals, this actually is the real thing, instead of another submenu. The "component"-attribute refers to the "id" you gave the plugin/component above.
-</para>
-<programlisting>
- <entry component="fictional_t_test" />
- </menu>
- <entry component="fictional_t_test" />
- </menu>
- <menu id="frequency" label="Frequency" index="2"/>
-</programlisting>
-<para>
-In case you have lost track: This is another submenu to the "Analysis" menu. See the screenshot below. We'll skip some of what's not visible, marked with [...].
-</para>
-<programlisting>
- [...]
- </menu>
- <entry component="corr_matrix" index="4"/>
- <entry component="descriptive" index="3"/>
- <entry component="simple_anova" index="5"/>
- </menu>
-</programlisting>
-<para>
-These are the final entries visible in the screenshots below. Note, that you don't need to define the entries in the order they should have in the menu. Use the "index"-attribute instead.
-</para>
-<programlisting>
- <menu id="plots" label="Plots" index="5">
- [...]
- </menu>
-</programlisting>
-<para>
-Of course you can also place your plugins in menus other than "Analysis".
-</para>
-<programlisting>
- <menu id="file" label="File" index="0">
- [...]
- </menu>
-</programlisting>
-<para>
-Even in standard-menus such as "File". All you need is the correct "id".
-</para>
-<programlisting>
- </hierarchy>
-</document>
-</programlisting>
-<para>
-That's how to do it. And this screenshot shows the result:
-</para>
-<screenshot>
-<screeninfo>Menu hierarchy created by the code shown above</screeninfo>
- <mediaobject>
- <imageobject>
- <imagedata fileref="menu_hierarchy_example.png" format="PNG"/>
- </imageobject>
- <textobject>
- <phrase>Menu hierarchy created by the code shown above</phrase>
- </textobject>
- </mediaobject>
-</screenshot>
-<para>
-Confused? The easiest way to get started is probably taking some of the existing .pluginmap files shipped with the distribution, and modifying them to your needs. Also, if you need help, don't hesitate to write to the development mailing list.
-</para>
-</chapter>
-
-<chapter id="mainxml">
-<title>Defining the GUI</title>
-<para>
-In the <link linked="pluginmap">previous chapter</link> you've seen how to register a plugin with &kapp;. The most important ingredient was specifying the path to an XML file with a description of what the plugin actually looks like. In this chapter you'll learn how to create this XML file.
-</para>
-<para>
-Once again we'll walk you through an example. The example is a (slightly simplified) version of the independent samples t-test.
-</para>
-<programlisting>
-<!DOCTYPE rkplugin>
-</programlisting>
-<para>
-The doctype is not really interpreted, yet. Set it to rkplugin, anyway.
-</para>
-<programlisting>
-<document>
- <code file="t_test.js"/>
-</programlisting>
-<para>
-All plugins generate some code. Currently the only way to do so is using JS, as detailed in <link linkend="jstemplate">the next chapter</link>. This defines, where to look for the JS-code. The filename is relative to the directory the plugin-xml is in.
-</para>
-<programlisting>
- <help file="t_test.rkh"/>
-</programlisting>
-<para>
-It is usually a good idea to also provide a help page for your plugin. The filename of that help page is given, here, relative to the directory, the plugin-xml is in. Writing help pages is documented <link linkend="pluginhelp">here</link>. If you do not provide a help file, omit this line.
-</para>
-<programlisting>
- <dialog label="Independent Samples T-Test">
-</programlisting>
-<para>
-As you know, plugins may have either a dialog or a wizard-interface or both. Here we start definining a dialog-interface. the label-attribute specifies the caption of the dialog.
-</para>
-<programlisting>
- <tabbook>
- <tab label="Basic settings">
-</programlisting>
-<para>
-GUI-elements can be organized using a tabbook. Here we define a tabbook as the first element in the dialog. Use <tabbook>[...]</tabbook> to define the tabbook and then for each page in the tabbook use <tab>[...]</tab>. The "label"-attribute in the <tab>-element allows you to specify a caption for that page of the tabbook.
-</para>
-<programlisting>
- <row id="main_settings_row">
-</programlisting>
-<para>
-The <row> and <column> tags specify the layout of the GUI elements. Here you say, that you'd like to place some elements side-by-side (left to right). The "id"-attribute is not strictly necessary, but we'll use it later on, when adding a wizard interface to our plugin. The first element to place in the row, is:
-</para>
-<programlisting>
- <varselector id="vars"/>
-</programlisting>
-<para>
-Using this simple tag you create a list from which the user can select variables. You have to specify an id for this element, so RKWard knows how to find it. Note that you may NOT use a dot (.) in the "id" string.
-</para>
-<programlisting>
- <column>
-</programlisting>
-<para>
-Next, we nest a <column> inside the row. I.e. the following elements will be place above each other (top-to-bottom), and all will be to the right of the <varselector>.
-</para>
-<programlisting>
- <varslot type="numeric" id="x" source="vars" required="true" label="compare"/>
- <varslot type="numeric" id="y" source="vars" required="true" label="against"/>
-</programlisting>
-<para>
-These elements are the counterpart to the <varselector>. They represent "slots" into which the user can put variables. You will note that the "source" is set to the same value as the "id" of the <varselector>. This means, the <varslot>s will each take their variables from the varselector. The <varslot>s also have to be given an "id". They may have a label, and they may be set to "required". This means that the submit-button will not be enabled until the <varslot> holds a valid value. Finally the "type"-attribute is not interpreted, yet, but it will be used to take care that only the correct types of variables will be allowed in the <varslot>.
-</para>
-<programlisting>
- <radio id="hypothesis" label="using test hypothesis">
- <option value="two.sided" label="Two-sided"/>
- <option value="greater" label="First is greater"/>
- <option value="less" label="Second is greater"/>
- </radio>
-</programlisting>
-<para>
-Here, you define a group of <radio>-exclusive buttons. The group has a "label" and an "id". Each <option> (button) has a label and is assigned a value. This is the value the <radio>-element will return when the option is selected.
-</para>
-<programlisting>
- </column>
- </row>
- </tab>
-</programlisting>
-<para>
-Each tag has to be closed. We've put all the elements we wanted (the two <varslots> and the <radio>) in the <column>. We put all elements we wanted (the <varselector> and the <column> with those elements) in the <row>. And we've put all the elements we wanted into the first page in the <tabbook>. We're not yet done defining the <tabbook> (more pages to come) and of course there's more to come in the <dialog>, too. But this screenshot is basically what we've done so far:
-</para>
-<screenshot>
-<screeninfo>T test plugin</screeninfo>
- <mediaobject>
- <imageobject>
- <imagedata fileref="t_test_plugin_example.png" format="PNG"/>
- </imageobject>
- <textobject>
- <phrase>T test plugin</phrase>
- </textobject>
- </mediaobject>
-</screenshot>
-<para>
-Note that we have not specified the "Submit", "Close", etc. buttons or the code-view. Those elements get generated automatically. But of course we still have to define the second page of the <tabbook>:
-</para>
-<programlisting>
- <tab label="Options">
- <checkbox id="varequal" label="assume equal variances" value=", var.equal=TRUE"/>
-</programlisting>
-<para>
-By default elements will be placed top-to-bottom like in a <column>. Since that is what we want here, we don't have to explicitly state a <row> or <column>-layout. The first element we define is a checkbox. Just like the <radio><option>s, the checkbox has a "label" and a "value". The "value" is what gets returned, if the checkbox is checked. Of course the checkbox also needs an "id".
-</para>
-<programlisting>
- <frame label="Confidence Interval" id="frame_conf_int">
-</programlisting>
-<para>
-Here's yet another layout-element: In order to signal that the two elements below belong together, we draw a <frame> (box). That frame may have a caption. Since the frame is just a passive layout-element, it does not need an "id", we still define one, here, as we'll refer to it later, when defining an additional wizard interface.
-</para>
-<programlisting>
- <checkbox id="confint" label="print confidence interval" value="1" checked="true"/>
- <spinbox type="real" id="conflevel" label="confidence level" min="0" max="1" initial="0.95"/>
- </frame>
-</programlisting>
-<para>
-Inside the <frame> we place another <checkbox> (using checked="true", we signal that checkbox should be checked by default), and a <spinbox>. The spinbox allows the user to select a value between "min" and "max" with the default/initial value "0.95". Setting the "type" to "real" signals that real numbers are accepted as opposed to type="integer" which would accept integers only.
-</para>
-<para>
-Note: It is also possible, and often preferrable, to make the <frame> itself checkable, instead of adding a <checkbox> inside. See the reference for details. This is not done, here, for illustrational purposes.
-</para>
-<programlisting>
- </tab>
- </tabbook>
- </dialog>
-</programlisting>
-<para>
-That's all for the second page of the <tabbook>, all pages in the <tabbook> and all elements in the <dialog>. We're finished defining what the dialog looks like.
-</para>
-<programlisting>
-</document>
-</programlisting>
-<para>
-Finally we close the <document>-tag, and that's it. The GUI is defined. You can save the file now.
-But how does R-syntax get generated from the GUI-settings? I'll deal with that in the <link linkend="jstemplate">next chapter</link>. First, however, we'll look into adding a wizard interface, and some general considerations.
-</para>
-
-<section id="wizard_interface">
- <title>Adding a wizard interface</title>
- <para>
- Actually we don't have to define an additional <wizard>-interface, but here's how that would be done. To add a wizard interface, you'll add a <wizard> tag at the same level as the <dialog> tag:
- </para>
- <programlisting>
- <wizard label="Independent Samples T-Test">
- <page id="firstpage">
- <text>As a first step, select the two variables you want to compare against each other. And specify, which one you theorize to be greater. Select two-sided, if your theory does not tell you, which variable is greater.</text>
- <copy id="main_settings_row/>
- </page>
- </programlisting>
- <para>
- Some of this is pretty self explanatory: We add a <wizard> tag with a label for the wizard. Since a wizard can hold several pages that are shown one after another, we next define the first page, and put an explanatory text note in there. Then we use a <copy>-tag. What this does, is really it saves us having to define yet again, what we already wrote for the <dialog>: The copy tag looks for another tag with the same "id" earlier in the .xml. This happens to be defined in the <dialog> section, and is a <row> in which there are the <varselector>, <varslots> and the "hypothesis" <radio>-control. All of this is copied 1:1 and inserted right at the <copy> element.
- </para>
- <para>
- Now to the second page:
- </para>
- <programlisting>
- <page id="secondpage">
- <text>Below are some advanced options. It's generally safe not to assume the variables have equal variances. An appropriate correction will be applied then. Chosing "assume equal variances" may increase test-strength, however.</text>
- <copy id="varequal"/>
- <text>Sometimes it's helpful to get an estimate of the confidence interval of the difference in means. Below you can specify whether one should be shown, and which confidence-level should be applied (95% corresponds to a 5% level of significance).</text>
- <copy id="frame_conf_int"/>
- </page>
- </wizard>
- </programlisting>
- <para>
- Much of the same thing here. We add some texts, and in between that <copy> further sections from the dialog interface.
- </para>
- <para>
- You may of course make the wizard-interface look very different to the plain dialog, and not use the <copy> tag at all. Be sure, however, to assign corresponding elements the same "id" in both interfaces. This is not only used to transfer settings from the dialog-interface to the wizard-interface and back, when the user switches interfaces (which does not yet happen in the current version of RKWard), but also simplifies writing your code-template (see below).
- </para>
-</section>
-
-<section id="mainxmltips">
- <title>Some considerations on GUI design</title>
- <para>
- This section contains some general considerations on which GUI elements to use where. If this is your first attempt of creating a plugin, feel free to skip over this section, as it isn't relevant to getting a basic GUI working. Come back here, later, to see, whether you can refine your plugin's GUI in some way or another.
- </para>
-
- <section id="radio_vs_checkbox_vs_dropdown">
- <title><radio> vs. <checkbox> vs. <dropdown></title>
- <para>
- The three elements <radio>, <checkbox>, <dropdown>, all serve a similar function: To select one out of several options. Obviously, a checkbox only allows to chose between two options: checked or not checked, so you can't use it, if there are more than two options to chose from. But when to use which of the elements? Some rules of thumb:
- </para>
- <para>
- If you find yourself creating a <radio> or <dropdown> with only two options, ask yourself, whether the question is essentially a yes / no type of question. E.g. a choice between "adjust results" and "do not adjust results", or between "remove missing values" and "keep missing values". In this case a <checkbox> is the best choice: It uses little space, will have the least words of labels, and is easiest to read for the user. There are very few situations where you should chose a <radio> over a <checkbox>, when there are only two options. An example of that might be: "Method of calculation: 'pearson'/'spearman'". Here, more methods might be thinkable, and they don't really form a pair of opposites.
- </para>
- <para>
- Chosing between a <radio> and a <dropdown> is mostly a question of space. The <dropdown> has the advantage of using little space, even if there are a lot of options to chose from. On the other hand, a <radio> has the advantage of making all possible choices visible to the user at once, without clicking on the dropdown arrow. Generally, if there are six or more options to chose from, a <dropdown> is preferrable. If there are five or less options, a <radio> is the better choice.
- </para>
- </section>
-</section>
-
-</chapter>
-
-<chapter id="jstemplate">
-<title>Generating R code from GUI settings</title>
-<para>
-Now we have a GUI defined, but we still need to generate some R-code from that. For that, we need another text-file, "code.js", located in the same directory as the <link linkend="mainxml">description.xml</link>. You may or may not be familiar with Javascript (or, to be technically precise: ECMA-script). Documentation on JS can be found in abundance, both in printed form, and on the internet (e.g.: https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide). But for most purposes you will not need to know much about JS at all, as we'll only use some very basic features.
-</para>
-<para>
-For the independent samples t-test, the code.js file looks as follows (with comments in between):
-</para>
-<programlisting>
-function preprocess () {
-}
-</programlisting>
-<para>
-The JS-file is organized into three separate functions: preprocess, calculate, and printout. This is because not all code is needed at all stages. Currently the preprocess-function is not really used in many places (typically you will omit it altogether).
-</para>
-<programlisting>
-function calculate () {
- echo ('res <- t.test (x=' + getValue ("x") + ', y=' + getValue ("y") + ', hypothesis="' + getValue ("hypothesis") + '"' + getValue ("varequal"));
- var conflevel = getValue ("conflevel");
- if (conflevel != "0.95") echo (', conf.level=' + conflevel);
- echo (')\n');
-}
-</programlisting>
-<para>
-This function generates the actual R-syntax to be run from the GUI-settings. Let's look at this in detail:
-The code to be used is generated using "echo"-statement. Looking at the echo() statement step by step, the first part of it is
-</para>
-<screen>
-res <- t.test (
-</screen>
-<para>
-as plain text. Next we need to fill in the value, the user selected as the first variable. We fetch this using getValue ("x"), and append it to the string to be "echoed". This prints out the value of the GUI-element with id "x": our first <varslot>. Next, we append a ', ', and do the same to fetch the value of the element "y" - the second <varslot>. For the hypothesis (the <radio>-group), and the equal variances-<checkbox>, the procedure is very similar.
-</para>
-<para>
-Note that instead of concatenating the output-snippets with "+", you can also use several echo()-statments. Everything is printed on a single line. To produce a line break in the generated code, insert a '\n' in the echoed string. In theory, you can even produce many lines with a single echo-statement, but please keep it to one line (or less) of generated code per echo().
-</para>
-<para>
-It gets a little more tricky for the confidence level. For reasons of aestethics, we don't want to explicitly specify the confidence level to use, if it corresponds to the default value. Hence, instead of printing the value unconditionally, we first fetch into a variable. Then we check, whether that variable differs from "0.95" and if so print out an additional argument.
-Finally, we echo a closing bracket and a line break: ')\n'. That's all for the calculate-function.
-</para>
-<programlisting>
-function printout () {
- echo ('rk.header ("Independent samples t test")\n');
- echo ('rk.print (res)\n');
-}
-</programlisting>
-<para>
-And this was all there is to the printout function in most cases. rk.header () prints a standard headline for the results. You can also add some more information to this, if you like, e.g.:
-</para>
-<programlisting>
-function printout () {
- makeHeaderCode ("Independent samples t test", new Array ("Assume equal variances", getValue ("varequal"), "Confidence level", getValue ("conflevel")))
- echo ('rk.print (res)\n');
-}
-</programlisting>
-<para>
-rk.print () utilizes the R2HTML package to provide HTML formatted output. Another helpful function is rk.results (), which can also output different kinds of result tables. If in doubt, however, just use rk.print (), and be done with. makeHeaderCode () is a Js-level helper function to create a call to rk.header () (just take a look at the generated code). In some cases you may want to call "echo ('rk.header (...)')" directly to print a header for your output.
-</para>
-<para>
-Note that internally, the output is just a plain HTML document at this point of time. Therefore you might be tempted to add custom HTML using rk.cat.output (). While this will work, please don't do this. The output format may change (e.g. to ODF) in the future, so it's best not to introduce HTML specific code. Rather keep things simple with rk.header (), rk.print (), rk.results (), and - if needed - rk.print.literal(). If those don't seem to satisfy your formatting needs, contact us on the mailing list for help.
-</para>
-<para>
-Congratulations! You created your first plugin. Read on in the next chapters for more advanced concepts.
-</para>
-
-<section id="jsconventions">
-<title>Conventions, policies, and background</title>
-<para>
-There are many ways to write R code for a certain task, and there are even more ways to generate this R code from Js. How exactly you do it, is left up to you. Still there are a number of considerations that you should follow, and background information you should understand.
-</para>
-
-<section id="policylocal">
-<title>Understanding the local() environment</title>
-<para>
-More often than not you will have to create one or more temporary R objects in the code generated by your plugin. Normally, you do not want those to be placed in the user's workspace, potentially even overwriting user variables. Hence, all plugin generated code is run in a local() environment (see R help page on function local()). This means, all variables you create are temporary and will not be saved permanently.
-</para>
-<para>
-If the user explicitely asks for a variable to be saved, you will need to assign to that object using ".GlobalEnv$objectname <- value". In general, do not use the "<<-"-operator. It will not necessarily assign in .GlobalEnv.
-</para>
-<para>
-One important pitfall is using eval(). Here, you need to note that eval will by default use the current environment for evaluation, i.e. the local one. This will work well most of the times, but but not always. Thus, if you need to use eval(), you will probably want to specify the "envir" parameter: eval(..., envir=globalenv()).
-</para>
-</section>
-
-<section id="policyformatting">
-<title>Code formatting</title>
-<para>
-The most important thing is for your generated R code to work. But please also keep an eye on formatting. Some considerations:
-</para>
-<para>
-Normal top-level R statements should be left aligned.
-</para>
-<para>
-Statements in a lower block should be indented with one tab (see example below).
-</para>
-<para>
-If you do very complex calculations, add a comment here and there, esp. to mark up logical sections.
-</para>
-<para>
-For example, generated code might look like this. The same code without indentation or comments would be pretty hard to read, despite its modest complexity:
-</para>
-<programlisting>
-# first determine the wobble and rotation
-my.wobble <- wobble (x, y)
-my.rotation <- wobble.rotation (my.wobble, z)
-
-# boggling method needs to be chosen according to rotation
-if (my.rotation > wobble.rotation.limit (x)) {
- method <- "foo"
- result <- boggle.foo (my.wobble, my.rotation)
-} else {
- method <- "bar"
- result <- boggle.bar (my.wobble, my.rotation)
-}
-</programlisting>
-</section>
-
-<section id="policysimplicity">
-<title>Dealing with complex options</title>
-<para>
-Many plugins can do more than one thing. For instance, the "Descriptive Statistics" plugin can compute mean, range, sum, product, median, length, etc. However, typically the user will only chose to have some of those calculations performed. In this case, please try to keep the generated code as simple as possible. It should only contain portions relevant to the options that are actually selected. To achieve this, here is an example of a common design patterns as you would use it (in JS):
-</para>
-<programlisting>
-function calculate () {
- echo ('x <- <' + getValue ("x") + ')\n');
- echo ('results <- list ()\n');
-
- if (getValue ("domean")) echo ("results$'Mean value' <- mean (x)\n");
- if (getValue ("domedian")) echo ("results$'Median' <- median (x)\n");
- if (getValue ("dosd")) echo ("results$'Standard deviation' <- sd (x)\n");
- //...
-}
-</programlisting>
-</section>
-
-</section>
-
-<section id="jstips">
-<title>Tips and tricks</title>
-<para>
-Here are a few assorted tricks which may make writing plugins less tedious:
-</para>
-<para>
-If you need the value of a GUI setting at several places in you plugin's code, consider assigning it to a variable in JS, and using that instead of fetching it again and again with getValue. This is faster, more readable, and less typing all at the same time:
-</para>
-<programlisting>
-function calculate () {
- var narm = ""; // na.rm=FALSE is the default in all functions below
- if (getValue ("remove_nas") == "1") {
- $narm = ", na.rm=TRUE";
- }
- // ...
- echo ("results$foo <- foo (x" + narm + ")\n");
- echo ("results$bar <- bar (x" + narm + ")\n");
- echo ("results$foobar <- foobar (x" + narm "\n");
- // ...
-}
-</programlisting>
-</section>
-
-</chapter>
-
-<chapter id="pluginhelp">
- <title>Writing a help page</title>
- <para>
- When your plugin basically works, the time has come to provide a help page. While typically you will not want to explain all the underlying concepts in depth, you may want to add some more explanation for some of the options, and link to related plugins and R functions.
- </para>
- <para>
- You may recall putting this inside your plugin-xml (if you haven't put this in, do so now):
- </para>
- <programlisting>
- <document>
- [...]
- <help file="filename.rkh" />
- [...]
- </document>
- </programlisting>
- <para>
- Where, obviously, you'd replace "filename" with a more appropriate name. Now it's time to create this .rkh file. Here is a self-descriptive example:
- </para>
- <programlisting>
- <!DOCTYPE rkhelp>
- <document>
- <summary>
- In this section, you'll put some short, very basic information about what the plugin does.
- This section will always show up on the very top of the help page.
- </summary>
-
- <usage>
- The usage section may contain a little more practical information. It does not explain all
- the settings in detail (that's done in the "settings" section), however.
-
- To start a new paragraph, insert an empty line, as shown above.
- This line, in contrast, will be in the same paragraph.
-
- In all sections you can insert some simple HTML code, such as <b>bold</b> or
- <i>italic</i> text. Please keep formatting to the minimum needed, however.
-
- The usage section is always the second section shown in a help page.
- </usage>
-
- <section id="sectionid" title="Generic section" short_title="Generic">
- If you need to, you can add additional sections between the usage and settings sections.
- However, usually, you will not need this while documenting plugins. The "id"-attribute
- provides an anchor point to jump to this section from the navigation menu. The "short_title"
- attribute provides a short title to use in the navigation bar. This is optional, by default
- the main "title" will be used both as a heading to the section, and as the link name in the
- navigation bar.
-
- In any section you may want to insert links to further information. You do this by adding
-
- <link href="URL">link name</link>
-
- Where URL could be an external link such as http://rkward.sourceforge.net .
- Several special URLs are supported in the help pages:
-
- <link href="rkward://page/path/page_id"/>
-
- This links to a top level rkward help page (not for a plugin).
-
- <link href="rkward://component/[namespace/]component_id"/>
-
- This links to the help page of another plugin. The [namespace/] part may be omitted
- (in this case, rkward is assumed as the standard namespace, e.g.:
- <link href="rkward://component/import_spss"/> or
- <link href="rkward://component/rkward/import_spss"/> are equivalent).
- The component_id is the same that you specified in the <link linkend="pluginmap">.pluginmap</link>.
-
- <link href="rkward://rhelp/rfunction"/>
-
- Links to the R help page on "rfunction".
-
- Note that the link names will be generated automatically for these types of links.
- </section>
-
- <settings>
- <caption id="id_of_tab_or_frame"/>
- <setting id="id_of_element">
- Description of the GUI element identified by the given id
- </setting>
- <setting id="id_of_elementb" title="description">
- Usually the title of the GUI element will be extracted from the
- <link linkend="mainxml">XML definition of the plugin</link>, automatically. However,
- for some GUI elements, this description may not be enough to identify them, reliably.
- In this case, you can add an explicit title using the "title" attribute.
- </setting>
- <setting id="id_of_elementc">
- Description of the GUI element identified by "id_of_elementc"
- </setting>
- [...]
- </settings>
-
- <related>
- The related section typically just contains some links, such as:
-
- <ul>
- <li><link href="rkward://rhelp/mean"/></li>
- <li><link href="rkward://rhelp/median"/></li>
- <li><link href="rkward://component/related_component"/></li>
- </ul>
- </related>
-
- <technical>
- The technical section (optional, always last) may contain some technical details of the plugin
- implementation, which are of interest only to RKWard developers. This is particularly relevant
- for plugins that are designed to be embedded in many other plugins, and could detail, which
- options are available to customize the embedded plugin, and which code sections contain which
- R code.
- </technical>
- </document>
- </programlisting>
-</chapter>
-
-
-<chapter id="logic">
-<title>GUI logic</title>
-<para>
-All the basic concepts of creating a plugin for &kapp; have been described in the previous chapters. Those basic concepts should be sufficient for many - if not most - cases. However, sometimes you want more control over how your plugin's GUI behaves.
-</para>
-<para>
-For instance, suppose you want to extend the t-test example used in this documentation to allow both: comparing a variable against another variable (as shown), and comparing a variable against a constant value. Now, one way of doing this would be to add a radio-control that switches between the two modes, and adding a spinbox to enter the constant value to compare against. Consider this simplified example:
-</para>
-<programlisting>
-<!DOCTYPE rkplugin>
-<document>
- <code file="code.js"/>
-
- <dialog label="T-Test">
- <row>
- <varselector id="vars"/>
- <column>
- <varslot id="x" type="numeric" source="vars" required="true" label="compare"/>
- <radio id="mode" label="Compare against">
- <option value="variable" checked="true" label="another variable (select below)"/>
- <option value="constant" label="a constant value (set below)"/>
- </radio>
- <varslot id="y" type="numeric" source="vars" required="true" label="variable"/>
- <spinbox id="constant" initial="0" label="constant" />
- </column>
- </row>
- </dialog>
-</document>
-</programlisting>
-<para>
-So far so good, but there are a number of problems with this GUI. First, both the varslot and the spinbox are always shown, whereas only one of the two is really used. Worse, the varslot always requires a valid selection, even if you compare against a constant. Obviously, if we create a multi-purpose GUI like this, we want more flexibility. Enter: the <logic>-section (inserted at the same level as <code>, <dialog>, or <wizard>).
-</para>
-<para>
-<programlisting>
- [...]
- <code file="code.js"/>
-
- <logic>
- <convert id="varmode" mode="equals" sources="mode.string" standard="variable" />
- <convert id="constmode" mode="equals" sources="mode.string" standard="constant" />
-
- <connect client="y.visible" governor="varmode" />
- <connect client="constant.visible" governor="constmode" />
- </logic>
-
- <dialog label="T-Test">
- [...]
-</programlisting>
-</para>
-<para>
-The first two lines inside the logic section are <conver> tags. Those basically provide two new boolean (on or off, true or false) properties, which can be used later on. The first property ("varmode") is true, whenever the upper radio-button is selected and the second whenever the lower radio-button is selected. How is this done?
-</para>
-<para>
-First, under sources, the "source" properties to work on are listed (in this case only one each; you could list several as sources="mode.string;somethingelse", then varmode would only be true, if both mode.string and somethingelse are equal to the string "variable"). Note that in this case we don't just write "mode" (as we would in getValue("mode"), but "mode.string". This is actually the internal way a radio control works: It has a property "string", which holds its string value. getValue("mode") is just a shorthand, and equivalent to getValue("mode.string"). See the reference for all properties of the different GUI elements.
-</para>
-<para>
-Second, we set the mode of conversion to mode="equals". This means, we want to check, whether the sources are equal to a certain value. Finally standard is the value to compare against, so with standard="variable", we check whether the property mode.string is equal to the string "variable" (the value of the upper radio option). If it is equal, then the property varmode is true, else it is false.
-</para>
-<para>
-The next line is basically the same, but reversed. Here we define a property ("constmode") which becomes true, if the second radio option is selected.
-</para>
-<para>
-Now to the real stuff: We <connect> the "varmode" property to y.visible, which controls whether the varslot "y" is shown or not. Note that any element which is made invisible is implicitly non-required. Thus, if the upper radio-option is selected, the varslot "y" is required, and visible. Else it is not required and hidden.
-</para>
-<para>
-We do just the reverse for the spinbox. So in effect, either the varslot is shown and required, <emphasis>or</emphasis> the spinbox is shown and required - depending on which option is selected in the radio control. The GUI is changing itself according to the radio option. Try the example, if you like.
-</para>
-<para>
-Note: In the above example, instead of defining two properties "varmode" and "constmode", we could also have used the negation of "varmode", like this:
-</para>
-<programlisting>
- <connect client="constant.visible" governor="varmode.not" />
-</programlisting>
-<para>
-Once again, for a complete list of properties, refer to the <link linkend="reference">reference</link>. One more property, however, is special in that all GUI elements have it: "enabled". This is slightly less drastic that "visible". It does not show/hide the GUI element, but only enables/disables it. Disabled elements are typically shown grayed out, and do not react to user input.
-</para>
-<section id="logic_scripted">
-<title>Scripted GUI logic</title>
-<para>While connecting properties as described above is often enough, sometimes it is more flexible or more convenient to use JS to script the GUI logic. In this way, the above example could be re-written as:</para>
-<programlisting>
- [...]
- <code file="code.js"/>
-
- <logic>
- <script><![CDATA[
- // ECMAScript code in this block
- // the top-level statement is only called once
- gui.addChangeCommand ("mode.string", "modeChanged ()");
-
- // this function is called whenever the "mode" was changed
- modeChanged = function () {
- var varmode = (gui.getValue ("mode.string") == "variable");
- gui.setValue ("y.enabled", varmode);
- gui.setValue ("constant.enabled", !varmode);
- }
- ]]></script>
- </logic>
-
- <dialog label="T-Test">
- [...]
-</programlisting>
-<para>
-The first line of code tells RKWard to call the function "modeChanged()" whenever the value of the "mode" radio-box changes. Inside this function, we define a helper-variable "varmode" which is true when the mode is "variable", false is it is "constant". Then we use "gui.setValue()" to set the and "enabled"-properties of "y" and "constant", in just the same way as we did using <connect>-statements, before.</para>
-<para>
-The scripted approach to GUI logic becomes particularly useful when you want to change the available option according to the type of object that the user has selected. See <link linkend="guilogic_functions">the reference</link> for available functions.
-</para>
-<para>
-Note that the scripted approach to GUI logic can be mixed with <connect> and <convert>-statements if you like. Also note that the <script>-tag allows to specify a script file name in addition to or as an alternative to inlining the script code. Typically, inlining the script code as shown above is most convenient, however.
-</para>
-</section>
-</chapter>
-
-<chapter id="embedding">
-<title>Embedding Plugins into Plugins</title>
-<para>
-When writing plugins, you will often find that you're creating a number of plugins that only differ in some respects, but have a lot more in common. For instance, for plotting, there are a number of generic R options that can be used with mostly all types of plots. Should you create a GUI and JS-template for those over and over again?
-</para>
-<para>
-Obviously that would be quite a hassle. Fortunately, you don't have to do that. Rather you create the common functionality once, and later you can embed it into several plugins. In fact it is possible to embed any plugin into any other plugin, even if the original author of the embedded plugin never thought, somebody would want to embed their plugin into another one.
-</para>
-<section id="embedding_dialog">
-<title>Embedding inside a dialog</title>
-<para>
-Ok, enough said. How does it work? Simple: Just use the <embed> tag. Here's a stripped down example:
-</para>
-<programlisting>
-<dialog>
- <tabbook>
- <tab [...]>
- [...]
- </tab>
- <tab label="Plot Options">
- <embed id="plotoptions" component="rkward::plot_options"/>
- </tab>
- <tab [...]>
- [...]
- </tab>
- </tabbook>
-</dialog>
-</programlisting>
-<para>
-What happens here, is that the entire GUI or the plot options plugin (except of course for the standard elements like submit-button, etc.) is embedded right into your plugin (try it!).
-</para>
-<para>
-As you can see the syntax of the <embed>-tag is fairly simple. It takes an id as most elements. The parameter component specifies which plugin to embed, as defined in the <link linkend="pluginmap">.pluginmap</link> file ("rkward::plot_options" is the result of concatenating the namespace "rkward", a separator "::", and the name of the component "plot_options").
-</para>
-</section>
-<section id="embedding_code">
-<title>Code generation when embedding</title>
-<para>
-So far so good, but what about the generated code? How are the code for the embedding and embedded plugin merged? In the embedding plugin's JS-code, simply write something like this:
-</para>
-<programlisting>
-function printout () {
- // ...
- echo ("myplotfunction ([...]" + getValue ("plotoptions.code.printout"); + ")\n");
- // ...
-}
-</programlisting>
-<para>
-So essentially, we're fetching the code generated by the embedded plugin just like we're fetchting any other GUI setting. Here the string "plotoptions.code.printout" can be deparsed to: "The printout section of the generated code of the element with the id plotoptions" (plotoptions is the id we gave for the <embed>-tag above). And yes, if you want advanced control, you can even fetch the values of individual GUI elements inside the embedded plugin (but not the other way around, as the embedded plugin does not know anything about its surroundings).
-</para>
-</section>
-<section id="embedding_wizard">
-<title>Embedding inside a wizard</title>
-<para>
-If your plugin provides a wizard GUI, embedding works basically in the same way. You'll generally use:
-</para>
-<programlisting>
- <wizard [...]>
- [...]
- <page id="page12">
- [...]
- </page>
- <embed id="plotoptions" component="rkward::plot_options"/>
- <page id="page13">
- [...]
- </page>
- [...]
- </wizard>
-</programlisting>
-<para>
-If the embedded plugin provides a wizard interface, its pages will be inserted right between page12 and page13 of your plugin. If the embedded plugin provides a dialog interface only, a single new page will be added between your pages page12 and page13. The user will never notice.
-</para>
-</section>
-<section id="embedding_as_button">
-<title>Less embedded embedding: Further options button</title>
-<para>
-While embedding is cool, you should be careful not to overdo it. Too many functions inside a GUI just make it hard to find the relevant options. Of course, sometimes you may want to embed a great deal of options (like all the options to plot ()), but as those are really optional, you don't want them prominently in your GUI.
-</para>
-<para>
-An alternative is to embed those options "as a button":
-</para>
-<programlisting>
-<dialog>
- <tabbook>
- [...]
- <tab label="Options">
- [...]
- <embed id="plotoptions" component="rkward::plot_options" as_button="true" label="Specify plotting options"/>
- </tab>
- [...]
- </tabbook>
-</dialog>
-</programlisting>
-<para>
-In this case, a single push button will be added to your plugin, labelled "Specify plotting options". When you press that button, a separate dialog will come up, with all the options of the embedded plugin. Even while this embedded GUI is not visible most of the time, you can fetch its settings just as described <link linkend="embedding_code">above</link>.
-</para>
-<para>
-<emphasis>Caution:</emphasis> Probably the "button" approach should only ever be used for plugins that can never be invalid (for missing/bad settings). Otherwise the user would not be able to submit the code, but might have a hard time finding out, the reason for that is hidden behind some button.
-</para>
-</section>
-<section id="embedding_incomplete">
-<title>Embedding/defining incomplete plugins</title>
-<para>
-Some plugins - and as a matter of fact, the plot_options used as an example above, is one of them - are not complete by themselves. They simply do not have the GUI elements to select some important values. They are meant to be used only embedded into other plugins.
-</para>
-<para>
-In how far is the plot_options plugin incomplete? Well, for some option settings, it needs to know the name of the objects/expressions for the x and y axes (actually it will do fine if it only has either, but it needs at least one to function properly). However, it does not have a mechansim of selecting those objects, or entering them any other way. So how does it know about them?
-</para>
-<para>
-In the logic section of the plot_options plugin there are two additional lines, not covered, yet:
-</para>
-<programlisting>
- <logic>
- <external id="xvar" />
- <external id="yvar" />
-
- [...]
- </logic>
-</programlisting>
-<para>
-This defines two additional properties in the plot_options plugin, whose sole purpose is to be connected to some (yet unknown) properties of the embedding plugin. In the plot_options plugin those two properties are simply used like any other, and for instance there are calls to getValue("xvar") in the plot_options JS template.
-</para>
-<para>
-Now, for the incomplete plugin there is no way of knowing, where it will be embedded, and what the relevant settings in the embedding plugin will be called. So we need to add two additional lines in the embedding plugin's logic section as well:
-</para>
-<programlisting>
- <logic>
- [...]
-
- <connnect client="plotoptions.xvar" governor="xvarslot.available" />
- <connnect client="plotoptions.yvar" governor="yvarslot.available" />
- </logic>
-</programlisting>
-<para>
-This is nothing new in principle, we've covered <connect> statements in the <link linkend="logic">chapter of GUI logic</link>. You simply connect the values in two varlots (called "xvarslot" and "yvarslot" in this example) to the receiving "external" properties of the embedded plugin. That's it. Everything else is taken care of automatically.
-</para>
-</section>
-</chapter>
-
-<chapter id="plugin_series">
-<title>Dealing with many similar plugins</title>
-<para>
-Sometimes, you may wish to develop plugins for a series of similar functions. As an example, consider the distribution plots. These generate fairly similar code, and of course it's desirable to make the graphical interfaces look similar to each other. Finally large sections of the help files can be identical. Only a few parameters are different for each plugin.
-</para>
-<para>
-The naive approach to this is to develop one plugin, then basically copy and paste the entire contents of the .js, .xml, and .rkh files, then changing the few portions that are different. However, what if sometime later you find a spelling mistake that has been copied and pasted to all plugins? What if you want to add support for a new feature? You'd have to visit all plugins again, and change each single one. A tiresome and tedious process.
-</para>
-<para>
-A second approach would be to use <link linkend="embedding">embedding</link>. However, in some cases this does not lend itself well to the problem at hand, mostly because the "chunks" you can embed are sometimes too large to be useful, and it places some constraints on the layout. For these cases, the concepts <link linkend="include_js">including .js files</link> <link linkend="include_xml">including .xml files</link> and <link linkend="snippets">snippets</link> can be very useful (but see the <link linkend="include_snippets_vs_embedding">thoughts on when it is preferrable to use embedding</link>).
-</para>
-<para>
-One word of caution, before you begin reading, though: These concepts can help making it simpler to deal with many similar plugins, and can improve maintainability and readability of those plugins. However, overdoing it can easily lead to the reverse effect. Use with some caution.
-</para>
- <section id="include_js">
- <title>Using the JS include statement</title>
- <para>
-You can easily include one script file into another in &kapp; plugins. The value of this becomes immediately obvious, if some sections of your JS code are similar across plugins. You can simply define those sections in a separate .js file, and include this in all the plugin .js files. For example, as in:
- </para>
- <programlisting>
-// this is a file called "common_functions.js"
-
-function doCommonStuff () {
- // perhaps fetch some options, etc.
- // ...
- echo ("# This is R code you want in several different plugins\n");
- // ...
-}
- </programlisting>
- <programlisting>
-// this is one of your regular plugin .js files
-
-// include the common functions
-include ("common_functions.js");
-
-function calculate () {
- // do something
- // ...
-
- // insert the common code
- doCommonStuff ();
-}
- </programlisting>
- <para>
-Note that sometimes it's even more useful to reverse this, and define the "skeleton" of preproces(), calculate(), and printout() functions is a common file, and make these call back for those part which are different across plugins. E.g.:
- </para>
- <programlisting>
-// this is a file called "common_functions.js"
-
-function calculate () {
- // do some things which are the same in all plugins
- // ...
-
- // add in something that is different across plugins
- getSpecifics ();
-
- // ...
-}
- </programlisting>
- <programlisting>
-// this is one of your regular plugin .js files
-
-// include the common functions
-include ("common_functions.js");
-
-// note: no calculate() function is defined in here.
-// it in the common_functions.js, instead.
-
-function getSpecifics () {
- // print some R code
-}
- </programlisting>
- <para>
-One issue you should be aware of when using this technique is variable scoping. See the JS manual on variable scopes.
- </para>
- <para>
-This technique is heavily used in the distribution plot and distribution CLT plot plugins, so you may want to look there for examples.
- </para>
- </section>
-
- <section id="include_xml">
- <title>Including .xml files</title>
- <para>
-Basically the same feature of including files is also available for use in the .xml and .rkh files. At any place in these files you can place an <include> tag as shown below. The effect is that the entire contents of that XML file (to be precise: everything within the <document> tag of that file) is included verbatim at this point in the file. Note that you can only include another XML file.
- </para>
- <programlisting>
-<document>
- [...]
- <include file="another_xml_file.xml"/>
- [...]
-</document>
- </programlisting>
- <para>
-The attribute "file" is the filename relative to the directory the current file is located in.
- </para>
- </section>
-
- <section id="snippets">
- <title>Using <snippets></title>
- <para>
-While including files as shown in the <link linkend="include_xml">previous section</link> is fairly powerful, it become most useful when used in combination with <snippets>. Snippets are really smaller sections which you can insert at another point in the file. An example illustrates this best:
- </para>
- <programlisting>
-<document>
- <snippets>
- <snippet id="note">
- <frame>
- <text>
- This will be inserted at two places in the GUI
- </text>
- </frame>
- </snippet>
- </snippets>
- <dialog label="test">
- <column>
- <insert snippet="note"/>
- [...]
- <insert snippet="note"/>
- </column>
- </dialog>
-</document>
- </programlisting>
- <para>
-Hence, you define the snippet at one place at the top of the xml file, and then you <insert> it at any place(s) you wish.
- </para>
- <para>
-While this example is not too useful in itself, think about combining this with an <include>d .xml file. Note, that you can also place snippets for the .rkh file in the same file. You'd simply <include> the file there as well, and <insert> the relevant snippet:
- </para>
- <programlisting>
-<!-- This is a file called "common_snippets.xml" -->
-<document>
- <snippet id="common_options">
- <spinbox id="something" [...]/>
- [...]
- </snippet>
- <snippet id="common_note">
- <text>An important note for this type of plugin</text>
- </snippet>
-
- <snippet id="common_help">
- <setting id="something">This does something</setting>
- [...]
- </snippet>
-</document>
- </programlisting>
- <programlisting>
-<!-- This is the .xml file of the plugin -->
-<document>
- <snippets>
- <!-- Import the common snippets -->
- <include file="common_snippets.xml"/>
- </snippets>
-
- <dialog label="test2">
- <insert snippet="common_note"/>
- <spinbox id="something_plugin_specific" [...] />
- <insert snippet="common_options"/>
- </dialog>
-</document>
- </programlisting>
- <para>
-Similar to <link linkend="include_js">inclusion in JS</link>, the reverse approach is often even more useful:
- </para>
- <programlisting>
-<!-- This is a file called "common_layout.xml" -->
-<document>
- <column>
- <insert snippet="note">
- [...]
- <insert snippet="plugin_parameters">
- </column>
- [...]
-</document>
- </programlisting>
- <programlisting>
-<!-- This is the .xml file of the plugin -->
-<document>
- <snippets>
- <snippet id="note">
- <text>The note used for this specific plugin</text>
- </snippet>
-
- <snippet id="plugin_parameters">
- <frame label="Parameters specific to this plugin">
- [...]
- </frame>
- </snippet>
- </snippets>
-
- <dialog label="test3">
- <include file="common_layout.xml"/>
- </dialog>
-</document>
- </programlisting>
- <para>
-Finally, it is also possible to <insert> snippets into other snippets, provided that: a) there is only one level of nesting, and b) the <snippets> section is placed at the top of the file (before a nested snippet is inserted); this is because <insert> statements are resolved from top to bottom.
- </para>
- </section>
-
- <section id="include_snippets_vs_embedding">
- <title><include> and <snippets> vs. embedding</title>
- <para>
-At first glance, <include> and <snippets> provides functionality rather similar to <link linkend="embedding">embedding</link>: It allows to reuse some portions of code across plugins. So what's the difference between these approaches, and when should you use which?
- </para>
- <para>
-The key difference between these concepts is that embeddable plugins are a more tight bundle. They combine a complete GUI, code to generate R code from this, and a help page. In contrast, include and insert allow much more fine grained control, but at the price of less modularity.
- </para>
- <para>
-That is, a plugin embedding another plugin will typically not need to know much about the internal details of the embedded plugin. A prime example is the plot_options plugin. Plugins wishing to embed this do not necessarily need to know about all the options provided, or how they are provided. This is a good thing, as otherwise a change in the plot_options plugin might make it necessary to adjust all plugins embedding this (a lot). In contrast, include and insert really exposes all the internal details, and plugins using this will - for example - need to know the exact ids and perhaps even the type of the elements used.
- </para>
- <para>
-Hence the rule of thumb is this: include and insert are great if the relevant options are only needed for a clearly limited group of plugins. Embedded plugins are better, if the group of plugins it may be useful to is not clearly defined, and if the functionality can easily be modularized. Another rule of thumb: If you can put the common portions into a single "chunk", then do so, and use embedding. If you need lots of small snippets to define the common portions - well, use <snippets>. A final way to look at it: If all plugins provide <emphasis>highly</emphasis> similar functionality, includes and inserts are probably a good idea. If they merely share one or two common "modules", embedding is likely better.
- </para>
- </section>
-</chapter>
-
-<chapter id="specialized_plugins">
-<title>Concepts for use in specialized plugins</title>
-<para>
-This chapter contains information on some topics that are useful only to certain classes of plugins.
-</para>
-
-<section id="preview_plots">
- <title>Preview functionality for graphing plugins</title>
- <para>
-A very useful feature for all plugins generating a plot / graph is to provide an automatically updating preview. To do so, you will need two things: Adding a <preview>-checkbox to your <link linkend="mainxml">GUI definition</link>, and adjusting the <link linkend="jstemplate">generated code</link> for the preview. We will deal with both in turn.
- </para>
- <para>
-Adding a <preview>-checkbox is simple. Just place the following somewhere in your GUI. It will take care of all the behind-the-scenes magic of creating a preview device, updaing the preview whenever the setting have changed, etc. Example:
- </para>
- <programlisting>
-<document>
- [...]
- <dialog [...]>
- [...]
- <preview id="preview"/>
- [...]
- </dialog>
- [...]
-</document>
- </programlisting>
- <para>
-And that's it for the GUI definition.
- </para>
- <para>
-Adjusting the JS template is a little more work. You will have to create a new function called "preview" in addition to the "preprocess", "calculate", etc. functions. This function should generate the code needed to produce the plot, and only that. Esp. no printing of headers, rk.graphics.on(), or similar calls. Below is an example of the typical pattern that you will use:
- </para>
- <programlisting>
-function preprocess () {
- // the "somepackage" is needed to create the plot
- ecoh ("require (somepackage)\n");
-}
-
-function printout () {
- // all the real work is moved to a custom defined function doPrintout (), below
-
- doPrintout (true); // true in this case means: We want all the headers that should be printed in the output
-}
-
-function preview () {
- // we call all stages of the general code. Only the printout () function need to be slightly different
- preprocess ();
- // calculate (); in this example the plugin has no calculate () function.
- doPrintout (false);
-}
-
-function doPrintout (full) {
- // this function takes care of generating the code for the printout() section. If "full" is set to true,
- // it generates the full code, including headers. If full is set to false, only the essentials will
- // be generated.
-
- if (full) {
- echo ('rk.header ("An example plot")\n\n');
- echo ('rk.graph.on ()\n');
- }
-
- // only the following section will be generated for full==false
- echo ('try ({plot (5, 5)})\n');
-
- if (full) {
- echo ('rk.graph.off ()\n');
- }
-}
- </programlisting>
- <para>
-That's it, your plugin should now be preview-enabled.
- </para>
-</section>
-
-<section id="contextualized_plugins">
- <title>Context-dependent plugins</title>
- <para>
-So far we have assumed, all plugins are always meaningful, and all placed in the main menu. However, some plugins are meaningful only (or additionally) in a certain context. For instance a plugin to export the contents of an R X11 graphics device is obviously most useful, when placed in the menu of an X11 device, not in the main menubar. Also, such a plugin should know about the device number that it should operate on, without having to ask the user about this.
- </para>
- <para>
-We call such plugins context-dependent. Correspondingly, in the <link linkend="pluginmap">.pluginmap file</link>, they are not (or not only) placed in the main <hierarchy> but rather into a <context> element. So far only two different contexts are supported (more will come later): x11 and file import. We'll deal with those in turn. Even if you are only interested in the import context, please also read the section on the x11 context, as this is slightly more elaborate.
- </para>
-
- <section id="context_x11">
- <title>X11 device context</title>
- <para>
-To use a plugin in the context of an x11 device - that is place it in the menu bar of the window you get when you call "x11 ()" in the cosonle, first declare it as usual in the <link linkend="pluginmap">.pluginmap file</link>:
- </para>
- <programlisting>
-<document [...]>
- <components>
- [...]
- <component id="my_x11_plugin" file="my_x11_plugin.xml" label="An X11 context plugin"/>
- [...]
- </components>
- </programlisting>
- <para>
-However, you do not need to define it in the hierarchy (you can, if it is also meaningful as a top-level plugin):
- </para>
- <programlisting>
- <hierarchy>
- [...]
- </hierarchy>
- </programlisting>
- <para>
-Instead, add a definition of the "x11" context, and add it to the menus there:
- </para>
- <programlisting>
- <context id="x11">
- [...]
- <menu id="edit">
- [...]
- <entry id="my_x11_plugin"/>
- </menu>
- </context>
-</document>
- </programlisting>
- <para>
-In the <link linkend="logic">logic section of the plugin xml</link>, you can now declare two <external> properties: "devnum" and "context". Context (if declared) will be set to "x11" when the plugin is invoked in this context. "devnum" will be set to the number of the graphics device to operate on. And that's all.
- </para>
- </section>
-
- <section id="context_import">
- <title>Import data context</title>
- <para>
-Before reading this section, please make sure to read the section on the <link linkend="context_x11">X11 device context</link>, as that explains the basic concepts.
- </para>
- <para>
-The "import" context is used to declare import file filter plugins. You simply place those in a context with id="import" in the .pluginmap file. However, there is one additional twist when declaring these plugins: In order to offer a unified file selection dialog for all supported file types, you need to declare one additional bit of information on your component:
- </para>
- <programlisting>
-<document [...]>
- <components>
- [...]
- <component id="my_xyz_import_plugin" file="my_xyz_import_plugin.xml" label="Import XYZ files">
- <attribute id="format" value="*.xyz *.zyx" label="XYZ data files"/>
- </component>
- [...]
- </components>
- <hierarchy>
- [...]
- </hierarchy>
- <context id="import">
- [...]
- <menu id="import">
- [...]
- <entry id="my_xyz_import_plugin"/>
- </menu>
- </context>
- [...]
-</document>
- </programlisting>
- <para>
-The attribute line simply says, that the associate filename extensions for XYZ files are *.xyz or *.zyx, and that the filter should be labelled "XYZ data files" in the file selection dialog.
- </para>
- <para>
-You can declare two <external> properties in your plugin. "filename" will be set to the selected file name, and "context" will be set to "import".
- </para>
- </section>
-</section>
-
-<section id="current_object">
-<title>Referencing the current object</title>
-<para>For many plugins it is desirable to work on the "current" object. For instance a "sort" plugin could pre-select the data.frame that is currently being edited for sorting. The name of the current object is available to plugins as a pre-defined property called "current_object". You can connect to this property in the usual way. If no object is current, the property equates to an empty string.</para>
-<para>Currently the "current_object" can only be of class data.frame, but please do not rely on this, since this will be extended to other types of data in the future. Therefore please check any requirements by using appropriate constraints on your <varslot>s, or by using <link linkend="logic_scripted">GUI logic scripting</link>.</para>
-</section>
-
-</chapter>
-
-<chapter id="external_plugins">
- <title>External plugins</title>
- <para>As of version 0.5.5, &kapp; provides a comfortable way to install additional third party plugins which do not belong to the core package itself. We call these "external plugins". They come in form of an R package and can be managed directly via the usual package management features of R and/or &kapp;. </para>
- <para>This section of the documentation describes how external plugins are to be packaged, so that &kapp; can use them. The plugin creation itself is of course identical to the previous sections. That is, you should probably first write a working plugin, and then check back here to learn how to distribute it. </para>
- <para>Since external plugins are a relatively young feature, details of this might probably change in future releases. You’re welcome to contribute your ideas to improve the process. </para>
- <para><emphasis>Note:</emphasis> These docs explain the details of external plugins so you can learn how they work. In addition to that, also have a look at the <link linkend="rkwarddev">"rkwarddev" package</link>, which was designed to automate a lot of the writing process. </para>
-
- <section id="why_external_plugins">
- <title>Why external plugins?</title>
- <para>The number of packages to extend the functionality of R is immense already, and climbing. On one hand, we want to encourage you to write plugins for even the most specialised tasks you need solved. On the other hand, the average user should not get lost in huge menu trees full of unknown statistical terms. Therefore it seemed reasonable to keep the plugin handling in &kapp; quite modular as well. </para>
- <para>As a rule of thumb, plugins that seem to serve a widely used purpose (e.g. t-Tests) should become part of the core package, while those who serve a rather limited group of people with special interests should be provided as an optional package. For you as a plugin author it’s best practice to just start with an external plugin. </para>
- </section>
-
- <section id="structure_of_a_plugin_package">
- <title>Structure of a plugin package</title>
- <para>For external plugins to install and work properly, they must follow some structural guidelines regarding their file hierarchy. </para>
-
- <section id="file_hierarchy"><title>File hierarchy</title>
- <para>Lets have a look at the prototypic file hierarchy of an elaborate plugin archive. You don’t have to include all of these directories and/or files for a plugin to work (read on to learn what’s absolutely necessary), consider this a "best practice" example: </para>
- <programlisting>
- plugin_name/
- inst/
- rkward/
- plugins/
- plugin_name.xml
- plugin_name.js
- plugin_name.rkh
- ...
- tests/
- testsuite_name/
- RKTestStandards.sometest_name.rkcommands.R
- RKTestStandards.sometest_name.rkout
- ...
- testsuite.R
- plugin_name.pluginmap
- ...
- ChangeLog
- README
- AUTHORS
- LICENSE
- DESCRIPTION
- </programlisting>
- <para><emphasis>Note:</emphasis> In this example, all occasions of "plugin_name", "testsuite_name" and "sometest_name" are to be replaced with their correct names, accordingly. You also don't have to create this file hierarchy by hand. If you use the function <code>rk.plugin.skeleton()</code> from the <link linkend="rkwarddev">"rkwarddev" package</link>, it will automatically create all necessary files and directories for you.</para>
- <section id="basic_plugin_components">
- <title>Basic plugin components</title>
- <para>It is mandatory to include at least three files: a .pluginmap, a plugin .xml description and a plugin .js file. That is, even the "plugins" directory is optional. It might just help to give your files some order, especially if you include more that one plugin/dialog in the archive, which is of course no problem. You can have as many directories for the actual plugin files as you see fit, they just have to resemble the .pluginmap, respectively. It is also possible to even include several .pluginmap files, if it fits your needs, but you should include them all in "plugin_name.pluginmap" then. </para>
- <para>Each R package must have a valid DESCRIPTION file, which is also crucial for &kapp; recognizing it as a plugin provider. Most of the information it carries is also needed in the plugin <link linkend="meta-information">Meta-information</link>, but in a different format (the R documentation explains <ulink url="http://cran.r-project.org/doc/manuals/R-exts.html#The-DESCRIPTION-file">the DESCRIPTION file in detail</ulink>).</para>
- <para>In addition to the general contents of a DESCRIPTIONS file, make sure to also include the line "Enhances: rkward". This will cause &kapp; to automatically scan the package for plugins if it is installed. An example DESCRIPTION file looks like this:</para>
- <programlisting>
- Package: SquaretheCircle
- Type: Package
- Title: Square the circle
- Version: 0.1-3
- Date: 2011-09-19
- Author: E.A. Dölle <doelle at eternalwondermaths.example.org>
- Maintainer: A. Assistant <alterego at eternalwondermaths.example.org>
- Enhances: rkward
- Description: Squares the circle using Heisenberg compensation.
- License: GPL
- LazyLoad: yes
- URL: http://eternalwondermaths.example.org/23/stc.html
- Authors at R: c(person(given="E.A.", family="Dölle", role="aut",
- email="doelle at eternalwondermaths.example.org"),
- person(given="A.", family="Assistant", role=c("cre",
- "ctb"), email="alterego at eternalwondermaths.example.org"))
- </programlisting>
- <para><emphasis>Note:</emphasis> You don't have to write this file by hand. If you use the function <code>rk.plugin.skeleton()</code> from the <link linkend="rkwarddev">"rkwarddev" package</link> and provide all necessary information via the "about" option, it will automatically create a working DESCRIPTION file for you.</para>
-
- </section>
- <section id="additional_information">
- <title>Additional information (optional)</title>
- <para>ChangeLog, README, AUTHORS, LICENSE should be self-explaining and are entirely optional. Actually, they won’t be interpreted by &kapp;, so they are rather meant to carry additional information that might be relevant e.g. for distributors. Most of their relevant content (author credits, licence terms etc.) will be included in the actual plugin files anyway, though (see the section on meta-information below). Note that all of these files could also be placed somewhere in the "inst" directory, if you want them not only to be present in the source archive but the installed package as well. </para>
- </section>
- <section id="automated_plugin_testing">
- <title>Automated plugin testing (optional)</title>
- <para>Another optional directory is "tests", which is meant to provide files needed for automated plugin testing. These tests are helpful to quickly check if your plugins still work with new versions of R or &kapp;. If you want to include tests, you should really restrain yourself to the naming scheme and hierarchy shown here. That is, tests should reside in a directory called "tests", which includes a file "testsuite.R" and a folder with tests standards named after the appropriate test suite. You can, however, provide more than one test suite; in that case, if you don’t want to append them all in the one "testsuite.R" file, you can split them in e.g. one file for each test suite and create one "testsuite.R" with "source()" calls for each suite file. In either case, create separate subdirectories with test standards for each defined suite. </para>
- <para>The benefits of upholding to this structure is that plugin tests can be run simply by calling "rktests.makplugintests()" from the tests directory without additional arguments. </para>
- </section>
- </section>
- </section>
-
- <section id="meta-information">
- <title>Meta-information</title>
- <para>Each plugin archive should provide some basic meta information on what it deals with, where to find more information, who maintains it, if it relies on specific R packages or other plugins, etc. </para>
- <para>This information is given at least once in your .pluginmap, and can then be included or overwritten in each plugin .xml file (which might be useful if that particular plugin file was contributed by someone else, for instance). </para>
- <para>To achieve this, the <about> tag is used. The overall structure of this tag looks something like this: </para>
- <programlisting>
- <about>
- <author />
- <author />
- ...
- <dependencies>
- <package />
- <package />
- ...
- <pluginmap />
- <pluginmap />
- ...
- </dependencies>
- </about>
- </programlisting>
- <para>That is, the <about> tag contains <author> and <dependencies>, and <dependencies> contains <package> and <pluginmap>. Each of these five tags knows in turn several further attributes (see below). </para>
- <para>As you can see, you can have more than one entry on authors, needed R packages and &kapp; pluginmaps. </para>
- <para>A full-blown example would look like this: </para>
- <programlisting>
-<document
- namespace="rkward"
- id="SquaretheCircle_rkward"
->
- <about
- name="Square the Circle"
- shortinfo="Squares the circle using Heisenberg compensation."
- version="0.1-3"
- releasedate="2011-09-19"
- url="http://eternalwondermaths.example.org/23/stc.html"
- license="GPL"
- category="Geometry"
- >
- <author
- given="E.A."
- family="Dölle"
- email="doelle at eternalwondermaths.example.org"
- role="aut"
- />
- <author
- given="A."
- family="Assistant"
- email="alterego at eternalwondermaths.example.org"
- role="cre, ctb"
- />
- <dependencies
- rkward_min_version="0.5.3"
- R_min_verion="2.10"
- >
- <package
- name="heisenberg"
- min_version="0.11-2"
- repository="http://rforge.r-project.org"
- />
- <package
- name="DreamsOfPi"
- min_version="0.2"
- />
- <pluginmap
- name="heisenberg.pluginmap"
- url="http://eternalwondermaths.example.org/hsb"
- />
- </dependencies>
- </about>
- <components>
- <component
- type="standard"
- id="SquaretheCircle.SquaretheCircle"
- file="plugins/SquaretheCircle.xml"
- label="SquaretheCircle"
- />
- </components>
- <hierarchy>
- <menu
- id="analysis"
- label="Analysis"
- >
- <menu
- id="menu_SquaretheCircle.SquaretheCircle"
- label="Square the Circle"
- >
- <entry component="SquaretheCircle.SquaretheCircle" />
- </menu>
- </menu>
- </hierarchy>
-</document>
- </programlisting>
- <para><emphasis>Note:</emphasis> You don't have to write this XML code by hand. If you use the function <code>rk.plugin.skeleton()</code> from the <link linkend="rkwarddev">"rkwarddev" package</link> and provide all necessary information via the "about" option, it will automatically create a .pluginmap file with a working <about> section for you.</para>
- <para>Most of this should explain itself, so we’ll not discuss each and every tag element. But let’s look at some details that probably need some commentary for easier understanding. </para>
- <para>The "category" element in <about> can be defined rather freely, but should be meaningful, as it’s thought to be used to order plugins into groups. All other attributes in this opening tag are mandatory and must be filled with reasonable content. </para>
- <para>At least one <author> with a valid e-mail address and the role "aut" ("author") must also be given. In case your plugin causes problems or someone would like to share its gratitude with you, it should be easy to contact someone who’s involved. For further information on other valid roles, like "ctb" for code contributors or "cre" for package maintenance, please refer to the <ulink url="http://stat.ethz.ch/R-manual/R-patched/library/utils/html/person.html">R documentation on <code>person()</code></ulink>. </para>
- <para>Actually the whole <dependencies> might be left empty if your plugin is supposed to run with any &kapp; version and standard R installation. But please be reasonable here as well. The inclusion of any <package> or <pluginmap> tags is of course optional as well, depending on the needs of your plugins. All the "min_version" and "max_version" information can be omitted, as well. They are obviously useful if your plugin is known to rely on certain versions of an R package, for instance. </para>
- <para>If you need an R package that is probably not hosted on an official CRAN mirror, you can specify a repository where it can be found in the <package> tag. &kapp; will check whether this repository is already defined in its configuration, and if not, add it, but only after the user has given its explicit permission to that. </para>
- <para>The "id" element in the <pluginmap> tag refers to the ID given in the top level <document> tag of the pluginmap that you need. </para>
- </section>
- <section id="building_the_plugin_package">
- <title>Building the plugin package</title>
- <para>As explained earlier, external RKWard plugins are in effect R packages, and therefore the packaging process is identical. In contrast to "real" R packages, a pure plugin package doesn't carry any further R code (although you can of course add RKWard plugins to usual R packages as well, using the same methods explained here). This should make it even easier to create a functioning package, as long as you have a valid DESCRIPTION file and adhere to the file hierarchy explained in previous sections.</para>
- <para>The easiest way to actually build and test your plugin is to use the <code>R</code> command on the command line, for example:</para>
- <programlisting>
- R CMD build SquaretheCircle
- R CMD INSTALL SquaretheCircle_0.1-3.tar.gz
- </programlisting>
- </section>
-</chapter>
-
-<chapter id="rkwarddev">
- <title>Plugin development with the "rkwarddev" package</title>
- <para>Writing external plugins involves writing files in three languages (XML, JavaScript and R) and the creation of a standardized hierarchy of directories. To make this a lot easier for willing plugin developers, we're providing the "rkwarddev" package. It provides a number of simple R functions to create the XML code for most dialog elements like tabbooks, checkboxes, dropdownlists or filebrowsers, as well as functions to create JavaScript code and RKWard help files to start with. The function <code>rk.plugin.skeleton()</code> creates the expected directory tree and all necessary files where they are supposed to be.</para>
- <para>This package is not installed by default, but has to be installed manually from <ulink url="http://rkward.sourceforge.net/R/">RKWard's own repository</ulink>. You can either do that by using the GUI interface (Settings -> Configure packages), or from any running R session:</para>
- <programlisting>
- install.packages("rkwarddev", repos="http://rkward.sf.net/R")
- library(rkwarddev)
- </programlisting>
- <para>The full <ulink url="http://rkward.sourceforge.net/R/pckg/rkwarddev/rkwarddev.pdf">documentation in PDF format</ulink> can also be found there.</para>
-</chapter>
-
-<appendix id="reference">
-<title>Reference</title>
-
-<section id="propertytypes"><title>Types of properties / Modifiers</title>
-<para>
-At some places in this introduction we've talked about "properties" of GUI elements or otherwise. In fact there are several different types of properties. Usually you do not need to worry about this, as you can use common sense to connect any property to any other property. However, internally, there are different types of properties. What this matters for, is when fetching some special values in the JS-template. In getValue ("id") statements you can also specify some so called "modifiers" like this: getValue ("id.modifier"). This modifier will affect, in which way the value is printed. Read on for the list of properties, and the modifiers they each make available:
-</para>
-<variablelist>
-<varlistentry>
-<term>String properties</term>
-<listitem>The most simple type of property, used to simply hold a piece of text. It does not provide any modifiers. If you attempt to fetch modified values from the JS template, it will return the usual value, and a warning will be written to the terminal you're running rkward from.</listitem>
-</varlistentry>
-<varlistentry>
-<term>Boolean properties</term>
-<listitem>Properties that can either be on or off, true or false. For instance the properties created by <convert>-tags, also the property accompanying a <checkbox> (see below). The following values will be returned according to the given modifier:
- <variablelist>
- <varlistentry>
- <term>No modifier ("")</term>
- <listitem>By default the property will return the string "TRUE", if it is true, and "FALSE" otherwise. Boolean properties attached to a checkbox behave slightly differently, and return the strings you specified in the "value" and "value_unchecked" attributes.</listitem>
- </varlistentry>
- <varlistentry>
- <term>"true"</term>
- <listitem>Return the string as if the property was true, even if it is false</listitem>
- </varlistentry>
- <varlistentry>
- <term>"false"</term>
- <listitem>Return the string as if the property was false, even if it is true</listitem>
- </varlistentry>
- <varlistentry>
- <term>"not"</term>
- <listitem>This actually returns another Boolean property, which is the reverse of the current (i.e. false if true, true if false)</listitem>
- </varlistentry>
- <varlistentry>
- <term>"numeric"</term>
- <listitem>Return the string "1" if the property is true, or "0" if it is false</listitem>
- </varlistentry>
- </variablelist></listitem>
-</varlistentry>
-<varlistentry>
-<term>Integer properties</term>
-<listitem>A property designed to hold an integer value (but of course it still returns a numeric character string to the JS-template). It does not accept any modifiers. Used in <spinbox>es (see below)</listitem>
-</varlistentry>
-<varlistentry>
-<term>Real number properties</term>
-<listitem>A property designed to hold a real number value (but of course it still returns a numeric character string to the JS-template). It does not accept any modifiers. Used in <spinbox>es (see below)</listitem>
-</varlistentry>
-<varlistentry>
-<term>RObject properties</term>
-<listitem>A property designed a selection of one or more R objects. Used most porminently in varselectors and varslots. The following values will be returned according to the given modifier:
- <variablelist>
- <varlistentry>
- <term>No modifier ("")</term>
- <listitem>By default the property will the full name of the selected object. If more than one object is selected, the object names will be separated by line breaks ("\n").</listitem>
- </varlistentry>
- <varlistentry>
- <term>"shortname"</term>
- <listitem>Like above, but returns only short name(s) for the object(s). For instance an object inside a list would only be given the name it has inside the list, without the name of the list.</listitem>
- </varlistentry>
- <varlistentry>
- <term>"label"</term>
- <listitem>Like above, but returns the &kapp; label(s) of the object(s) (if no label availabe, this is the same as shortname)</listitem>
- </varlistentry>
- </variablelist></listitem>
-</varlistentry>
-<varlistentry>
-<term>Code properties</term>
-<listitem>A property held by plugins that generated code. This is important for embedding plugins, in order to embed the code generated by the embedded plugin into the code generated by the embedding (top-level) plugin. The following values will be returned according to the given modifier:
- <variablelist>
- <varlistentry>
- <term>No modifier ("")</term>
- <listitem>Returns the full code, i.e. the sections "preprocess", "calculate", "printout", and (but not "preview") concatenated to one string.</listitem>
- </varlistentry>
- <varlistentry>
- <term>"preprocess"</term>
- <listitem>Returns only the preprocess section of the code</listitem>
- </varlistentry>
- <varlistentry>
- <term>"calculate"</term>
- <listitem>Returns only the calculate section of the code</listitem>
- </varlistentry>
- <varlistentry>
- <term>"printout"</term>
- <listitem>Returns only the printout section of the code</listitem>
- </varlistentry>
- <varlistentry>
- <term>"preview"</term>
- <listitem>Returns the preview section of the code</listitem>
- </varlistentry>
- </variablelist></listitem>
-</varlistentry>
-</variablelist>
-</section>
-
-<section id="globalxmlelements">
- <title>General purpose elements to be used in any XML file (.xml, .rkh, .pluginmap)</title>
- <variablelist>
- <varlistentry>
- <term><snippets></term>
- <listitem>Allowed as a direct child of the <document> node and only there. Should be placed near the top of the file. See <link linkend="snippets">section on using snippets</link>. Only one <snippets> element may be present. Optional, no attributes.</listitem>
- </varlistentry>
- <varlistentry>
- <term><snippet></term>
- <listitem>Defines a single snippet. Allowed only as a direct child of the <snippets/> element. Attributes:
- <variablelist>
- <varlistentry>
- <term><id></term>
- <listitem>An identifier string for the snippet. Required.</listitem>
- </varlistentry>
- </variablelist></listitem>
- </varlistentry>
- <varlistentry>
- <term><insert></term>
- <listitem>Insert the contents of a <snippet>. Allowed anywhere. Attributes:
- <variablelist>
- <varlistentry>
- <term><snippet></term>
- <listitem>The identifier string of the snippet to insert. Required.</listitem>
- </varlistentry>
- </variablelist></listitem>
- </varlistentry>
- <varlistentry>
- <term><include></term>
- <listitem>Include the contents of another xml file (everything inside the <document> element of that file). Allowed anywhere. Attributes:
- <variablelist>
- <varlistentry>
- <term><file></term>
- <listitem>The filename, relative to the directory, the current file is in. Required.</listitem>
- </varlistentry>
- </variablelist></listitem>
- </varlistentry>
- </variablelist>
-</section>
-
-<section id="xmlelements"><title>Elements to be used in the XML description of the plugin</title>
-<para>Properties held by the elements are listed in a <link linkend="elementproperties">separate section</link>.</para>
-
-<section id="generalelements"><title>General elements</title>
-<variablelist>
-<varlistentry>
-<term><document></term>
-<listitem>Needs to be present in each description.xml-file as the root-node. No special function. No attributes</listitem>
-</varlistentry>
-<varlistentry>
-<term><code></term>
-<listitem>Defines where to look for the JS template to the plugin. Use only once per file, as a direct child of the document-tag. Attributes:
- <variablelist>
- <varlistentry>
- <term><file></term>
- <listitem>Filename of the JS template, relative to the directory the plugin-xml is in</listitem>
- </varlistentry>
- </variablelist></listitem>
-</varlistentry>
-<varlistentry>
-<term><help></term>
-<listitem>Defines where to look for the help file for the plugin. Use only once per file, as a direct child of the document-tag. Attributes:
- <variablelist>
- <varlistentry>
- <term><file></term>
- <listitem>Filename of the help file, relative to the directory the plugin-xml is in</listitem>
- </varlistentry>
- </variablelist></listitem>
-</varlistentry>
-<varlistentry>
-<term><copy></term>
-<listitem>Can be used as a child (direct or indirect) of the main layout elements, i.e. <dialog> and <wizard>. This is used to copy an entire block a xml elements 1:1. Attributes:
- <variablelist>
- <varlistentry>
- <term><id></term>
- <listitem>The id to look for. The <copy> tag will look for a previous XML element that has been given the same id, and copy it including all descendent elements.</listitem>
- </varlistentry>
- <varlistentry>
- <term><copy_element_tag_name></term>
- <listitem>In some few cases, you will want an almost literal copy, but change the tag-name of the element to copy. The most important example of this is, when you want to copy an entire <tab> from a dialog interface to the <page> of a wizard interface. In this case, you'd set coyp_elemnent_tag_name="page" to do this conversion automatically.</listitem>
- </varlistentry>
- </variablelist></listitem>
-</varlistentry>
-</variablelist>
-</section>
-
-<section id="interfaceelements"><title>Interface definitions</title>
-<variablelist>
-<varlistentry>
-<term><dialog></term>
-<listitem>Defines a dialog-type interface. Place the GUI-definition inside this tag. Use only once per file, as a direct child of the document-tag. At least one of "dialog" or "wizard" tags is required for a plugin. Attributes:
- <variablelist>
- <varlistentry>
- <term><label></term>
- <listitem>Caption for the dialog</listitem>
- </varlistentry>
- </variablelist></listitem>
-</varlistentry>
-<varlistentry>
-<term><wizard></term>
-<listitem>Defines a wizard-type interface. Place the GUI-definition inside this tag. Use only once per file, as a direct child of the document-tag. At least one of "dialog" or "wizard" tags is required for a plugin. Accepts only <page> or <embed>-tags as direct children. Attributes:
- <variablelist>
- <varlistentry>
- <term><label></term>
- <listitem>Caption for the wizard</listitem>
- </varlistentry>
- </variablelist></listitem>
-</varlistentry>
-</variablelist>
-</section>
-
-<section id="layoutelements"><title>Layout elements</title>
-<para>All elements in this section accept an attribute id="identifierstring". This attribute is optional for all elements. It can be used, for example, to hide/disable the entire layout element and all the elements contained therein (see <link linkend="logic">chaper GUI logic</link>). The id-string may not contain "." (dot) or ";" (semicolon), and should generally be limited to alphanumeric characters and the underscore ("_"). Only the additional attributes are listed.</para>
-<variablelist>
-<varlistentry>
-<term><page></term>
-<listitem>Defines a new page inside a wizard. Only allowed as a direct child of a <wizard> element.</listitem>
-</varlistentry>
-<varlistentry>
-<term><row></term>
-<listitem>All direct children of a "row" tag will be placed left-to-right.</listitem>
-</varlistentry>
-<varlistentry>
-<term><column></term>
-<listitem>All direct children of a "column" tag will be placed top-to-bottom.</listitem>
-</varlistentry>
-<varlistentry>
-<term><stretch></term>
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list