[R] Removing named objects using rm(..)
Duncan Murdoch
murdoch.duncan at gmail.com
Tue Dec 11 02:27:31 CET 2012
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
you can still access the one in timeSeries using
timeSeries::USDCHF
Is there a straight forward way of ensuring that when I delete
> a variable by name I delete all copies in scope?
No. It is not straightforward to delete any variables other than the
ones that you created in the global environment.
Duncan Murdoch
>
> Worik
>
>
> On Tue, Dec 11, 2012 at 11:08 AM, Duncan Murdoch
> <murdoch.duncan at gmail.com <mailto:murdoch.duncan at gmail.com>> wrote:
>
> 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 <mailto:R-help at r-project.org> mailing list
> https://stat.ethz.ch/mailman/__listinfo/r-help
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide
> http://www.R-project.org/__posting-guide.html
> <http://www.R-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
More information about the R-help
mailing list