[R] how to get a primitive function object
Yi Zhang
yizhang84 at gmail.com
Fri Jan 23 19:52:36 CET 2009
On Fri, Jan 23, 2009 at 9:40 AM, Wacek Kusnierczyk
<Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:
> you might want to specify what 'completely unrecoverable' means, and
> what approaches are allowed.
>
> for the former, i guess that:
> - 'incompletely recoverable' means that there is at least one function
> name in the global environment such that its value has been redefined
> and it's not possible, within the session, to revert the binding to the
> original value;
> - 'completely unrecoverable' means that if there are any function names
> with redefined bindings in the global environment, it is not possible,
> within the session, to revert the binding for any of them.
>
> you might also mean the extreme situation where there is no function
> name that has not been redefined and it is not possible to recover the
> original binding for any function name, but i guess this is not what you
> mean. (if you do, then i think the answer is negative, what should be
> fairly easy to prove.)
>
> the two cases are effectively equivalent:
> - if we are in a completely unrecoverable situation, then there is at
> least one function name that cannot be reverted to the original value,
> hence the situation is also incompletely recoverable (for those
> logically inclined, there is one obvious completely unrecoverable
> situation, one in which no function name has been redefined; i'll
> ignore this void case);
> - conversely, if we are in an incompletely recoverable situation with n
> function names redefined of which m are recoverable, recovering those m
> leads to a completely unrecoverable situation.
>
> note, 'unrecoverable' does not necessarily mean useless.
>
> for the latter above (allowed approaches), i hope that using 'assign' is
> ok. you have already hinted a solution; i believe, naively, that it
> satisfies the requirement:
>
> for (f in strsplit('remove rm :: .Primitive .Internal', split=' ')[[1]])
> assign(f, function() 'roobisch')
>
> as far as i can see, this renders a completely unrecoverable, but still
> pretty useful session.
>
>
> vQ
>
> ______________________________________________
> 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.
>
I'm already at a somewhat messy situation, as shown in the following code:
# in .onLoad of a package
env <- as.environment('package:base')
unlockBinding('<-',env)
assign('<-', newAssign, envir=env)
.Internal(lockBinding(as.name('<-'), env)) #not using lockBinding
directly because it calls '<-'
It gave me this error: Error: evaluation nested too deeply: infinite
recursion / options(expressions=)?
I have no clue why infinite recursion...
--
Yi
More information about the R-help
mailing list