[R] eval and tcltk : target of assignment expands to non-language object

peter dalgaard pdalgd at gmail.com
Mon Sep 24 11:26:37 CEST 2012


On Sep 24, 2012, at 10:27 , vincent guyader wrote:

> Hi everyone,
> 
> I have a problem to assign a value with tcl/tk

Not 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]] <- 3
Error 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




More information about the R-help mailing list