[rkward-cvs] SF.net SVN: rkward-code:[5004] trunk/rkward
tfry at users.sf.net
tfry at users.sf.net
Thu Nov 13 12:54:49 UTC 2014
Revision: 5004
http://sourceforge.net/p/rkward/code/5004
Author: tfry
Date: 2014-11-13 12:54:46 +0000 (Thu, 13 Nov 2014)
Log Message:
-----------
Add a simple new (object based) method for creating rk.header()-calls from JS code.
This should be more readable than makeHeaderCode(), particularly when combined with i18n()-calls.
It also makes it easy to define parts of the header in other places of the JS code (such as in the calculate() function).
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/doc/rkwardplugins/index.docbook
trunk/rkward/rkward/plugins/analysis/t_test.js
trunk/rkward/rkward/plugins/testing/test1.js
trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R
trunk/rkward/rkward/scriptbackends/common.js
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2014-11-12 19:35:14 UTC (rev 5003)
+++ trunk/rkward/ChangeLog 2014-11-13 12:54:46 UTC (rev 5004)
@@ -1,3 +1,4 @@
+- New Object based convience method for printing headers from plugins
- Implement polyPath()-drawing in RK() device
- Pre-compile the common js code included in every plugin (only when compiled with Qt >= 4.7)
- Improve crash recovery dialog to not prompt again for the same files
@@ -7,13 +8,11 @@
- IN PROGESS: Allow plugins to be translated
+ Notes:
- Is it a problem to sync KDE_LANG and LANGUAGE? Should that also be set for the backend?
- - Message extraction: Should we do this in R, using XiMpLe? That might allow us to give better context / comments
+ - Lifetime of RKMessageCatalogs? Should probably be destructable, at least when reloading pluginmaps. Should be possible to implement in a sane ways
+ using QSharedPointer magic.
- Don't forget to write documentation
- Also general documentation for JS-functions is missing!
- - Also adjust all examples throughout the docs.
- - Document message merging, or better yet: Make extract_plugin_messages.py take care of that
- What should be the policy regarding installing translations (80% criterion)
- - discuss i18n_context vs. comments
- Important pitfalls: String comparison with checkbox / radio labels! (Probably wrong in some plugins)
- i18n'ed plugins vs. automated tests
- Sure, we can run automated tests under C locale. But it would be nice to have an additional check that translations don't cause
@@ -21,13 +20,7 @@
- At least we could check for errors
- Perhaps a special diff of the generated R commands, where all quoted strings and comments are stripped?
- i18n calls
- - wcgrep getStringAttribute.*i18n
- - element text
- - i18n in JS:
- - should return strings quoted, by default. Safer and less typing.
- - enforces suggested policy of not i18n'ing functional parts of the code (variable / function names)
- - Additional function comment(), equivalent to printIndented ("#", i18n (noquote ("something")))
- - An elegant (object based?) way to fix the makeHeaderCode()-mess?
+ - <about> data!
--- Version 0.6.2 - Oct-20-2014
- In data editor, indicate NAs, explicitly
Modified: trunk/rkward/doc/rkwardplugins/index.docbook
===================================================================
--- trunk/rkward/doc/rkwardplugins/index.docbook 2014-11-12 19:35:14 UTC (rev 5003)
+++ trunk/rkward/doc/rkwardplugins/index.docbook 2014-11-13 12:54:46 UTC (rev 5004)
@@ -555,13 +555,15 @@
</para>
<programlisting>
function printout () {
- makeHeaderCode (i18n ("Two Variable t-Test"), new Array (i18n ("Assume equal variances"),
- getBoolean ("varequal.state") ? i18n ("yes") : i18n ("no"), i18n ("Confidence level"), getString ("conflevel")))
+ new Header (i18n ("Two Variable t-Test"))
+ .add (i18n ("Assume equal variances"), getBoolean ("varequal.state") ? i18n ("yes") : i18n ("no"))
+ .add (i18n ("Confidence level"), getString ("conflevel"))
+ .print ();
echo ('rk.print (res)\n');
}
</programlisting>
<para>
- <function>rk.print()</function> utilizes the R2HTML package to provide HTML formatted output. Another helpful function is <function>rk.results()</function>, which can also output different kinds of result tables. If in doubt, however, just use <function>rk.print()</function>, and be done with. <function>makeHeaderCode()</function> is a JS level helper function to create a call to <function>rk.header()</function> (just take a look at the generated code). In some cases you may want to call <function>echo ('rk.header (...)')</function> directly to print a header for your output.
+ <function>rk.print()</function> utilizes the R2HTML package to provide HTML formatted output. Another helpful function is <function>rk.results()</function>, which can also output different kinds of result tables. If in doubt, however, just use <function>rk.print()</function>, and be done with. The JS class <function>Header</function> is a JS level helper to create a call to <function>rk.header()</function> (just take a look at the generated code). In some cases you may want to call <function>echo ('rk.header (...)')</function> 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 <function>rk.cat.output()</function>. 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 <function>rk.header()</function>, <function>rk.print()</function>, <function>rk.results()</function>, and -- if needed -- <function>rk.print.literal()</function>. If those don't seem to satisfy your formatting needs, contact us on the mailing list for help.
Modified: trunk/rkward/rkward/plugins/analysis/t_test.js
===================================================================
--- trunk/rkward/rkward/plugins/analysis/t_test.js 2014-11-12 19:35:14 UTC (rev 5003)
+++ trunk/rkward/rkward/plugins/analysis/t_test.js 2014-11-13 12:54:46 UTC (rev 5004)
@@ -41,33 +41,25 @@
}
function printout () {
- echo ('rk.header (result$method, \n');
- if (testForm != "const") {
- echo (' parameters=list ("Comparing"=paste (names[1], "against", names[2]),\n');
- } else {
- echo (' parameters=list ("Comparing"=paste (names[1], "against constant"),\n');
- }
- echo (' "H1"=rk.describe.alternative (result)');
+ var header = new Header (noquote ('result$method'));
+ header.add (i18n ('Comparing'), noquote ('names[1]'));
+ header.add (i18nc ("compare against", 'against'), (testForm != "const") ? noquote ('names[2]') : i18n ('constant value: %1', mu));
+ header.add ('H1', noquote ('rk.describe.alternative (result)'));
if (testForm == "indep") {
- echo (',\n');
- echo (' "Equal variances"="');
- if (!varequal) echo ("not");
- echo (' assumed"');
+ header.add (i18n ('Equal variances'), varequal ? i18n ('assumed') : i18n ('not assumed'));
}
- echo ('))\n');
+ header.print ();
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 (' ' + i18n ('Variable Name') + '=names,\n');
+ echo (' ' + i18n ('estimated mean') + '=result$estimate,\n');
+ echo (' ' + i18n ('degrees of freedom') + '=result$parameter,\n');
echo (' t=result$statistic,\n');
echo (' p=result$p.value');
if (confint) {
echo (',\n');
- echo (' \'confidence interval percent\'=(100 * attr(result$conf.int, "conf.level")),\n');
- echo (' \'confidence interval of difference\'=result$conf.int ');
+ echo (' ' + i18n ('confidence interval percent') + '=(100 * attr(result$conf.int, "conf.level")),\n');
+ echo (' ' + i18n ('confidence interval of difference') + '=result$conf.int ');
}
echo ('))\n');
}
-
-
Modified: trunk/rkward/rkward/plugins/testing/test1.js
===================================================================
--- trunk/rkward/rkward/plugins/testing/test1.js 2014-11-12 19:35:14 UTC (rev 5003)
+++ trunk/rkward/rkward/plugins/testing/test1.js 2014-11-13 12:54:46 UTC (rev 5004)
@@ -9,8 +9,10 @@
}
function printout () {
- makeHeaderCode ("SimpleAnova", new Array (i18nc ("GLM Model specification", "Model"), getValue ("model"), "Data", getValue ("model.table"), "Test", noquote ("print ('hi')")))
-// makeHeaderCode ("SimpleAnova", new Array ("Model", "Data"))
+ new Header (i18n ("SimpleAnova"))
+ .add (i18nc ("GLM Model specification", "Model"), getValue ("model"))
+ .add (i18n ("Data"), getValue ("model.table"))
+ .add ("Test", noquote ("print ('hi')")).print ();
echo ('rk.echo (result)\n');
comment ('i18n tests below');
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R 2014-11-12 19:35:14 UTC (rev 5003)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R 2014-11-13 12:54:46 UTC (rev 5004)
@@ -128,6 +128,7 @@
if (length (parameters)) {
# legacy handling: parameter=value used to be passed as parameter, value
if (is.null (names (parameters))) {
+ warning ("Unnamed parameter lists are deprecated in rk.header()")
s <- seq.int (1, length (parameters), by=2)
pnames <- as.character (parameters[s])
parameters <- parameters[s+1]
Modified: trunk/rkward/rkward/scriptbackends/common.js
===================================================================
--- trunk/rkward/rkward/scriptbackends/common.js 2014-11-12 19:35:14 UTC (rev 5003)
+++ trunk/rkward/rkward/scriptbackends/common.js 2014-11-13 12:54:46 UTC (rev 5004)
@@ -97,18 +97,27 @@
echo ("rk.header(" + quote (title));
if (parameters.length) {
echo (", parameters=list(");
- for (var p = 0; p < parameters.length; ++p) {
- if (p) {
- if (!(p % 2)) echo (",\n\t");
- else echo (", ");
- }
- echo (quote(parameters[p]));
+ for (var p = 0; p < parameters.length; p += 2) {
+ if (p) echo (",\n\t");
+ echo (quote (parameters[p]) + "=" + quote (parameters[p+1]));
}
echo (")");
}
echo (")\n");
}
+Header = function (title) {
+ this.title = title;
+ this.parameters = [];
+ this.add = function (caption, value) {
+ this.parameters.push (caption, value);
+ return this;
+ }
+ this.print = function () {
+ makeHeaderCode (this.title, this.parameters);
+ }
+}
+
getValue = function (id) {
return (_RK_backend.getValue (id));
}
More information about the rkward-tracker
mailing list