[rkward] rkward/plugins/rkwarddev_scripts: finalized changes from ite() to js()

m.eik michalke meik.michalke at uni-duesseldorf.de
Fri Nov 27 21:28:28 UTC 2015


Git commit 44c1ba32114c62bfb29850818323334e304fd565 by m.eik michalke.
Committed on 27/11/2015 at 15:17.
Pushed by meikm into branch 'master'.

finalized changes from ite() to js()

  - there's still some scope issues, js() doesn't find the helper function defined inside the local() env,
    but once it's assigned globally, there's no problem. so using this as a workaround.

M  +119  -119  rkward/plugins/rkwarddev_scripts/rkwarddev_power_plugin_script.R

http://commits.kde.org/rkward/44c1ba32114c62bfb29850818323334e304fd565

diff --git a/rkward/plugins/rkwarddev_scripts/rkwarddev_power_plugin_script.R b/rkward/plugins/rkwarddev_scripts/rkwarddev_power_plugin_script.R
index 7198463..85d65c8 100644
--- a/rkward/plugins/rkwarddev_scripts/rkwarddev_power_plugin_script.R
+++ b/rkward/plugins/rkwarddev_scripts/rkwarddev_power_plugin_script.R
@@ -4,7 +4,7 @@
 # *EXCEPT* for the last call, see below.
 
 require(rkwarddev)
-rkwarddev.required("0.07-1")
+rkwarddev.required("0.07-4")
 
 local({
 # set the output directory to overwrite the actual plugin
@@ -343,126 +343,124 @@ pwr.js.calc <- rk.paste.JS(
         } else {}
         echo("\n\t\t\tr=", pwr.input.effect)
       } else {}
-    } else {}
-  ),
+    } else {},
   ########
   ## ANOVA
-  ite(id(pwr.stat.drop, " == \"pwr.anova.test\""),
-    rk.paste.JS(
-      echo("pwr.anova.test("),
-      echo("\n\t\t\tk=", pwr.input.groups),
-      ite(id(pwr.parameter.rad, " != \"Sample size\""),
+    if(pwr.stat.drop == "pwr.anova.test"){
+      echo("pwr.anova.test(")
+      echo("\n\t\t\tk=", pwr.input.groups)
+      if(pwr.parameter.rad != "Sample size"){
         echo(",\n\t\t\tn=", pwr.input.sample)
-      ),
-      ite(id(pwr.parameter.rad, " != \"Effect size\""),
-        ite(id(pwr.effect.etasq.rad, " == \"f\""),
-          echo(",\n\t\t\tf=", pwr.input.effect),
-          rk.paste.JS (echo(",\n\t\t\tf=sqrt(", pwr.input.effect,"/(1-", pwr.input.effect,"))"), R.comment ("calculate f from eta squared"))
-        )
-      )
-    )
-  ),
+      } else {}
+      if(pwr.parameter.rad != "Effect size"){
+        if(pwr.effect.etasq.rad == "f"){
+          echo(",\n\t\t\tf=", pwr.input.effect)
+        } else {
+          echo(",\n\t\t\tf=sqrt(", pwr.input.effect,"/(1-", pwr.input.effect,"))")
+          R.comment ("calculate f from eta squared")
+        }
+      } else {}
+    } else {},
   ######
   ## GLM
-  ite(id(pwr.stat.drop, " == \"pwr.f2.test\""),
-    rk.paste.JS(
-      echo("pwr.f2.test("),
-      ite(id(pwr.parameter.rad, " != \"Parameter count\""),
-        rk.paste.JS(
-          echo("\n\t\t\tu=", pwr.input.dfu)
-        )
-      ),
-      ite(id(pwr.parameter.rad, " != \"Sample size\""),
-        rk.paste.JS(
-          ite(id(pwr.parameter.rad, " != \"Parameter count\""),
-            echo (",")
-          ),
-          echo("\n\t\t\tv=", pwr.input.dfv)
-        )
-      ),
-      ite(id(pwr.parameter.rad, " != \"Effect size\""),
-        rk.paste.JS(
-          echo(",\n\t\t\tf2=", pwr.input.effect)
-        )
-      )
-    )
-  ),
+    if(pwr.stat.drop == "pwr.f2.test"){
+      echo("pwr.f2.test(")
+      if(pwr.parameter.rad != "Parameter count"){
+        echo("\n\t\t\tu=", pwr.input.dfu)
+      } else {}
+      if(pwr.parameter.rad != "Sample size"){
+        if(pwr.parameter.rad != "Parameter count"){
+          echo (",")
+        } else {}
+        echo("\n\t\t\tv=", pwr.input.dfv)
+      } else {}
+      if(pwr.parameter.rad != "Effect size"){
+        echo(",\n\t\t\tf2=", pwr.input.effect)
+      } else {}
+    } else {},
   ##############
   ## Chi squared
