From spinuvit.list at gmail.com  Mon Oct 25 09:45:40 2010
From: spinuvit.list at gmail.com (Vitalie S.)
Date: Mon, 25 Oct 2010 09:45:40 +0200
Subject: [Rd] "$<-" fails (invalid subscript type 'language')
In-Reply-To: <4CC49EFC.7090801@gmail.com> (Peter Dalgaard's message of "Sun,
	24 Oct 2010 23:02:52 +0200")
References: <cpnwrp7zs2t.fsf@gmail.com>
	<FB9D7384-795F-4EB1-8ABE-A1C1BD11977D@comcast.net>
	<87fwvv7355.fsf@gmail.com> <4CC49EFC.7090801@gmail.com>
Message-ID: <874oca7m1n.fsf@gmail.com>


> There are some things you are not really supposed to mess with in R...
> Computing the index to $-constructs is one of them (trying to set up a
> for loop as a call to `for` is another). It can be done, it's just
> rather painful, and most likely not what you wanted in the first place.
>
Sorry, I was somewhat sloppy and in imprecise. For my class, I really need `$` to behave
as usually [[ behaves in R. So to say, to evaluate the "name" argument.  To be
short, my "$" is part of an user interface (lots of checks, very slow), [[ and
[  are left unattached and are part of "programing" interface for  my classes.

There are not to many symbols in R to use as accessors of the internals of
the objects. Wouldn't  it be natural that the programmer to decide
how to implement his "$" for himself?

> The second argument to `$` and `$<-` is passed unevaluated and expected
> to be of mode "name" (i.e., a symbol). Trying to compute it inline is
> going to pass an unevaluated expression, which has mode "language".
>

I would expect the following to behave identically:

> tv <- c(a="dsf", b="sss")
> tl <- list(232)

> `$<-`(tl, tv[[1]], "sdfdsfdsfsd")
Error: invalid subscript type 'language'

> tl$`tv[[1]]` <- "sdfdsfdsfsd"
> tl
[[1]]
[1] 232

$`tv[[1]]`
[1] "sdfdsfdsfsd"

So what is relay going on? In one case the name is expected, in another case any
"language" object would work?


> If you insist, you can do things like
>
> eval(bquote(`$<-`(x, .(as.name(tv[[1]])), 4343)))
>
> or similar constructs using substitute().
>
> However, the whole situation suggests that you are really looking for
> methods for "[[<-".



[Rd] "$<-" fails (invalid subscript type 'language')
Vitalie S.