[rkward] packages/rkwarddev/R: fixed limitation of only one call in if condidtions (JavaScript)

m.eik michalke meik.michalke at uni-duesseldorf.de
Tue Oct 27 15:28:32 UTC 2015


Git commit ba02d1d3e5a84d4e657e9991ed6b44c279e5fd35 by m.eik michalke.
Committed on 27/10/2015 at 14:12.
Pushed by meikm into branch 'master'.

fixed limitation of only one call in if condidtions (JavaScript)

  - if js() finds an "if" condition, it now translates all calls in the "then" and "else" sections to JavaScript, not just the first one
  - also removed the hacky tryCatch() attempt to look for an "else" section, using length() now

M  +18   -9    packages/rkwarddev/R/rk-internal.R

http://commits.kde.org/rkward/ba02d1d3e5a84d4e657e9991ed6b44c279e5fd35

diff --git a/packages/rkwarddev/R/rk-internal.R b/packages/rkwarddev/R/rk-internal.R
index 9057937..6c7b3db 100644
--- a/packages/rkwarddev/R/rk-internal.R
+++ b/packages/rkwarddev/R/rk-internal.R
@@ -1490,8 +1490,18 @@ replaceJSOperators <- function(..., call="id"){
 # omitting curly brackets that would get in the way with ite()
 uncurl <- function(cond, level=1){
   if(!is.null(cond)){
+    cond.list <- as.list(cond)
+    # NOTE: is it better to check for the bracket or lenght > 1?
     if(identical(as.character(cond[[1]]), "{")){
-      cond <- do.call("js", args=list(cond[[2]], level=level))
+      cond <- paste0(
+        sapply(
+          2:length(cond.list),
+          function(this.cond.num){
+            do.call("js", args=list(cond[[this.cond.num]], level=level))
+          }
+        ),
+        collapse=paste0("\n", paste0(rep("\t", level-1), collapse=""))
+      )
     } else {
       cond <- do.call("js", args=list(cond, level=level))
     }
@@ -1512,16 +1522,15 @@ replaceJSIf <- function(cond, level=1, paste=TRUE){
       cond.then <- do.call("js", args=list(uncurl(cond[[3]], level=level+1), level=level))
     }
     # else do -- could be missing or yet another if condition
-    try.else <- NULL
-    cond.else <- tryCatch(
+    cond.else <- NULL
+    if(length(as.list(cond)) > 3){
       if(inherits(cond[[4]], "if")){
-        try.else <- replaceJSIf(cond[[4]], level=level+1, paste=FALSE)
+        cond.else <- replaceJSIf(cond[[4]], level=level+1, paste=FALSE)
       } else {
-        try.else <- do.call("js", args=list(uncurl(cond[[4]], level=level+1), level=level))
-      },
-      error=function(e) NULL,
-      finally=try.else
-    )
+        cond.else <- do.call("js", args=list(uncurl(cond[[4]], level=level+1), level=level))
+      }
+    } else {}
+
     iteObject <- ite(
       ifjs=cond.if,
       thenjs=cond.then,



More information about the rkward-tracker mailing list