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

Duncan Murdoch murdoch.duncan at gmail.com
Mon Dec 10 23:08:56 CET 2012


On 12-12-10 4:40 PM, Worik R wrote:
> When I import the library timeSeries I get (at least) the variable USDCHF
> imported too.
>
> I would like to delete it, but I cannot.  As you can see below.

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.

> Clearly I am doing something wrong.  What is it?

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

>
>> library(timeSeries)
> Loading required package: timeDate
>> class(USDCHF)
> [1] "timeSeries"
> attr(,"package")
> [1] "timeSeries"
>> rm(list=c("USDCHF"))
> Warning message:
> In rm(list = c("USDCHF")) : object 'USDCHF' not found
>> rm(USDCHF)
> Warning message:
> In rm(USDCHF) : object 'USDCHF' not found
>> class(USDCHF)
> [1] "timeSeries"
> attr(,"package")
> [1] "timeSeries"
>>
>
> I can assign to it...
>
>> USDCHF<-NULL
>> class(USDCHF)
> [1] "NULL"
>> get("USDCHF")
> NULL
>>
>
>
> Worik
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list