Skip to content

Removing named objects using rm(..)

13 messages · Duncan Murdoch, William Dunlap, Jeff Newmiller +2 more

#
On 12-12-10 4:40 PM, Worik R wrote:
You didn't import timeSeries, you attached it.  It is on your search 
list; you can see the full list using search().

The first item on the search list is .GlobalEnv, the user's global 
environment.  You can create and delete items there.  You can't easily 
do so in the other items in the search list, they are essentially read-only.
You need to learn more about how R does scoping.  I don't think the 
description in the Intro to R is sufficient; you probably need the R 
Language Definition discussion (or a third party book).

Duncan Murdoch
#
On 12-12-10 7:33 PM, Worik R wrote:
You can use any legal variable name.  The only risk is that you will 
overwrite some other variable that you created.  You can't overwrite 
variables from packages.  (You might mask them, but they are still 
accessible using the :: notation.  E.g. after you set

USDCHF <- NULL

you can still access the one in timeSeries using

timeSeries::USDCHF


  Is there a straight forward way of ensuring that when I delete
No.  It is not straightforward to delete any variables other than the 
ones that you created in the global environment.

Duncan Murdoch
#
You may find it more reliable to define an environment in which you
will be storing your data (perhaps globalenv(), perhaps something created
by new.env())  and then testing for existence of a dataset by a given name
in that environment.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
#
What about putting your objects in a list, which does not have the search through parents semantics?
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.
Worik R <worikr at gmail.com> wrote:

            
#

        
WR> On Tue, Dec 11, 2012 at 7:49 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us>wrote:
>> What about putting your objects in a list, which does not have the search
    >> through parents semantics?
    >> ---------------------------------------------------------------------------
    >> 
    >> 

    >>> 
    >>> You may find it more reliable to define an environment in which you
    >>> will be storing your data (perhaps globalenv(), perhaps something
    >> created
    >>> by new.env())  and then testing for existence of a dataset by a given
    >> name
    >>> in that environment.

    WR> Both  interesting ideas.

Well,  Do follow only Bill Dunlap's.
Using environments is *the way* to add and remove variables,


    WR> Turns out I can remove 'timeSeries' so that  solves my problem but does not
    WR> answer my questions.

When are taught to use  get(),  and it does not immediately do
what you want,
why not read its help page and look at the examples on that help
page ??

[Hint:  The optional argument you want start with 'in..']

Martin
#
On 12-12-10 8:46 PM, Worik R wrote:
I think you are very confused.  What are you "getting around" by doing 
this?
It doesn't exist in the location where you asked to do the remove, i.e. 
in the global environment.
I don't know what you think you are seeing, but in this respect R is not 
particularly broken.
You said "remove USDCHF from the global environment", and R said "object 
'USDCHF' not found".  How is that a lie?  It was never there.

Duncan Murdoch
#
On 12-12-11 12:42 AM, Worik R wrote:
I think if you had followed my advice (reading up on scoping) you 
wouldn't find it so hard.  new.env() creates a new environment whose 
parent (or enclosure) is globalenv().  So when you do a search in 
PAIR.ENV, you'll search there first, then in globalenv(), then in its 
parent, etc.

If you don't want this to happen, don't set globalenv() as the parent. 
emptyenv() is likely what you want instead:

PAIR.ENV <- new.env(parent=emptyenv())

means that only the objects you put there will be found.

Duncan Murdoch