Hi All,

The last line if the following code returns the error right below this
paragraph. Essentially, I use the operator %:% to retrieve a variable
in a nested frame. Then I want to use the same operator (with '<-') to
change its value.  I'm not sure if this is possible in R with %:%
operator. Would you please help and let me how to correct the code if
it is possible?

Error in `%:%<-`(`*tmp*`, a, value = 2) : unused argument(s) (value = 2)


#####code###

`%:%`=function(x,y) {
  if(!is.environment(x)) {
    x=as.character(substitute(x))
    x=get(x)
  }
  y=as.character(substitute(y))
  get(y, envir=x)
}

assign('e1', new.env(parent=emptyenv()))
assign('e2', new.env(parent=emptyenv()), envir=e1)
assign('a', 3, envir=get('e2', envir=e1))
e1%:%e2%:%a

`%:%<-`=function(x,y,z) {
  if(!is.environment(x)) {
    x=as.character(substitute(x))
    x=get(x)
  }
  y=as.character(substitute(y))
  assign(y, z, envir=x)
}

e1%:%e2%:%a=2#fails here

-- 
Tom

______________________________________________
R-help@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.

Reply via email to