R Gui Rkward
R Gui Rkward
R Gui Rkward
RKWard: A Comprehensive Graphical User Interface and Integrated Development Environment for Statistical Analysis with R
Stefan R odiger
Charit e-Universit atsmedizin Berlin
Thomas Friedrichsmeier
Ruhr-University Bochum
Prasenjit Kapat
The Ohio State University
Meik Michalke
Heinrich Heine University D usseldorf
Abstract R is a free open-source implementation of the S statistical computing language and programming environment. The current status of R is a command line driven interface with no advanced cross-platform graphical user interface (GUI), but it includes tools for building such. Over the past years, proprietary and non-proprietary GUI solutions have emerged, based on internal or external tool kits, with dierent scopes and technological concepts. For example, Rgui.exe and Rgui.app have become the de facto GUI on the Microsoft Windows and Mac OS X platforms, respectively, for most users. In this paper we discuss RKWard which aims to be both a comprehensive GUI and an integrated development environment for R. RKWard is based on the KDE software libraries. Statistical procedures and plots are implemented using an extendable plugin architecture based on ECMAScript (JavaScript), R, and XML. RKWard provides an excellent tool to manage dierent types of data objects; even allowing for seamless editing of certain types. The objective of RKWard is to provide a portable and extensible R interface for both basic and advanced statistical and graphical analysis, while not compromising on exibility and modularity of the R programming environment itself.
develop an S-like language without inheriting memory and performance issues. The source code of R was nally released in 1995, and since 1997 development has evolved under the umbrella of the R Development Core Team (R Development Core Team 2001, 2012a; Ihaka 1998). R does not include an advanced cross-platform graphical user interface (GUI) as known from other statistical software packages. However, R includes tools for building GUIs mainly based on Tcl/Tk (Dalgaard 2001, 2002). Meanwhile a plethora of R GUIs have emerged (see Grosjean 2010, for a comprehensive list). In 2005 John Fox released version 1.0 of R Commander (Fox 2005, package Rcmdr), which can be considered a milestone in R GUI development; it was the rst GUI implementation that was able to make statistical tests, plots and data manipulation easily accessible for R novices. John Fox stated that Rcmdrs target was to provide functionality for basic-statistical courses, though the features have increased over time beyond this (Fox 2005, 2007). In November 2002 Thomas Friedrichsmeier started the RKWard open-source software project with the goal to create a GUI for R based on KDE (KDE e.V. 2012) and Qt (Nokia Corporation 2012) technologies 1 . The scope of RKWard is deliberately broad, targeting both R novices and experts. For the rst group, the aim is to allow any person with knowledge on statistical procedures to start using RKWard for their everyday work without having to learn anything about the R programming language, at least initially. At the same time, RKWard tries to support users who want to learn and exploit the full exibility of the R language for automating or customizing an analysis. At the other end of the learning curve, RKWard provides advanced integrated development environment (IDE) features to R experts to assist in writing R scripts. Yet, the idea is that R experts too will benet from the availability of task-oriented GUI dialogs, such as when exploring an unfamiliar type of analysis or by allowing to implement routinely performed tasks as a GUI element. In addition, many features like the integrated data editor and the plot preview will be useful to R novices and R experts alike in their everyday work (see Section 3). RKWard provides a high level of transparency about the steps that are needed to perform any supported task in R, in order to make it easy for the user to see complete codes for all GUI actions2 . In doing so, RKWard deliberately generates comparatively verbose code. It avoids wrapping complex sequences of data manipulation or analysis into custom highlevel R functions. The task of providing high-level functions is logically independent of the development of the GUI frontend, and should best be addressed in dedicated R packages, where necessary. This approach allows to make better use of the modular design of R, avoids lockingin users to a specic GUI application, and provides them with more options for customizing the generated code patterns. While RKWard tries to address users wishing to learn R, it is specically not designed as a teaching tool such as Rcmdr (Fox 2005) or TeachingDemos (Snow 2012) but as a productive tool. Since its incarnation RKWard has gained acceptance for usage in peerreviewed publications (Zou and Tolstikov 2008, 2009; Rugg-Gunn, Cox, Ralston, and Rossant
KDE is a desktop environment and software collection based on Qt. In the context of this paper, the term KDE is primarily used to refer to the programming library and runtime environment of KDE, rather than the complete software collection. For an introduction to KDE as a programming library, see Faure (2000). Qt is a C++-based cross-platform programming library with a focus on GUI development. For an introduction to programming with Qt, see Blanchette and Summereld (2008). 2 This distinguishes RKWard from R GUIs such as Red-R (Parikh and Covington 2010), which specically aims to hide the complexities of the R programming language, following the concept of visual data-ow programming (Sutherland 1966). In contrast, RKWard limits itself to generate R code from GUI settings.
1
End of 2002: Project starts Conceptual draft Low development efforts Development stopped after 0.1.0 release
End of 2005 Packages for major distributions (e.g. Debian, Fedora) Basic statistical tests available as plugins Addition of R console emulation and syntax highlighting
End of 2009: close Qt3 branch No further feature inclusion Supported up to R 2.11.1 Support ended with R 2.12.0
August 2004: Alpha Stage Development resumed R engine running in a thread Support for multiple data.frames Two developers
2006: Accelerated Development Growing productive user base Inclusion of many plugins by external developers First localizations
2009: Porting to KDE4 & Qt4 Porting to KDE4 and Qt4 Qt3 branch continues to be maintained but no new features included Qt4 branch stabilized, and initial port to MS Windows platform
2010: Qt4 branch and new features Move from PHP to JavaScript back-end Stable running port on MS Windows platforms Proof of concept on Mac OS X New features (e.g. plot history) More options to script complex plugins
Years
Figure 1: Timeline of important development milestones and changes in RKWard. Time is presented on an arbitrary scale. Here Qt3 and Qt4 refers to the 3.x and 4.x versions of the Qt libraries, respectively and KDE4 refers to the 4.x version of the KDE libraries.
2010; Yang, Liu, Liu, Qian, Zhang, and Hu 2011; R odiger et al. 2011, 2012). Dialogs for statistical procedures in RKWard do not necessarily show a one-to-one correspondence to the underlying steps in R, but are rather oriented at statistical tasks. Furthermore, RKWard does not impose articial limitations on how users can work with the application. For example, the user is not limited to using only one data.frame or one model at a time. RKWard is designed to allow users to create custom GUI dialogs as plugins, requiring relatively little programming knowledge. In essence, RKWard plugins consist of an XML le describing the dialog layout, and ECMAScript code which generates R code from the settings made in the GUI. Most of the data handling functionality in RKWard is implemented as plugins (see Section 3.5), and many of these plugins have originated as user contributions. Since version 0.5.5, RKWard also provides support for downloading user contributed plugin packs, which are not included in the ocial RKWard releases. Details on the denition of plugins, and a commented example can be found in the technical appendix of this article. RKWard is licensed under the terms of the GNU General Public License Version 2 or higher. However, due to its dependencies, RKWard binaries are eectively distributable only under the terms of Version 2 of the license. Parts of the documentation are available under the GNU Free Documentation License. Full terms and explanations of both licenses are available at http://www.gnu.org/licenses/gpl.html and http://www.gnu.org/licenses/fdl.html, respectively. While the project remains in constant development, a growing number of users employs RKWard in productive scenarios. The source code, selected binaries and documentation is hosted at SourceForge (http://rkward.sourceforge.net/). Selected key milestones of the development of RKWard are visualized in Figure 1. In this paper we will give an overview over the installation process (Section 2), the main GUI elements and features of RKWard (Section 3), and closing by a short example of a simple RKWard session (Section 4). For readers interested in the technical design, and reasons for certain design decisions, a technical appendix of this article is available.
many hours to complete on current systems. Further, RKWards graphics device window related features (see Section 3.6) are only available when compiling and using KDE and RKWard in X11 mode. In conclusion, RKWard on Mac OS X is not suitable for most users in its current state.
Figure 2: Default RKWard main window after start up. (A) Menu bar and toolbar, (B) tool panel showing workspace browser, (C) document view area, showing dierent documents (welcome message, data.frame my.data, mean help page, R script demo.R), (D) tool panel showing embedded R console, and (E) status bar with an option to stop running processes. Panels B and D can be resized or collapsed. The red border around B indicates that the workspace browser is the active interface element. Users can also detach all types of document windows and tool windows from the main application window, which will then appear as independent windows, managed by the window manager, or re-attach them to the main window. This is to allow users to take advantage of an SDI (single-document interface), where useful, such as the ability to view any two documents side-by-side, or to make better use of multiple displays. On-screen graphics device windows are created detached by default, but can be attached to the document view area of the main window. Windows can be selected (or shown / hidden) using a mouse device with point & click, as well as using a series of keyboard shortcuts (dened by default) for activating specic tool windows, or for cycling through all windows in the order of most recent usage6 . All key bindings can be congured from the GUI via SettingsConfigure Shortcuts. However, for technical reasons only the shortcuts of currently active components will be listed. Thus, for example, to congure data editor shortcuts, one has to open a data editor rst and then to select SettingsConfigure Shortcuts. Since RKWard relies on the RKWard
This uses the shortcut Ctrl+Tab by default, and behaves similar to the Alt+Tab feature of common window managers. The dierence is that this cycles through RKWard windows, only, including both detached windows, and windows which are attached inside the main application window.
6
editor component, shortcuts for the script editor (Section 3.2) are managed separately via SettingsConfigure EditorShortcuts. On most systems, it is also possible to congure shortcuts by right-clicking on the respective menu item. The choice of available actions on the toolbar can be congured via SettingsConfigure Toolbars. Further, it is possible to add and remove sets of data manipulation and analysis features from the GUI, using SettingsConfigure RKWardPlugins.
Figure 3: Code hinting features of the script editor. The script editor is able to hint (A) R object names and (B) function arguments.
Figure 4: Paste special dialog. This tool allows to paste data (e.g., tabular, text) from the clipboard, directly to an R script and therefore accelerates the work process with data from dierent sources like spreadsheet applications. saves snapshots of the currently edited les at congurable intervals. For interaction with R, the editor has predened shortcuts (and toolbar icons) for submitting the current line, the current selection, predened blocks, or the entire document to the R engine for evaluation. It also oers object name completion and function argument hinting (Figure 3A and B) based on the objects present in the R workspace8 . A further feature specic to the R language is the Paste Special action, which allows to paste the clipboard content (e.g., from a separate spreadsheet application) as a single string, vector, or matrix, suitable for inclusion in an R script, optionally transforming it in advance (Figure 4). Script editor windows can be created by opening an existing R script le from the le browser or the File menu. It can also be invoked from R, e.g., using the file.edit(), file.show(), or fix() commands.
Figure 5: RKWard with several data.frames in use at the same time. (A) One data.frame (CO2 data of the datasets package) is opened for editing in the main window. Two further data.frames are opened in the background in tabs. (B) Another data.frame (ChickWeight) is opened in a detached window. (C) Rs standard data editing features (e.g., fix(), edit()) are also usable in RKWard. In this example fix(DNase) was invoked from the console (arrow). of R running in a console session, not a real R session. This leads to a few subtle dierences, e.g., with respect to the command history feature in R. However, for most purposes RKWards R console can be used exactly like R running in a terminal. Adding to that, it provides many of the features which are also available in the code editor (see Section 3.2). Most prominently, it supports syntax highlighting, code folding, function argument hinting, object name completion, and pasting vector or matrix data directly from the clipboard. By default, any code that is submitted to the R engine from the code editor or from help pages, is sent through the R console. However, it can be congured to be submitted in the background, instead.
10
Metadata on each column of a data.frame (i.e., name of the column, data type, and potentially data labels) is shown in the upper portion of the data editor, and can be manipulated there, while the data itself is shown in the lower portion. The upper portion can be hidden using a slider, to save space for the display and editing of actual data. Similarly, an editable column showing the row names of the data.frame can be shown or hidden separately from the data. For columns of type factor, factor levels can be edited by double-clicking on the Levels row of the meta information. Levels can also be assigned to other types of variables, but only for consecutive integer values. These levels will be displayed instead of the underlying value, if applicable. Each column can also be assigned an arbitrary descriptive Label, which is stored in R as an attribute of the column. Contrary to many other editors, the data editor in RKWard does not automatically convert data types of columns. For instance, if a non-numeric string is entered into a cell of a numeric column, the data type of the column remains numeric, and the entered value is highlighted in red. Internally, the invalid cell is set to NA. The entered value is stored separately, in an attribute of the column. The rationale for this approach is that it oers protection against accidental, and probably undetected, conversion of data types. The user can manually convert the storage mode of a column by simply selecting a dierent data type in the Type row of the meta information. The data editor supports insertion and deletion of rows or columns at arbitrary positions. Rows (columns) can also be added at the bottom (right) by simply entering data into the trailing row (column) shown in gray. Copy & paste is supported, where the area aected by paste operations can optionally be constrained to the selected region, or to the dimensions of the table. The data editor can also be set to read-only mode to examine data objects. In the context of data editing, it is noteworthy that RKWard supports working with multiple objects simultaneously, rather than limiting actions to a single active data.frame, as with e.g., Rcmdr or Deducer (Fellows 2012). Given this non-modal interface design, multiple data editor windows can be opened at once (Figure 5).
11
Figure 6: General data import dialog. Useful defaults for a variety of formats can be set using the Quick Mode selector on the left. Further customizations can be done from the Rows and Columns and Further Options tabs. The code in the bottom area can be copied and used for other purposes. At the time of writing, RKWard provides support for importing SPSS, Stata, and delimited text data. Internally, RKWard relies on standard R functions and the package foreign (Murdoch 2002) for reading these data les. To import CSV data, select FileImport formatImport TextCSV data from the menu. This will open the dialog shown in Figure 6. The central area of this dialog provides options to control the import. The File name eld is highlighted, to indicate that it is required to specify a le before the dialog can proceed. Further options are available from the tabbed pages of the central area. The right-side area is common to all data handling dialogs. Here the Submit button is used to start the import action. It is enabled once all required settings have been made, i.e., in this case, once a le name has been selected. The Close button will close the dialog without taking any action. The bottom area optionally shows the R code corresponding to the current settings which will be run upon pressing the Submit button (see Section 4.1 for generated R code). The code display is hidden by default and can be revealed using the Code button. This generated code display is updated dynamically as the user changes settings, allowing to see the eect of each change instantly. Most data handling functions will produce some output, which is sent to the output window. From there it is possible to repeat the action by clicking on the Run again-link (see Section 3.7).
12
Figure 7: On-screen graphics device window in RKWard. The plot history is available as a drop-down list, allowing to jump directly to a previous plot. In this example, ve dierent plots were performed on the same data set of a random sample (rnorm()). The plot can be exported via DeviceExport as described in Section 4.3.
13
Further, RKWard provides access to dierent plotting functions using GUI dialogs, available from the Plots menu. Wherever appropriate, RKWard supports a plot preview feature. When the Preview box of the respective dialog is checked, a device window is opened, which shows the plot as it would be created with the current settings (see Section 4.3 for an example). The preview is updated automatically as the user makes changes, allowing to see the eect of each setting instantly10 . For example, the central limit theorem plugins under the Distributions menu can be very helpful to dynamically show the convergence in distribution while teaching. For the sake of simplicity, such preview plots are not added to the history.
14
Figure 8: Sample contents of the output window. Upper portion: Result of analyzing sample data (from the DNase and ChickWeight datasets of the datasets package) in the Descriptive Statistics plugin. Standard elements of plugin output include a standardized header, and a Run again-link, which allows to repeat the analysis with identical or similar parameters. Lower portion: A custom heading added using the rk.header() function, and a short transcript of R code with corresponding output. are not properly rendered by older supported versions of the KDE libraries. Users can also add custom content to the output window using rk.header(), rk.print(), and some related functions. Further, custom R code as well as the corresponding R output can easily be documented in the RKWard output window, including syntax highlighting (see the lower portion of Figure 8).
15
existing R packages. The underlying package management technology is that of R (Ligges 2003; Ripley 2005). RKWard supports installing packages to any user writable location. If no current library location is user writable, RKWard oers to create a new one. On Unix systems, interactively acquiring root privileges for installation to the system-wide libraries is also supported. The installation process itself can be monitored at the interface for error tracking. At the time of writing, RKWard has no built-in tools for the interactive exploration of R packages. However, it is possible to invoke external helpers as reported elsewhere (Zhang and Gentleman 2004).
For technical background of RKWard GUI help pages please refer to the technical appendix of this article.
16
The help browser window is based on the KDE HTML viewer component and supports many standard features like increasing or decreasing the font size and searching text within a page. Additionally, R code inside a help page can be sent to the R engine for evaluation by selecting it and pressing F8 (or via RunRun Selection).
Figure 9: (A) CSV import dialog. Useful defaults for a variety of common text separated value formats can be set using the Quick Mode selector on the left. Beyond that, many options can be customized. (B) Data editor. The imported CSV data from experiment.txt are presented (data visually trimmed).
17
Figure 10: Students t test dialog for two variables. The bottom area shows the R code corresponding to the settings.
18
Figure 12: Boxplot dialog. The rst tab Variables is used to select the variables for analysis. It is possible to combine any data present in .GlobalEnv. The second tab Options allows further adjustments (e.g., the addition of mean and standard deviation) to the plot (not shown).
19
Figure 13: Plotted data and plot export dialog. The export dialog (DeviceExport) provides numerous options like resolution and size for dierent vector formats (e.g., SVG, PDF) and pixel formats (e.g., PNG, JPEG). (Note: For the shown gure, the optional mean ( ) and standard deviation (+) parameters were selected in the boxplot plugin.)
Uses standard R formats (see R Development Core Team 2012b) for data storage, and open standards (HTML, PNG, SVG) for storage of output.
Future versions of RKWard will continue to add value for both groups of users. Planned features include an enhanced interface for debugging R code, support for editing more types of data, and the ability to connect the RKWard GUI to a remote R engine. Perhaps most importantly, RKWard will gain many new graphical dialogs for manipulation, analysis, and visualization of data. The ability to develop these dialogs as plugins allows to develop and distribute GUI dialogs independently of the RKWard core application, allowing any user to help in enhancing RKWard, without in-depth programming knowledge.
Acknowledgments
The software RKWard, presented in this paper, is currently developed by Thomas
20
Friedrichsmeier (lead developer), Prasenjit Kapat, Meik Michalke, and Stefan R odiger. Many more people have contributed, or are still contributing to the project in various forms. We would like to thank (in alphabetical order) Adrien dHardemare, Daniele Medri, David Sibai, Detlef Steuer, Germ an M arquez Mej a, Ilias Soumpasis, Jannis Vajen, Marco Martin, Philippe Grosjean, Pierre Ecochard, Ralf Tautenhahn, Roland Vollgraf, Roy Qu, Yves Jacolin, and many more people on rkward-devel@lists.sourceforge.net for their contributions. The rst two authors of this article have contributed equally, and both are available for correspondence pertaining to this article. Questions and comments regarding the software RKWard should be addressed to the projects main mailing list, rkward-devel@lists.sourceforge. net.
References
Blanchette J, Summereld M (2008). C++ GUI Programming with Qt 4. 2nd edition. Prentice Hall. Burnette E (2005). Eclipse IDE Pocket Guide. OReilly Media. Cullmann C (2012). KatePart. URL http://kate-editor.org/about-katepart/. Dalgaard P (2001). A Primer on the R-Tcl/Tk Package. R News, 1(3), 2731. URL http://CRAN.R-project.org/doc/Rnews/. Dalgaard P (2002). Changes to the R-Tcl/Tk Package. R News, 2(3), 2527. URL http: //CRAN.R-project.org/doc/Rnews/. Ettrich M, Taylor O (2002). XEmbed Protocol Specication Version 0.5. URL http:// standards.freedesktop.org/xembed-spec/xembed-spec-latest.html. Faure D (2000). Creating and Using Components (KParts). In D Sweet (ed.), KDE 2.0 Development. Sams, Indianapolis. Fellows I (2012). Deducer: A Data Analysis GUI for R. Journal of Statistical Software, 49(8), 115. URL http://www.jstatsoft.org/v49/i08/. Fox J (2005). The R Commander: A Basic-Statistics Graphical User Interface to R. Journal of Statistical Software, 14(9), 142. URL http://www.jstatsoft.org/v14/i09/. Fox J (2007). Extending the R Commander by Plug-In Packages. R News, 7(3), 4652. URL http://CRAN.R-project.org/doc/Rnews/. Fox J (2008). Editorial. R News, (2), 12. URL http://CRAN.R-project.org/doc/Rnews/. Friedrichsmeier T, Michalke M (2011). Introduction to Writing Plugins for RKWard. URL http://rkward.sourceforge.net/documents/devel/plugins/index.html. Gentleman RC, Carey VJ, Bates DM, Bolstad B, Dettling M, Dudoit S, Ellis B, Gautier L, Ge Y, Gentry J, Hornik K, Hothorn T, Huber W, Iacus S, Irizarry R, Leisch F, Li C, Maechler M, Rossini AJ, Sawitzki G, Smith C, Smyth G, Tierney L, Yang JYH, Zhang
21
J (2004). Bioconductor: Open Software Development for Computational Biology and Bioinformatics. Genome Biology, 5, R80. URL http://genomebiology.com/2004/5/10/ R80. Grosjean P (2010). R GUI Projects. URL http://www.R-project.org/GUI. Haumann D (2010). Kate: Scripted Actions. URL http://kate-editor.org/2010/07/ 09/kate-scripted-actions/. Helbig M, Urbanek S, Fellows I (2011). JGR: Java Gui for R. R Package Version 1.7-9, URL http://CRAN.R-project.org/package=JGR. Hopkins D (2005). HyperTIES Hypermedia Browser and Emacs Authoring Tool for NeWS. URL http://www.donhopkins.com/drupal/node/101. Ihaka R (1998). R: Past and Future History. In S Weisberg (ed.), Proceedings of the 30th Symposium on the Interface, pp. 392396. The Interface Foundation of North America. URL http://CRAN.R-project.org/doc/html/interface98-paper/paper.html. Jarvis S (2010). KDE 4 on Windows. Linux Journal, 2010. KDE eV (2012). About KDE. Berlin. URL http://www.kde.org/community/whatiskde/. KDevelopOrg (2011). KDevelop. URL http://www.kdevelop.org/. Kim J, Lutteroth C (2009). Multi-Platform Document-Oriented GUIs. In G Weber, P Calder (eds.), Tenth Australasian User Interface Conference (AUIC 2009), volume 93 of CRPIT, pp. 3138. ACS, Wellington, New Zealand. URL http://crpit.com/confpapers/ CRPITV93Kim.pdf. KOceOrg (2010). KWord. URL http://www.koffice.org/kword/. Kuhn M (2006). Sweave and the Open Document Format The odfWeave Package. R News, 6(4), 28. URL http://CRAN.R-project.org/doc/Rnews/. Lecoutre E (2003). The R2HTML Package Formatting HTML Output on the Fly or by Using a Template Scheme. R News, 3(3), 3336. URL http://CRAN.R-project.org/ doc/Rnews/. Leisch F (2002). Dynamic Generation of Statistical Reports Using Literate Data Analysis. In W H ardle, B R onz (eds.), COMPSTAT 2002 Proceedings in Computational Statistics, pp. 575580. Physica-Verlag, Heidelberg. Ligges U (2003). R Help Desk: Package Management. R News, 3(3), 3739. URL http: //CRAN.R-project.org/doc/Rnews/. Microsoft Developer Network (2010). Microsoft Developer Network. URL http://msdn2. microsoft.com/en-us/library/ms997505.aspx. Murdoch D (2002). Reading Foreign Files. R News, 2(1), 23. R-project.org/doc/Rnews/. URL http://CRAN.
22
Nokia Corporation (2012). Qt Cross-Platform Application and UI Framework. Oslo. URL http://qt.nokia.com/. Parikh A, Covington KR (2010). Red-R: A Open Source Visual Programming GUI Interface for R. URL http://www.Red-R.org/. Plate T (2009). trackObjs: Track Objects. R package version 0.8-6, URL http://CRAN. R-project.org/package=trackObjs. Raaphorst S (2003). A Usability Inspection of Several Graphical User Interface Toolkits. Technical Report 51222, University of Ottawa. URL http://www.cs.utoronto.ca/~sr/ academic/csi51222paper.pdf. Raelsberger W, Krause Y, Moulinier L, Kieer D, Morand AL, Brino L, Poch O (2008). RReportGenerator: Automatic Reports from Routine Statistical Analysis Using R. Bioinformatics, 24(2), 276278. R Development Core Team (2001). What is R? R News, (1), 23. URL http://CRAN. R-project.org/doc/Rnews/. R Development Core Team (2012a). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. ISBN 3-900051-07-0, URL http://www.R-project.org/. R Development Core Team (2012b). R Data Import/Export. R Foundation for Statistical Computing, Vienna, Austria. ISBN 3-900051-10-0, URL http://www.R-project.org/. R Development Core Team (2012c). R Internals. R Foundation for Statistical Computing, Vienna, Austria. ISBN 3-900051-14-3. R Development Core Team (2012d). Writing R Extensions. R Foundation for Statistical Computing, Vienna, Austria. ISBN 3-900051-11-9. Ripley BD (2004). Lazy Loading and Packages in R 2.0.0. R News, 4(2), 24. URL http://CRAN.R-project.org/doc/Rnews/. Ripley BD (2005). Packages and Their Management in R 2.1.0. R News, 5(1), 811. URL http://CRAN.R-project.org/doc/Rnews/. R odiger S, Ruhland M, Schmidt C, Schr oder C, Grossmann K, B ohm A, Nitschke J, Berger I, Schimke I, Schierack P (2011). Fluorescence Dye Adsorption Assay to Quantify Carboxyl Groups on the Surface of Poly(methyl methacrylate) Microbeads. Analytical Chemistry, 83(9), 33793385. R odiger S, Schierack P, B ohm A, Nitschke J, Berger I, Fr ommel U, Schmidt C, Ruhland M, Schimke I, Roggenbuck D, Lehmann W, Schr oder C (2012). A Highly Versatile Microscope Imaging Technology Platform for the Multiplex Real-Time Detection of Biomolecules and Autoimmune Antibodies. Advances in Biochemical Bioengineering/Biotechnology. Rugg-Gunn PJ, Cox BJ, Ralston A, Rossant J (2010). Distinct Histone Modications in Stem Cell Lines and Tissue Lineages from the Early Mouse Embryo. Proceedings of the National Academy of Sciences, 107(24), 1078310790.
23
Sarkar D (2008). lattice: Multivariate Data Visualization with R. Springer-Verlag, New York. URL http://lmdvr.R-Forge.R-project.org/. Snow G (2012). TeachingDemos: Demonstrations for Teaching and Learning. R package version 2.8, URL http://CRAN.R-project.org/package=TeachingDemos. Sutherland WR (1966). The On-line Graphical Specication of Computer Procedures. Ph.D. thesis, MIT. URL http://hdl.handle.net/1721.1/13474. Visne I, Dilaveroglu E, Vierlinger K, Lauss M, Yildiz A, Weinhaeusel A, Noehammer C, Leisch F, Kriegner A (2009). RGG: A General GUI Framework for R Scripts. BMC Bioinformatics, 10(1), 74. Yang L, Liu J, Liu M, Qian M, Zhang M, Hu H (2011). Identication of Fatty Acid Synthase from the Pacic White Shrimp, Litopenaeus vannamei and its Specic Expression Proles During White Spot Syndrome Virus Infection. Fish & Shellsh Immunology, 30(2), 744 749. Zhang J, Gentleman R (2004). Tools for Interactively Exploring R Packages. R News, 4(1), 2025. URL http://CRAN.R-project.org/doc/Rnews/. Zou W, Tolstikov VV (2008). Probing Genetic Algorithms for Feature Selection in Comprehensive Metabolic Proling Approach. Rapid Communications in Mass Spectrometry, 22(8), 13121324. Zou W, Tolstikov VV (2009). Pattern Recognition and Pathway Analysis with Genetic Algorithms in Mass Spectrometry Based Metabolomics. Algorithms, 2(2), 638666.
24
A. Appendix overview
In this appendix we will give an overview of some key aspects of RKWards technical design and development process, comparing them briey to competing GUI solutions, where appropriate. We will give slightly more attention to the details of the plugin framework (Section F) used in RKWard, since this is central to the extensibility of RKWard, and we will conclude with an example for extending RKWard by a plugin (Section G). Note that this document refers to RKWard version 0.5.6. Several technical details, described here, have changed in RKWard version 0.5.7 and the current development version.
25
Plugin R Console
RKWard
Script editor(s) Data editor(s)
Plugin
R engine
R engine runs in a separate process
Figure 14: Technical design of RKWard. Only a few central components are visualized. All communication with the R engine is passed through a single interface living in the frontend process. The R engine itself runs in a separate process. Separate threads within the frontend process are used to generate R code from plugins. clear separation between the GUI code and the code making direct use of the R application programming interface (API) (see also Figure 14). In future releases it could be made possible to run GUI and R engine on dierent computers.
This is similar to the approach taken in the trackObjs package (Plate 2009).
26
The use of active bindings has signicant performance implications when objects are accessed very frequently. This is particularly notable where an object inside the global environment is used as the index variable in a loop, as illustrated by the following example. When control returns to the top level prompt, after the rst assignment, i will become subject to object modication detection (i. e., it will be wrapped into an active binding). The subsequent for loop will then run slow. R> i <- 1 R> for (i in 1:100000) i + i In contrast, in the following example, i is a local object, and will not be replaced by an active binding. Therefore the loop will run approximately as fast as in a plain R session: R> f <- function () { + i <- 1 + for (i in 1:100000) i + i + } R> f () Future versions of RKWard will try to avoid this performance problem. One approach that is currently under consideration is to simply perform a pointer comparison of the SEXP records of objects in global environment with their copies in a hidden storage environment. Due to the implicit sharing of SEXP records (R Development Core Team 2012d,c), this should provide for a reliable way to detect changes for most types of R objects, with comparatively low memory and performance overhead. Special handling will be needed for environments and active bindings.
27
Plugins in RKWard rely on XML (http://www.w3.org/XML/) and ECMAScript (http:// www.ecmascript.org/; see Section F). XML is not only well suited to describe the layout of the GUI of plugins, but simple functional logic can also be represented (see also Visne et al. 2009). ECMAScript was chosen for the generation of R commands within plugins, in particular due to its availability as an embedded scripting engine inside the Qt libraries. While at rst glance R itself would appear as a natural choice of scripting language as well, this would make it impossible to use plugins in an asynchronous way. Further, the main functional requirement in this place is the manipulation and concatenation of text strings. While R provides support for this, concatenating strings with the + operator, as available in ECMAScript, allows for a very readable way to perform such basic text manipulation.
28
F. Plugin infrastructure
One of the earliest features of RKWard was the extensibility by plugins. Basically, plugins in RKWard provide complete GUI dialogs, or re-usable GUI components, which accept user settings and translate those user settings into R code19 . Thus, the plugin framework is basically a tool set used to dene GUIs for the automatic generation of R code. Much of the functionality in RKWard is currently implemented as plugins. For example, importing dierent le formats relying on the foreign package is achieved by this approach. Similarly, RKWard provides a modest GUI driven tool set for statistical analysis, especially for item response theory, distributions, and descriptive statistical analysis.
29
Figure 15: Plugin structure of RKWard. One or more plugins are declared in a plugin map. Each plugin is dened by two XML les, and one ECMAScript le. advice on using the plugin. Plugins can be invoked from their help page by clicking on a link near the top, which can be useful after following a link from a related help page. Changes to the source code of these elements take eect without the requirement to recompile RKWard.
30
thin wrapper around the HTML() function of the R2HTML package (Lecoutre 2003) in the current implementation. The use of custom formatting with HTML is possible, but discouraged. Standard elements such as a horizontal separator, and the Run again link (see Section 3.7) are inserted automatically, without the need to dene them for each plugin. Regarding the style of the generated R code, enforcing consistency is harder, but plugins which are to become part of the ocial RKWard application are reviewed for adherence to some guidelines. Perhaps the most important guidelines are
Write readable code, which is properly indented, and commented where necessary. Do not hide any relevant computations from the user by performing them in the ECMAScript. Rather, generate R code which will perform those computations, transparently. Plugins can be restricted to accept only certain types of data (such as only onedimensional numeric data). Use such restrictions where appropriate to avoid errors, but be very careful not to add too many of them.
31
Figure 16: Generated menu structure as dened by the plugin map. With the release of version 0.5.5, RKWard gained support for downloading additional sets of plugins directly from the internet. By simply clicking an Install button in a graphical dialog (SettingsConfigure RKWardPlugins), an external plugin set is downloaded, unpacked and its plugin map added to RKWards conguration, so it becomes instantly available after the conguration dialog is closed. External plugin sets are neither ocially included nor supported by the RKWard developers. However, they allow plugin developers to easily extend RKWard with state-of-the-art or highly specialized features. To achieve this, RKWard (version 0.5.6) draws on KNewStu2, a KDE library providing support for GHNS23 .
Automated testing
A second requirement for new plugins is that each plugin must be accompanied by at least one automated test. The automated testing framework in RKWard consists of an R package, rkwardtests, providing a set of R functions which allow to run a plugin with specic GUI settings, automatically. The resulting R code, R messages, and output are then compared to a dened standard. Automated tests are run routinely after changes in the plugin infrastructure, and before any new release. The automated testing framework is also useful in testing some aspects of the application which are not implemented as plugins, but this is currently limited to very few basic tests.
32
33
<dialog label="Two Variable t-Test"> <tabbook> <tab label="Basic settings" id="tab_variables"> <row id="basic_settings_row"> <varselector id="vars"/> <column> <varslot type="numeric" id="x" source="vars" required="true" label="compare"/> <varslot type="numeric" id="y" source="vars" required="true" label="against"/> <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> <checkbox id="paired" label="Paired sample" value="1" value_unchecked="0" /> </column> </row> </tab> <tab label="Options" id="tab_options"> <checkbox id="varequal" label="assume equal variances" value="1" value_unchecked="0"/> <frame label="Confidence Interval" id="confint_frame"> <spinbox type="real" id="conflevel" label="confidence level" min="0" max="1" initial="0.95"/> <checkbox id="confint" label="print confidence interval" value="1" checked="true"/> </frame> <stretch/> </tab> </tabbook> </dialog> </document>
function preprocess () { x = getValue ("x"); y = getValue ("y"); echo ('names <- rk.get.description (' + x + ", " + y + ')\n'); } function calculate () { varequal = getValue ("varequal"); paired = getValue ("paired");
34
var conflevel = getValue ("conflevel"); var hypothesis = getValue ("hypothesis"); var options = ", alternative=\"" + hypothesis + "\""; if (paired) options += ", paired=TRUE"; if ((!paired) && varequal) options += ", var.equal=TRUE"; if (conflevel != "0.95") options += ", conf.level=" + conflevel; echo ('result <- t.test (' + x + ", " + y + options + ')\n'); } function printout () { echo ('rk.header (result\$method, \n'); echo (' parameters=list ("Comparing", paste (names[1], "against", names[2]),\n'); echo (' "H1", rk.describe.alternative (result)'); if (!paired) { echo (',\n'); echo (' "Equal variances", "'); if (!varequal) echo ("not"); echo (' assumed"'); } echo ('))\n'); echo ('\n'); echo ('rk.results (list (\n'); echo (' \'Variable Name\'=names,\n'); echo (' \'estimated mean\'=result\$estimate,\n'); echo (' \'degrees of freedom\'=result\$parameter,\n'); echo (' t=result\$statistic,\n'); echo (' p=result\$p.value'); if (getValue ("confint")) { echo (',\n'); echo (' \'confidence interval percent\'=(100 * attr(result\$conf.int, "conf.level")),\n'); echo (' \'confidence interval of difference\'=result\$conf.int '); } echo ('))\n'); }
Aliation:
Stefan R odiger Lausitz University of Applied Sciences Department of Bio-, Chemistry and Process Engineering and Kardiologie-CCM, Charit e-Universit atsmedizin Berlin Germany E-mail: stefan_roediger@gmx.de, rkward-devel@lists.sourceforge.net