This might be just beyond of my understanding of how assignment works in R, but the documentation does not say anything about:> tv <- c(a="dsf", b="sss") > tl <- list(232) > `$<-`(tl, tv[[1]], "sdfdsfdsfsd")Error: invalid subscript type 'language' This happens even before the method is dispatched. I can not handle the "name" argument in my S4 method, because it's not even entered. Thanks, Vitalie.
spinuvit.list at gmail.com (Vitalie S.) writes:> This might be just beyond of my understanding of how assignment works in R, but > the documentation does not say anything about: > >> tv <- c(a="dsf", b="sss") >> tl <- list(232) >> `$<-`(tl, tv[[1]], "sdfdsfdsfsd") > Error: invalid subscript type 'language' >I can partially solve this with do.call, but there is another problem. Quoted expressions are evaluated during the assignment: te <- new.env()> tq <- quote(print("!!!!")) > do.call("$<-", list(te, "aa", tq))[1] "!!!!" This is some weird do.call and $<- interaction. Does not happen with other functions.> This happens even before the method is dispatched. I can not handle the > "name" argument in my S4 method, because it's not even entered. > > Thanks, > Vitalie.
David Winsemius
2010-Oct-24 13:34 UTC
[Rd] "$<-" fails (invalid subscript type 'language')
On Oct 24, 2010, at 5:35 AM, Vitalie S. wrote:> > This might be just beyond of my understanding of how assignment > works in R, but > the documentation does not say anything about: > >> tv <- c(a="dsf", b="sss") >> tl <- list(232) >> `$<-`(tl, tv[[1]], "sdfdsfdsfsd") > Error: invalid subscript type 'language'Are either of these what you should have done to get what it appears you were aiming for but didn't specify? `$<-`(tl, "sdfdsfdsfsd", tv[[1]]) # yields [[1]] [1] 232 $sdfdsfdsfsd [1] "dsf" > `[<-`(tl, tv[[1]], "sdfdsfdsfsd") [[1]] [1] 232 $dsf [1] "sdfdsfdsfsd" The "$" operator does not evaluate the index whereas the "[" function does. And the documentation is quite clear about that distinction. -- David Winsemius.> > This happens even before the method is dispatched. I can not handle > the > "name" argument in my S4 method, because it's not even entered. > > Thanks, > Vitalie.