[rkward-cvs] [rkward] /: Fix more issues of excessive digit printing, add some more i18n on the way.
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Mon Nov 24 11:07:54 UTC 2014
Git commit de1babc6616c519e50dfc68c4231961c1c640a0d by Thomas Friedrichsmeier.
Committed on 24/11/2014 at 11:07.
Pushed by tfry into branch 'master'.
Fix more issues of excessive digit printing, add some more i18n on the way.
M +1 -3 ChangeLog
M +2 -2 rkward/plugins/analysis/corr_matrix.js
M +41 -44 rkward/plugins/uni1.2/code.js
M +25 -26 tests/analysis_plugins/basic_statistics_a.rkcommands.R
M +5 -5 tests/analysis_plugins/basic_statistics_a.rkout
M +5 -6 tests/analysis_plugins/basic_statistics_b.rkcommands.R
M +1 -1 tests/analysis_plugins/basic_statistics_b.rkout
http://commits.kde.org/rkward/de1babc6616c519e50dfc68c4231961c1c640a0d
diff --git a/ChangeLog b/ChangeLog
index 21692f0..7a05c59 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- Fix several issues of excessive printing of digits in plugins' output
- Restructure layout of CSV-import dialog
- Allow to open (any number of) R script files and rkward://-urls from the command line
- Add command line option --reuse for reusing an existing instance of RKWard
@@ -19,14 +20,11 @@
- Don't forget to write documentation
- Also general documentation for JS-functions is missing!
- What should be the policy regarding installing translations (80% criterion)
- - 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
any obvious problems.
- 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
- - <about> data!
--- Version 0.6.2 - Oct-20-2014
- In data editor, indicate NAs, explicitly
diff --git a/rkward/plugins/analysis/corr_matrix.js b/rkward/plugins/analysis/corr_matrix.js
index d323844..bdc8ada 100644
--- a/rkward/plugins/analysis/corr_matrix.js
+++ b/rkward/plugins/analysis/corr_matrix.js
@@ -102,8 +102,8 @@ function calculate () {
}
if (do_p) {
echo (' result[j, i] <- result[i, j] <- t$rho\n');
- echo (' result.p[j, i] <- paste("Chisq=", t$chisq, ",<br />df=", t$df, ",<br />p=", pchisq(t$chisq, t$df, lower.tail=FALSE), sep="")\n');
- echo (' result.p[i, j] <- paste("se=", sqrt(diag(t$var)), ",<br />n=", t$n, sep="")\n');
+ echo (' result.p[j, i] <- paste("Chisq=", format(t$chisq), ",<br />df=", t$df, ",<br />p=", format(pchisq(t$chisq, t$df, lower.tail=FALSE)), sep="")\n');
+ echo (' result.p[i, j] <- paste("se=", format(sqrt(diag(t$var))), ",<br />n=", t$n, sep="")\n');
} else {
echo (' result[i, j] <- result[j, i] <- t\n');
}
diff --git a/rkward/plugins/uni1.2/code.js b/rkward/plugins/uni1.2/code.js
index 4f29097..89650ca 100644
--- a/rkward/plugins/uni1.2/code.js
+++ b/rkward/plugins/uni1.2/code.js
@@ -2,120 +2,117 @@ function calculate () {
var narm = "na.rm=FALSE";
if (getValue ("narm")) narm = "na.rm=TRUE";
- var vars = trim (getValue ("z"));
- echo ('vars <- rk.list (' + vars.split ("\n").join (", ") + ')\n');
- echo ('results <- data.frame (\'Variable Name\'=I(names (vars)), check.names=FALSE)\n');
+ var vars = getList ("z");
+ echo ('vars <- rk.list (' + vars.join (", ") + ')\n');
+ echo ('results <- data.frame (' + i18n ("Variable Name") + '=I(names (vars)), check.names=FALSE)\n');
echo ('for (i in 1:length (vars)) {\n');
echo (' var <- vars[[i]]\n');
echo ('\n');
if (getValue ("length")) {
- echo (' results[i, \'Number of obs\'] <- length(var)\n');
- echo (' results[i, \'Number of missing values\'] <- sum(is.na(var))\n');
+ echo (' results[i, ' + i18n ("Number of cases") + '] <- length(var)\n');
+ echo (' results[i, ' + i18n ("Number of missing values") + '] <- sum(is.na(var))\n');
}
if (getValue ("mean")) {
- echo (' results[i, \'Mean\'] <- mean(var,' + narm + ')\n');
+ echo (' results[i, ' + i18n ("Mean") + '] <- mean(var,' + narm + ')\n');
}
if (getValue ("geo_mean")) {
// compute the geometric mean
- echo (' results[i, \'geometric mean\'] <- try (prod (na.omit(var))^(1 / length (na.omit(var))))\n');
+ echo (' results[i, ' + i18n ("geometric mean") + '] <- try (prod (na.omit(var))^(1 / length (na.omit(var))))\n');
}
if (getValue ("interquantile_mean")) {
// compute the quartile (25% and 75%) mean
- echo (' results[i, \'interquantile mean\'] <- try (sum(quantile(var, probs=c(0.25), na.rm=T), quantile(var, probs=c(0.75), na.rm=TRUE)) / 2)\n');
+ echo (' results[i, ' + i18n ("interquantile mean") + '] <- try (sum(quantile(var, probs=c(0.25), na.rm=T), quantile(var, probs=c(0.75), na.rm=TRUE)) / 2)\n');
}
if (getValue ("harmonic_mean")) {
// compute the harmonic mean
- echo (' results[i, \'harmonic mean\'] <- try (1 / mean(1 / na.omit(var)))\n');
+ echo (' results[i, ' + i18n ("harmonic mean") + '] <- try (1 / mean(1 / na.omit(var)))\n');
}
if (getValue ("vari")) {
- echo (' results[i, \'Variance\'] <- var(var,' + narm + ')\n');
+ echo (' results[i, ' + i18n ("Variance") + '] <- var(var,' + narm + ')\n');
}
if (getValue ("sd")) {
- echo (' results[i, \'Sd\'] <- sd(var,' + narm + ')\n');
+ echo (' results[i, ' + i18nc ("standard deviation; short", "sd") + '] <- sd(var,' + narm + ')\n');
}
if (getValue ("minimum")) {
- echo (' results[i, \'Minimum\'] <- min(var,' + narm + ')\n');
+ echo (' results[i, ' + i18n ("Minimum") + '] <- min(var,' + narm + ')\n');
}
if (getValue ("maximum")) {
- echo (' results[i, \'Maximum\'] <- max(var,' + narm + ')\n');
+ echo (' results[i, ' + i18n ("Maximum") + '] <- max(var,' + narm + ')\n');
}
var nmin;
if ((nmin = getValue ("nbminimum")) != "0") {
echo (' if (length (var) >= ' + nmin + ') {\n');
- echo (' results[i, \'Minimum values\'] <- paste (sort(var, decreasing=FALSE, na.last=TRUE)[1:' + nmin + '], collapse=" ")\n');
+ echo (' results[i, ' + i18n ("Minimum values") + '] <- paste (format(sort(var, decreasing=FALSE, na.last=TRUE)[1:' + nmin + ']), collapse=" ")\n');
echo (' }\n');
}
var nmax;
if ((nmax = getValue ("nbmaximum")) != "0") {
echo (' if (length (var) >= ' + nmax + ') {\n');
- echo (' results[i, \'Maximum values\'] <- paste (sort(var, decreasing=TRUE, na.last=TRUE)[1:' + nmax + '], collapse=" ")\n');
+ echo (' results[i, ' + i18n ("Maximum values") + '] <- paste (format(sort(var, decreasing=TRUE, na.last=TRUE)[1:' + nmax + ']), collapse=" ")\n');
echo (' }\n');
}
if (getValue ("median")) {
- echo (' results[i, \'Median\'] <- median(var,' + narm + ')\n');
+ echo (' results[i, ' + i18n ("Median") + '] <- median(var,' + narm + ')\n');
}
if (getValue ("irq")) {
- echo (' results[i, \'Inter Quartile Range\'] <- IQR(var,' + narm + ')\n');
+ echo (' results[i, ' + i18n ("Inter Quartile Range") + '] <- IQR(var,' + narm + ')\n');
}
if (getValue ("quartile")) {
echo (' temp <- quantile (var,' + narm + ')\n');
- echo (' results[i, \'Quartiles\'] <- paste (names (temp), temp, sep=": ", collapse=" ")\n');
+ echo (' results[i, ' + i18n ("Quartiles") + '] <- paste (names (temp), format (temp), sep=": ", collapse=" ")\n');
}
var nautre;
if ((nautre = getValue ("autre")) != "0") {
echo (' temp <- quantile (var, probs=seq (0, 1, length.out=' + nautre + '), ' + narm + ')\n');
- echo (' results[i, \'Quantiles\'] <- paste (names (temp), temp, sep=": ", collapse=" ")\n');
+ echo (' results[i, ' + i18n ("Quantiles") + '] <- paste (names (temp), format (temp), sep=": ", collapse=" ")\n');
}
echo (' \n');
- echo (' #robust statistics\n');
+ comment ("robust statistics", " ");
if (getValue ("trim") == "1") {
- echo (' results[i, \'Trimmed Mean\'] <- mean (var, trim=' + getValue ("pourcent") + ', ' + narm + ')\n');
+ echo (' results[i, ' + i18n ("Trimmed Mean") + '] <- mean (var, trim=' + getValue ("pourcent") + ', ' + narm + ')\n');
}
if (getValue ("mad") == "1") {
- echo (' results[i, \'Median Absolute Deviation\'] <- mad (var, constant=' + getValue ("constMad") + ', ' + narm + ')\n');
+ echo (' results[i, ' + i18n ("Median Absolute Deviation") + '] <- mad (var, constant=' + getValue ("constMad") + ', ' + narm + ')\n');
}
if (getValue ("huber") == "1") {
echo (' require ("MASS")\n');
- echo (' temp <- list (c(\'Location Estimate\',\'Mad scale estimate\'), c(NA,NA))\n');
+ echo (' temp <- list (c(' + i18n ("Location Estimate") + ',' + i18n ("Mad scale estimate") + '), c(NA,NA))\n');
echo (' try({\n');
echo (' temp <- hubers (var, k = ' + getValue ("winsor") + ',tol=' + getValue ("tol"));
if (getValue("customMu")=="1") echo (", mu="+getValue("mu"));
if (getValue("customS")=="1") echo (", s="+getValue("s"));
echo (",initmu ="+getValue("initmu")+"(var))\n");
echo (' })\n');
- echo (' results[i, \'Huber M-Estimator\'] <- paste (temp[[1]], temp[[2]], sep=": ", collapse=" ")\n');
+ echo (' results[i, ' + i18n ("Huber M-Estimator") + '] <- paste (format (temp[[1]]), format (temp[[2]]), sep=": ", collapse=" ")\n');
}
echo ('}\n');
echo ('\n');
if (getValue ("saveas.active")) {
- echo ('# store results\n');
+ comment ('store results');
echo ('.GlobalEnv$' + getValue ("saveas") + ' <- results\n');
}
}
function printout () {
- echo ('rk.header ("Univariate statistics", parameters=list (\n');
- echo ('"Remove Missing values", ');
- if (getValue ("narm")) echo ("TRUE");
- else echo ("FALSE");
- if (getValue("trim")=="1") {
- echo (', "Trimmed value for trimmed mean", "' + getValue ("pourcent") + '"\n');
- }
- if (getValue("mad")=="1") {
- echo (', "Constant for the MAD estimation", "' + getValue ("constMad") + '"\n');
- }
- if (getValue("huber")=="1") {
- echo (', "Winsorized values for Huber estimator", "' + getValue ("winsor") + '"\n');
- echo (', "Tolerance in Huber estimator", "' + getValue ("tol") + '"\n');
- if (getValue ("customMu")=="1") {
- echo (', "Mu for Huber estimator", "' + getValue ("mu") + '"\n');
+ header = new Header (i18n ("Univariate statistics")).addFromUI ("narm");
+ if (getBoolean("trim.state")) {
+ header.add (i18n ("Proprotion of trimmed values for trimmed mean"), getString ("pourcent"));
+ }
+ if (getBoolean("mad.state")) {
+ header.add (i18n ("Constant for the MAD estimation"), getString ("constMad"));
+ }
+ if (getBoolean("huber.state")) {
+ header.add (i18n ("Winsorized values for Huber estimator"), getString ("winsor"));
+ header.add (i18n ("Tolerance in Huber estimator"), getString ("tol"));
+ if (getBoolean ("customMu.state")) {
+ header.add (i18n ("Mu for Huber estimator"), getString ("mu"));
}
- if (getValue ("customS")=="1") {
- echo (', "S for Huber estimator", "' + getValue ("s") + '"\n');
+ if (getBoolean ("customS.state")) {
+ header.add (i18n ("S for Huber estimator"), getString ("s"));
}
- echo (', "Initial value", "' + getValue ("initmu") + '"\n');
+ header.add (i18n ("Initial value"), getString ("initmu"));
}
- echo ('))\n');
+ header.print ();
echo ('\n');
echo ('rk.results (results)\n');
if (getValue ("save_to_file")) echo ('write.csv(file="' + getValue ("file") + '", results)\n');
diff --git a/tests/analysis_plugins/basic_statistics_a.rkcommands.R b/tests/analysis_plugins/basic_statistics_a.rkcommands.R
index 98e92ed..9db0abb 100644
--- a/tests/analysis_plugins/basic_statistics_a.rkcommands.R
+++ b/tests/analysis_plugins/basic_statistics_a.rkcommands.R
@@ -1,47 +1,46 @@
local({
## Compute
vars <- rk.list (women[["weight"]], test50x)
-results <- data.frame ('Variable Name'=I(names (vars)), check.names=FALSE)
+results <- data.frame ("Variable Name"=I(names (vars)), check.names=FALSE)
for (i in 1:length (vars)) {
var <- vars[[i]]
- results[i, 'Number of obs'] <- length(var)
- results[i, 'Number of missing values'] <- sum(is.na(var))
- results[i, 'Mean'] <- mean(var,na.rm=TRUE)
- results[i, 'Variance'] <- var(var,na.rm=TRUE)
- results[i, 'Sd'] <- sd(var,na.rm=TRUE)
- results[i, 'Minimum'] <- min(var,na.rm=TRUE)
- results[i, 'Maximum'] <- max(var,na.rm=TRUE)
- results[i, 'Median'] <- median(var,na.rm=TRUE)
- results[i, 'Inter Quartile Range'] <- IQR(var,na.rm=TRUE)
+ results[i, "Number of cases"] <- length(var)
+ results[i, "Number of missing values"] <- sum(is.na(var))
+ results[i, "Mean"] <- mean(var,na.rm=TRUE)
+ results[i, "Variance"] <- var(var,na.rm=TRUE)
+ results[i, "sd"] <- sd(var,na.rm=TRUE)
+ results[i, "Minimum"] <- min(var,na.rm=TRUE)
+ results[i, "Maximum"] <- max(var,na.rm=TRUE)
+ results[i, "Median"] <- median(var,na.rm=TRUE)
+ results[i, "Inter Quartile Range"] <- IQR(var,na.rm=TRUE)
temp <- quantile (var,na.rm=TRUE)
- results[i, 'Quartiles'] <- paste (names (temp), temp, sep=": ", collapse=" ")
+ results[i, "Quartiles"] <- paste (names (temp), format (temp), sep=": ", collapse=" ")
temp <- quantile (var, probs=seq (0, 1, length.out=6), na.rm=TRUE)
- results[i, 'Quantiles'] <- paste (names (temp), temp, sep=": ", collapse=" ")
+ results[i, "Quantiles"] <- paste (names (temp), format (temp), sep=": ", collapse=" ")
- #robust statistics
- results[i, 'Trimmed Mean'] <- mean (var, trim=0.05, na.rm=TRUE)
- results[i, 'Median Absolute Deviation'] <- mad (var, constant=1.4628, na.rm=TRUE)
+ # robust statistics
+ results[i, "Trimmed Mean"] <- mean (var, trim=0.05, na.rm=TRUE)
+ results[i, "Median Absolute Deviation"] <- mad (var, constant=1.4628, na.rm=TRUE)
require ("MASS")
- temp <- list (c('Location Estimate','Mad scale estimate'), c(NA,NA))
+ temp <- list (c("Location Estimate","Mad scale estimate"), c(NA,NA))
try({
temp <- hubers (var, k = 1.50,tol=0.07, mu=3, s=,initmu =median(var))
})
- results[i, 'Huber M-Estimator'] <- paste (temp[[1]], temp[[2]], sep=": ", collapse=" ")
+ results[i, "Huber M-Estimator"] <- paste (format (temp[[1]]), format (temp[[2]]), sep=": ", collapse=" ")
}
# store results
.GlobalEnv$my.data <- results
## Print result
-rk.header ("Univariate statistics", parameters=list (
-"Remove Missing values", TRUE, "Trimmed value for trimmed mean", "0.05"
-, "Constant for the MAD estimation", "1.4628"
-, "Winsorized values for Huber estimator", "1.50"
-, "Tolerance in Huber estimator", "0.07"
-, "Mu for Huber estimator", "3"
-, "S for Huber estimator", ""
-, "Initial value", "median"
-))
+rk.header ("Univariate statistics", parameters=list("Omit missing values"="yes",
+ "Proprotion of trimmed values for trimmed mean"="0.05",
+ "Constant for the MAD estimation"="1.4628",
+ "Winsorized values for Huber estimator"="1.50",
+ "Tolerance in Huber estimator"="0.07",
+ "Mu for Huber estimator"="3",
+ "S for Huber estimator"="",
+ "Initial value"="median"))
rk.results (results)
})
diff --git a/tests/analysis_plugins/basic_statistics_a.rkout b/tests/analysis_plugins/basic_statistics_a.rkout
index f759ee0..8ed864f 100644
--- a/tests/analysis_plugins/basic_statistics_a.rkout
+++ b/tests/analysis_plugins/basic_statistics_a.rkout
@@ -1,7 +1,7 @@
<h1>Univariate statistics</h1>
<h2>Parameters</h2>
-<ul><li>Remove Missing values: TRUE</li>
-<li>Trimmed value for trimmed mean: 0.05</li>
+<ul><li>Omit missing values: yes</li>
+<li>Proprotion of trimmed values for trimmed mean: 0.05</li>
<li>Constant for the MAD estimation: 1.4628</li>
<li>Winsorized values for Huber estimator: 1.50</li>
<li>Tolerance in Huber estimator: 0.07</li>
@@ -11,7 +11,7 @@
</ul>
DATE<br />
<table border="1">
-<tr><td>Variable Name</td><td>Number of obs</td><td>Number of missing values</td><td>Mean</td><td>Variance</td><td>Sd</td><td>Minimum</td><td>Maximum</td><td>Median</td><td>Inter Quartile Range</td><td>Quartiles</td><td>Quantiles</td><td>Trimmed Mean</td><td>Median Absolute Deviation</td><td>Huber M-Estimator</td></tr>
-<tr><td>weight</td><td>15</td><td>0</td><td>136.73</td><td>240.21</td><td>15.499</td><td>115</td><td>164</td><td>135</td><td>23.5</td><td>0%: 115 25%: 124.5 50%: 135 75%: 148 100%: 164</td><td>0%: 115 20%: 122.4 40%: 130.8 60%: 140.2 80%: 150.8 100%: 164</td><td>136.73</td><td>17.554</td><td>3: 143.017677999144</td></tr>
-<tr><td>test50x</td><td>50</td><td>0</td><td>125.5</td><td>212.5</td><td>14.577</td><td>101</td><td>150</td><td>125.5</td><td>24.5</td><td>0%: 101 25%: 113.25 50%: 125.5 75%: 137.75 100%: 150</td><td>0%: 101 20%: 110.8 40%: 120.6 60%: 130.4 80%: 140.2 100%: 150</td><td>125.5</td><td>18.285</td><td>3: 138.260549866364</td></tr>
+<tr><td>Variable Name</td><td>Number of cases</td><td>Number of missing values</td><td>Mean</td><td>Variance</td><td>sd</td><td>Minimum</td><td>Maximum</td><td>Median</td><td>Inter Quartile Range</td><td>Quartiles</td><td>Quantiles</td><td>Trimmed Mean</td><td>Median Absolute Deviation</td><td>Huber M-Estimator</td></tr>
+<tr><td>weight</td><td>15</td><td>0</td><td>136.73</td><td>240.21</td><td>15.499</td><td>115</td><td>164</td><td>135</td><td>23.5</td><td>0%: 115.0 25%: 124.5 50%: 135.0 75%: 148.0 100%: 164.0</td><td>0%: 115.0 20%: 122.4 40%: 130.8 60%: 140.2 80%: 150.8 100%: 164.0</td><td>136.73</td><td>17.554</td><td>3: 143.02</td></tr>
+<tr><td>test50x</td><td>50</td><td>0</td><td>125.5</td><td>212.5</td><td>14.577</td><td>101</td><td>150</td><td>125.5</td><td>24.5</td><td>0%: 101.00 25%: 113.25 50%: 125.50 75%: 137.75 100%: 150.00</td><td>0%: 101.0 20%: 110.8 40%: 120.6 60%: 130.4 80%: 140.2 100%: 150.0</td><td>125.5</td><td>18.285</td><td>3: 138.26</td></tr>
</table>
diff --git a/tests/analysis_plugins/basic_statistics_b.rkcommands.R b/tests/analysis_plugins/basic_statistics_b.rkcommands.R
index 984457a..21625de 100644
--- a/tests/analysis_plugins/basic_statistics_b.rkcommands.R
+++ b/tests/analysis_plugins/basic_statistics_b.rkcommands.R
@@ -1,23 +1,22 @@
local({
## Compute
vars <- rk.list (test10x, women[["height"]])
-results <- data.frame ('Variable Name'=I(names (vars)), check.names=FALSE)
+results <- data.frame ("Variable Name"=I(names (vars)), check.names=FALSE)
for (i in 1:length (vars)) {
var <- vars[[i]]
if (length (var) >= 2) {
- results[i, 'Minimum values'] <- paste (sort(var, decreasing=FALSE, na.last=TRUE)[1:2], collapse=" ")
+ results[i, "Minimum values"] <- paste (format(sort(var, decreasing=FALSE, na.last=TRUE)[1:2]), collapse=" ")
}
if (length (var) >= 3) {
- results[i, 'Maximum values'] <- paste (sort(var, decreasing=TRUE, na.last=TRUE)[1:3], collapse=" ")
+ results[i, "Maximum values"] <- paste (format(sort(var, decreasing=TRUE, na.last=TRUE)[1:3]), collapse=" ")
}
- #robust statistics
+ # robust statistics
}
## Print result
-rk.header ("Univariate statistics", parameters=list (
-"Remove Missing values", TRUE))
+rk.header ("Univariate statistics", parameters=list("Omit missing values"="yes"))
rk.results (results)
})
diff --git a/tests/analysis_plugins/basic_statistics_b.rkout b/tests/analysis_plugins/basic_statistics_b.rkout
index e764cee..802b742 100644
--- a/tests/analysis_plugins/basic_statistics_b.rkout
+++ b/tests/analysis_plugins/basic_statistics_b.rkout
@@ -1,6 +1,6 @@
<h1>Univariate statistics</h1>
<h2>Parameters</h2>
-<ul><li>Remove Missing values: TRUE</li>
+<ul><li>Omit missing values: yes</li>
</ul>
DATE<br />
<table border="1">
More information about the rkward-tracker
mailing list