-  ite(id(pwr.stat.drop, " == \"pwr.chisq.test\""),
-    rk.paste.JS(
-      echo("pwr.chisq.test("),
-      ite(id(pwr.parameter.rad, " != \"Effect size\""),
+    if(pwr.stat.drop == "pwr.chisq.test"){
+      echo("pwr.chisq.test(")
+      if(pwr.parameter.rad != "Effect size"){
         echo("\n\t\t\tw=", pwr.input.effect)
-      ),
-      ite(id(pwr.parameter.rad, " != \"Sample size\""),
-        rk.paste.JS(
-          ite(id(pwr.parameter.rad, " != \"Effect size\""), echo(",")),
-          echo("\n\t\t\tN=", pwr.input.sample)
-        )
-      ),
+      } else {}
+      if(pwr.parameter.rad != "Sample size"){
+        if(pwr.parameter.rad != "Effect size"){
+          echo(",")
+        } else {}
+        echo("\n\t\t\tN=", pwr.input.sample)
+      } else {}
       echo(",\n\t\t\tdf=", pwr.input.df)
-    )
-  ),
+    } else {},
   ##############
   ## proportions
-  ite(id(pwr.stat.drop, " == \"pwr.p.test\""),
-    rk.paste.JS(
-      ite(id(pwr.proptype.drop, " == \"two.sample.same\""), echo("pwr.2p.test(")),
-      ite(id(pwr.proptype.drop, " == \"two.sample.diff\""), echo("pwr.2p2n.test(")),
-      ite(id(pwr.proptype.drop, " == \"one.sample\""), echo("pwr.p.test(")),
-      ite(id(pwr.parameter.rad, " != \"Effect size\""),
+    if(pwr.stat.drop == "pwr.p.test"){
+      if(pwr.proptype.drop == "two.sample.same"){
+        echo("pwr.2p.test(")
+      } else {}
+      if(pwr.proptype.drop == "two.sample.diff"){
+        echo("pwr.2p2n.test(")
+      } else {}
+      if(pwr.proptype.drop == "one.sample"){
+        echo("pwr.p.test(")
+      } else {}
+      if(pwr.parameter.rad != "Effect size"){
         echo("\n\t\t\th=", pwr.input.effect)
-      ),
-      ite(id(pwr.parameter.rad, " != \"Sample size\""),
-        rk.paste.JS(
-          ite(id(pwr.parameter.rad, " != \"Effect size\""), echo(",")),
-          ite(id(pwr.proptype.drop, " != \"two.sample.diff\""),
-            echo("\n\t\t\tn=", pwr.input.sample),
-            echo("\n\t\t\tn1=", pwr.input.sample.n1, ",\n\t\t\tn2=", pwr.input.sample.n2)
-          )
-        ),
-        ite(id(pwr.proptype.drop, " == \"two.sample.diff\""),
-          echo(",\n\t\t\tn1=", pwr.input.sample.n1),
-        )
-      )
-    )
-  ),
+      } else {}
+      if(pwr.parameter.rad != "Sample size"){
+        if(pwr.parameter.rad != "Effect size"){
+          echo(",")
+        } else {}
+        if(pwr.proptype.drop != "two.sample.diff"){
+          echo("\n\t\t\tn=", pwr.input.sample)
+        } else {
+          echo("\n\t\t\tn1=", pwr.input.sample.n1, ",\n\t\t\tn2=", pwr.input.sample.n2)
+        }
+      } else {
+        if(pwr.proptype.drop == "two.sample.diff"){
+          echo(",\n\t\t\tn1=", pwr.input.sample.n1)
+        } else {}
+      }
+    } else {},
   ######################
   ## normal distribution
