vincent guyader
2012-Sep-24 08:27 UTC
[R] eval and tcltk : target of assignment expands to non-language object
Hi everyone, I have a problem to assign a value with tcl/tk ths is the code ( it should be simple to understand) : library(tcltk) valA<-tclVar("0") valB<-tclVar("0") valC<-tclVar("0") id<-"A" out<-"1" out2<-"2" print(paste("tclvalue(val",id,")",sep="")) # ok print(as.name(paste("tclvalue(val",id,")",sep=""))) #ok print(eval(as.name(paste("val",id,sep="")))) #seems to be OK print(tclvalue(eval(as.name(paste("val",id,sep=""))))) #ok print("fin") tclvalue(valA)<-out # this is good tclvalue(valA) tclvalue(paste("val",id,sep="")) #dont work but its normal tclvalue(as.name(paste("val",id,sep="")))# dont work... eval(as.name(paste("val",id,sep="")))# ok tclvalue(eval(as.name(paste("val",id,sep=""))))#ok is(eval(as.name(paste("val",id,sep="")))) #that is what I want to do but it dont work : tclvalue(eval(as.name(paste("val",id,sep=""))))<-out2 #>target of assignment expands to non-language object # Have you any idea to do what I want to do? [[alternative HTML version deleted]]
peter dalgaard
2012-Sep-24 09:26 UTC
[R] eval and tcltk : target of assignment expands to non-language object
On Sep 24, 2012, at 10:27 , vincent guyader wrote:> Hi everyone, > > I have a problem to assign a value with tcl/tkNot really. You'll get into the same sort of trouble if you try other kinds of complex assignments:> a <- 1:2 > eval(as.name("a"))[[1]][1] 1> eval(as.name("a"))[[1]] <- 3Error in eval(as.name("a"))[[1]] <- 3 : target of assignment expands to non-language object This is similar to Lumley's fortune("parse"): You may want to rethink the question. Wouldn't l <- list(A=tclVar("0"), B=tclVar("0"), B=tclVar("0")) ... tclvalue(l[[id]]) <- .... do the job much neater? However if you insist, I suspect you need to use bquote() and an outer eval(), as in eval(bquote(.(as.name("a"))[[1]] <- 3))> > ths is the code ( it should be simple to understand) : > > library(tcltk) > > valA<-tclVar("0") > valB<-tclVar("0") > valC<-tclVar("0") > id<-"A" > out<-"1" > out2<-"2" > > print(paste("tclvalue(val",id,")",sep="")) # ok > print(as.name(paste("tclvalue(val",id,")",sep=""))) #ok > print(eval(as.name(paste("val",id,sep="")))) #seems to be OK > print(tclvalue(eval(as.name(paste("val",id,sep=""))))) #ok > print("fin") > > tclvalue(valA)<-out # this is good > tclvalue(valA) > tclvalue(paste("val",id,sep="")) #dont work but its normal > tclvalue(as.name(paste("val",id,sep="")))# dont work... > eval(as.name(paste("val",id,sep="")))# ok > tclvalue(eval(as.name(paste("val",id,sep=""))))#ok > is(eval(as.name(paste("val",id,sep="")))) > > #that is what I want to do but it dont work : > tclvalue(eval(as.name(paste("val",id,sep=""))))<-out2 > #>target of assignment expands to non-language object > > # Have you any idea to do what I want to do? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com