[R] Removing named objects using rm(..)

Duncan Murdoch murdoch.duncan at gmail.com
Tue Dec 11 13:05:40 CET 2012


On 12-12-10 8:46 PM, Worik R wrote:
>
>
>
>
> On Tue, Dec 11, 2012 at 2:27 PM, Duncan Murdoch
> <murdoch.duncan at gmail.com <mailto:murdoch.duncan at gmail.com>> wrote:
>
>     On 12-12-10 7:33 PM, Worik R wrote:
>
>         Let me restate my question.
>
>         Is there a straightforward way of ensuring I can use the
>         variable name
>         USDCHF?
>
>
>     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
>
>
> Exactly.  I got around this by assigning NULL to the variable names that
> I would have deleted.  Then instead of testing for existence I tested
> for NULL.

I think you are very confused.  What are you "getting around" by doing 
this?
>
>
>     you can still access the one in timeSeries using
>
>     timeSeries::USDCHF
>
>
> Christ.  That is what I wanted to delete.  I read the scoping section of
> R-Lang (again) and nothing  I could see prepared me for the shock of...
>
>  > library(timeSeries)
>  > nrow(USDCHF)
> [1] 62496
>  > rm(USDCHF)
> Warning message:
> In rm(USDCHF) : object 'USDCHF' not found
>  > nrow(USDCHF)
> [1] 62496
>
>
> The message from rm was that USDCHF did not exist.  But I can still
> access its properties with nrow.

It doesn't exist in the location where you asked to do the remove, i.e. 
in the global environment.

>
> This is very broken.  I would not have believed I would see that in the
> 21st century with a modern language.  (Oh wait, there is Javascript and
> PHP, so in comparison R is not that broken)

I don't know what you think you are seeing, but in this respect R is not 
particularly broken.

> I am not new to R, I have been (mis)using it for 5 years.  I love
> aspects of R, but this and a few other things (lack of debugging support
> and ignoring the "principle of least surprise" are two biggies) are very
> frustrating.  Without debugging support or more help from the compiler
> (like a "cannot rm EURCHF" message instead of a lie) R causes as many
> problems as it solves.

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


>
> Sigh.  Thanks for the help.
>
> Worik
>
>
>
>
>




More information about the R-help mailing list