我刚开始使用tcltk
和R
。当调用第二个函数myFun1
时,我正在通过名为myFun2
的函数访问计算值时遇到麻烦:
以下是我的用户界面的简化版本:
library(tcltk)
tt <- tktoplevel()
topMenu <- tkmenu(tt)
tkconfigure(tt, menu = topMenu)
fileMenu <- tkmenu(topMenu, tearoff = FALSE)
tkadd(fileMenu, "command", label = "Function1", command = myFun1)
tkadd(fileMenu, "command", label = "Function2", command = myFun2)
tkadd(topMenu, "cascade", label = "Tab", menu = fileMenu)
tkfocus(tt)
myFun1 <- function() {
compVal <- 2*3
compVal
}
myFun2 <- function() {
msg <- paste("The value is: \n", compVal )
mbval<- tkmessageBox(title="This is the title",
message=msg,type="yesno",icon="question")
}
调用myFun1
有效,但myFun2
返回
粘贴错误(“值为:\ n”,compVal): 找不到对象'compVal'
将compVal
包装到return(compVal)
中也不起作用。
我也想做:
res <- list(compVal=compVal)
但我无法使用myFun2
访问创建的列表。
有关如何在myFun1
内找到myFun2
的返回值的任何内容吗?
答案 0 :(得分:0)
I found a solution, at first I thought its not really a "clean" way of doing it, but even in the offical documentation it is done this way.
Simply create a global variable using for (var i = 0; i<= Object.keys(response.result).length; i++ ) {
if(response.result[0].runners[i].runnerName.indexOf('Su Jeong') >0 {
document.body.innerHTML = response.result[0].runners[i].selectionId;
}
}
:
<<-