[rkward] packages/rkwarddev/R: fixed js() issues when called inside local()

m.eik michalke meik.michalke at uni-duesseldorf.de
Sun Nov 8 16:41:45 UTC 2015


Git commit 62aba8d88790ebe4886119fe15599ed008ae9f0c by m.eik michalke.
Committed on 08/11/2015 at 16:36.
Pushed by meikm into branch 'master'.

fixed js() issues when called inside local()

  - preventing evaluation in js() calls led to some confusion regarding the availablility of objects,
    when js() was called in a local() environment. this is hopefully fixed now, but to be honest,
    i wouldn't be surprised if this problem popped up again at some point...

M  +3    -1    packages/rkwarddev/R/js.R
M  +16   -1    packages/rkwarddev/R/rk-internal.R

http://commits.kde.org/rkward/62aba8d88790ebe4886119fe15599ed008ae9f0c

diff --git a/packages/rkwarddev/R/js.R b/packages/rkwarddev/R/js.R
index 8b5cfeb..684836f 100644
--- a/packages/rkwarddev/R/js.R
+++ b/packages/rkwarddev/R/js.R
@@ -61,7 +61,9 @@ js <- function(..., level=2){
     function(this.part){
       # get the object, not just a name from eval(substitute(alist(...)))
       if (is.name(this.part)){
-        this.part <- eval(this.part)
+        # also, if this gets called inside a local() call, make sure we fetch
+        # the referenced object at all
+        this.part <- dynGet(as.character(this.part), ifnotfound=get(as.character(this.part)))
       } else {}
       if(is.call(this.part)){
         # recursively check for if conditions
diff --git a/packages/rkwarddev/R/rk-internal.R b/packages/rkwarddev/R/rk-internal.R
index b22ed2f..604bd0c 100644
--- a/packages/rkwarddev/R/rk-internal.R
+++ b/packages/rkwarddev/R/rk-internal.R
@@ -1452,7 +1452,6 @@ replaceJSOperators <- function(..., call="id"){
       # with the operator as first argument (name).
       # there can also be calls nested in calls so we need to test this recursively
       if(inherits(thisItem, "call")){
-        # break the 
         callList <- unlist(thisItem)
         if(as.character(callList[[1]]) %in% JS.operators){
           result <- list(
@@ -1460,6 +1459,10 @@ replaceJSOperators <- function(..., call="id"){
               do.call("replaceJSOperators", list(callList[[2]]))
             } else if(is.character(callList[[2]])){
               paste0("\"", callList[[2]], "\"")
+            } else if(is.name(callList[[2]])){
+              # if this gets called inside a local() call, make sure we fetch the referenced object at all
+              fetchedObject1 <- dynGet(as.character(callList[[2]]), ifnotfound=get(as.character(callList[[2]])))
+              do.call(call, list(fetchedObject1))
             } else {
               do.call(call, list(callList[[2]]))
             },
@@ -1468,12 +1471,24 @@ replaceJSOperators <- function(..., call="id"){
               do.call("replaceJSOperators", list(callList[[3]]))
             } else if(is.character(callList[[3]])){
               paste0("\"", callList[[3]], "\"")
+            } else if(is.name(callList[[2]])){
+              # same as fetchedObject1 above
+              fetchedObject2 <- dynGet(as.character(callList[[3]]), ifnotfound=get(as.character(callList[[3]])))
+              do.call(call, list(fetchedObject2))
             } else {
               do.call(call, list(callList[[3]]))
             }
           )
           return(paste0(unlist(result), collapse=""))
         } else {
+          # replace object names with the actual objects for evaluation
+          if(length(thisItem) > 1){
+            for (itemParts in 2:length(thisItem)){
+              if(is.name(thisItem[[itemParts]])){
+                thisItem[[itemParts]] <- dynGet(as.character(thisItem[[itemParts]]), ifnotfound=get(as.character(thisItem[[itemParts]])))
+              } else {}
+            }
+          } else {}
           thisItem <- eval(thisItem)
           # R vectors don't make much sense, collapse them for JS
           if(is.vector(thisItem)){



More information about the rkward-tracker mailing list