An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121211/0df75897/attachment.pl>
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:
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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121211/1e225c6d/attachment.pl>
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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121211/78542a00/attachment.pl>
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.
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
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Worik R Sent: Monday, December 10, 2012 5:47 PM To: Duncan Murdoch Cc: r-help Subject: Re: [R] Removing named objects using rm(..) On Tue, Dec 11, 2012 at 2:27 PM, Duncan Murdoch <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.
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. 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 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. Sigh. Thanks for the help. 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121211/220860e5/attachment.pl>
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:
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.
I did that.
PAIR.ENV <- new.env()
....
get("USDCHF", env=PAIR.ENV)
returns trhe USDCHF defined in timeSeries
This is very hard!
Worik
Bill Dunlap
Spotfire, TIBCO Software wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org]
On Behalf
Of Worik R Sent: Monday, December 10, 2012 5:47 PM To: Duncan Murdoch Cc: r-help Subject: Re: [R] Removing named objects using rm(..) On Tue, Dec 11, 2012 at 2:27 PM, Duncan Murdoch <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.
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. 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 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. Sigh. Thanks for the help. 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.
[[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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121211/2371f2d2/attachment.pl>
"WR" == Worik R <worikr at gmail.com>
on Tue, 11 Dec 2012 19:59:58 +1300 writes:
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:
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
On 12-12-11 12:42 AM, Worik R wrote:
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.
I did that.
PAIR.ENV <- new.env()
....
get("USDCHF", env=PAIR.ENV)
returns trhe USDCHF defined in timeSeries
This is very hard!
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
Worik Bill Dunlap
Spotfire, TIBCO Software wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf
Of Worik R Sent: Monday, December 10, 2012 5:47 PM To: Duncan Murdoch Cc: r-help Subject: Re: [R] Removing named objects using rm(..) On Tue, Dec 11, 2012 at 2:27 PM, Duncan Murdoch <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.
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. 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 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. Sigh. Thanks for the help. 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.
[[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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121211/f82c18a2/attachment.pl>