[R] how to get a primitive function object

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Jan 23 15:40:39 CET 2009


Duncan Murdoch wrote:
> Wacek Kusnierczyk wrote:
>> Duncan Murdoch wrote:
>>  
>>> You can use parent.frame() as the pos or envir argument to assign(),
>>> and then the assignment happens in the caller's frame.  And assign()
>>> is also  another way out if you overwrite <- with something that
>>> doesn't work; just call it to reassign base::`<-` to it.  Or just
>>> rm(`<-`) to unhide the original one.
>>>     
>>
>> unless you have redefined rm as well, that is.
>
> Right, but then there's remove, or base::rm.  Unless you redefined
> remove and `::`.
>
> So here's the question for a frustrating contest:  is it possible to
> define enough functions in the global environment to render your R
> session completely unrecoverable?  (I think it probably is.)  And
> what's the minimal set, or the minimal script to brick your R?  No
> manipulating the search list or writing anywhere but the global
> environment is allowed.
> Duncan Murdoch

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




More information about the R-help mailing list