-  ite(id(pwr.stat.drop, " == \"pwr.norm.test\""),
-    rk.paste.JS(
-      echo("pwr.norm.test("),
-      ite(id(pwr.parameter.rad, " != \"Effect size\""),
+    if(pwr.stat.drop == "pwr.norm.test"){
+      echo("pwr.norm.test(")
+      if(pwr.parameter.rad != "Effect size"){
         echo("\n\t\t\td=", pwr.input.effect)
-      ),
-      ite(id(pwr.parameter.rad, " != \"Sample size\""),
-        rk.paste.JS(
-          ite(id(pwr.parameter.rad, " != \"Effect size\""), echo(",")),
-          echo("\n\t\t\tn=", pwr.input.sample)
-        )
-      )
-    )
-  ),
-  ite(id(pwr.parameter.rad, " != \"Significance level\""),
-    ite(id(pwr.input.signif, " != 0.05"), echo(",\n\t\t\tsig.level=", pwr.input.signif)),
-    echo(",\n\t\t\tsig.level=NULL")
-  ),
-  ite(id(pwr.parameter.rad, " != \"Power\""),
-    echo(",\n\t\t\tpower=", pwr.input.power)
-  ),
-  ite(id(pwr.stat.drop, " == \"pwr.t.test\" & ", pwr.type.drop, " != \"two.sample.diff\" & ", pwr.type.drop, " != \"two.sample\""),
-    echo(",\n\t\t\ttype=\"", pwr.type.drop, "\"")
-  ),
-  ite(id(pwr.stat.drop, " != \"pwr.anova.test\" & ", pwr.stat.drop, " != \"pwr.f2.test\" & ", pwr.stat.drop, " != \"pwr.chisq.test\""),
-    ite(id(pwr.hypothesis.drop, " != \"two.sided\""),
-      echo(",\n\t\t\talternative=\"", pwr.hypothesis.drop, "\"")
-    )
+      } else {}
+      if(pwr.parameter.rad != "Sample size"){
+        if(pwr.parameter.rad != "Effect size"){
+          echo(",")
+        } else {}
+        echo("\n\t\t\tn=", pwr.input.sample)
+      } else {}
+    } else {},
+    if(pwr.parameter.rad != "Significance level"){
+      if(pwr.input.signif != 0.05){
+        echo(",\n\t\t\tsig.level=", pwr.input.signif)
+      } else {}
+    } else {
+      echo(",\n\t\t\tsig.level=NULL")
+    },
+    if(pwr.parameter.rad != "Power"){
+      echo(",\n\t\t\tpower=", pwr.input.power)
+    } else {},
+    if(pwr.stat.drop == "pwr.t.test" && pwr.type.drop != "two.sample.diff" && pwr.type.drop != "two.sample"){
+      echo(",\n\t\t\ttype=\"", pwr.type.drop, "\"")
+    } else {},
+    if(pwr.stat.drop != "pwr.anova.test" && pwr.stat.drop != "pwr.f2.test" && pwr.stat.drop != "pwr.chisq.test"){
+      if(pwr.hypothesis.drop != "two.sided"){
+        echo(",\n\t\t\talternative=\"", pwr.hypothesis.drop, "\"")
+      } else {}
+    } else {}
   ),
   echo("\n\t\t)\n\t)\n\n")
 )
 
-helper.make.effect.size.legend <- function (indicator, small, medium, large) {
+# unfortunately, js() somehow doesn't find this function if it's just defined inside the local environment
+helper.make.effect.size.legend <<- function (indicator, small, medium, large) {
    indicator <- paste0("\"", indicator, "\"")
    rk.paste.JS (echo(
       "\trk.print(", i18n ("Interpretation of effect size <strong>%1</strong> (according to Cohen): ", indicator, context="Argument is name of statistic, e.g. 'r'"), ")\n",
@@ -493,23 +491,25 @@ pwr.js.print <- rk.paste.JS(
     "\trk.results(pwr.result)\n",
     "\tif(!is.null(note)){\n\t\trk.print(paste(", i18n ("<strong>Note:</strong>"), ", note))\n\t}\n\n"
   ),
-  ite(id(pwr.stat.drop, " == \"pwr.t.test\" | ", pwr.stat.drop, " == \"pwr.norm.test\""),
-    helper.make.effect.size.legend ("d", "0.2", "0.5", "0.8")
-  ),
-  ite(id(pwr.stat.drop, " == \"pwr.r.test\""),
-    helper.make.effect.size.legend ("r", "0.1", "0.3", "0.5")
-  ),
-  ite(id(pwr.stat.drop, " == \"pwr.f2.test\""),
-    helper.make.effect.size.legend ("f<sup>2</sup>", "0.02", "0.15", "0.35")
-  ),
-  ite(id(pwr.stat.drop, " == \"pwr.anova.test\""),
-    helper.make.effect.size.legend ("f", "0.1", "0.25", "0.4")
-  ),
-  ite(id(pwr.stat.drop, " == \"pwr.chisq.test\""),
-    helper.make.effect.size.legend ("w", "0.1", "0.3", "0.5")
-  ),
-  ite(id(pwr.stat.drop, " == \"pwr.p.test\""),
-    helper.make.effect.size.legend ("h", "0.2", "0.5", "0.8")
+  js(
+    if(pwr.stat.drop == "pwr.t.test" || pwr.stat.drop == "pwr.norm.test"){
+      helper.make.effect.size.legend ("d", "0.2", "0.5", "0.8")
+    } else {},
+    if(pwr.stat.drop == "pwr.r.test"){
+      helper.make.effect.size.legend ("r", "0.1", "0.3", "0.5")
+    } else {},
+    if(pwr.stat.drop == "pwr.f2.test"){
+      helper.make.effect.size.legend ("f<sup>2</sup>", "0.02", "0.15", "0.35")
+    } else {},
+    if(pwr.stat.drop == "pwr.anova.test"){
+      helper.make.effect.size.legend ("f", "0.1", "0.25", "0.4")
+    } else {},
+    if(pwr.stat.drop == "pwr.chisq.test"){
+      helper.make.effect.size.legend ("w", "0.1", "0.3", "0.5")
+    } else {},
+    if(pwr.stat.drop == "pwr.p.test"){
+      helper.make.effect.size.legend ("h", "0.2", "0.5", "0.8")
+    } else {}
   )
 )
 



More information about the rkward-tracker mailing list