Re: [R] Warning message about closing a connection XXXX

2012-01-04 Thread Martin Morgan

On 01/04/2012 09:25 AM, Prof Brian Ripley wrote:

On 04/01/2012 17:12, William Dunlap wrote:

Re
> How can I avoid the warning message altogether?

?closeAllConnections

I think of calls to closeAllConnections() in the same
way that I think of calls to rm(list=objects()):
they both can remove things that are not theirs to remove.

Calling gc() will close all unused connections, so
no damage can be done. (I thought that the warning
about closing unused text connections was dropped in
a recent release of R so neither is really needed.)


Yes, it was. The warning is there because the user may need to do
something about the 'other end' of the now-closed connection, which R
manages for textConnections.

There is however one circumstance where gc() does not close all unused
connections, and that is when gzcon() is used (because that involves two
connections and it is not clear when the inner one is 'in use': and we
used to guess wrong).

Rather than using a sledgehammer, use showConnections(all=TRUE) to see
all connections, and close the ones you want to (and its help page shows
you how).


Since connections are using R's finalizers, and order of evaluation of 
finalizers are not reliable, it is not always possible to get in front 
of the automatic close, e.g., when a reference class relies on a 
finalize method to tidy up after itself (perhaps this was also the case 
with gzcon?).


setOldClass(c("file", "connection"))

setRefClass("A", fields=list(x="file"),
methods=list(initialize=function(fname, ...) {
callSuper(x=file(fname, "r"))
}, finalize=function() {
## This sometimes provokes an error
close(.self$x)
}))

getRefClass("A")$new("/tmp")

A desirable feature would allow the message or automatic close to be 
silenced, or the potentially closed connection to be queried for its 
validity.


Martin




Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius
Sent: Wednesday, January 04, 2012 7:10 AM
To: Dan Abner
Cc: r-help@r-project.org
Subject: Re: [R] Warning message about closing a connection 


On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:


Hello everyone,

After running the following code, I obtain this error message.



mydata<- read.table(textConnection(mystring),

+ header=TRUE, sep=",",
+ row.names="id", na.strings=" ")

mydata

Warning message:
closing unused connection 3 (mystring)

=

However, when I attempt to run read.table() again and immediately
submit
the close() function (below), I obtain this message:


close(mystring)

Error in UseMethod("close") :
no applicable method for 'close' applied to an object of class
"character"
=

How can I avoid the warning message altogether?


?closeAllConnections

The error message occurs because "mystring was never the connection
name.

--

David Winsemius, MD
West Hartford, CT

__
R-help@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.


__
R-help@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.






--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793

__
R-help@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.


Re: [R] Warning message about closing a connection XXXX

2012-01-04 Thread peter dalgaard

On Jan 4, 2012, at 19:21 , Duncan Murdoch wrote:

> On 12-01-04 12:25 PM, Prof Brian Ripley wrote:
>> 
>> 
>> Rather than using a sledgehammer, use showConnections(all=TRUE) to see
>> all connections, and close the ones you want to (and its help page shows
>> you how).
> 
> In older versions that do give the warning, wouldn't it be sufficient to name 
> the textConnection, and close it explicitly?  E.g.
> 
> mydata<- read.table(con <- textConnection(mystring),  header=TRUE, sep=",",   
> row.names="id", na.strings=" ")
> 
> close(con)
> 

Or, in recent versions, use the tools designed for the purpose and do

mydata <- read.table(text=mystring, )


-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@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.


Re: [R] Warning message about closing a connection XXXX

2012-01-04 Thread Prof Brian Ripley

On 04/01/2012 18:21, Duncan Murdoch wrote:

On 12-01-04 12:25 PM, Prof Brian Ripley wrote:

On 04/01/2012 17:12, William Dunlap wrote:

Re
> How can I avoid the warning message altogether?

?closeAllConnections

I think of calls to closeAllConnections() in the same
way that I think of calls to rm(list=objects()):
they both can remove things that are not theirs to remove.

Calling gc() will close all unused connections, so
no damage can be done. (I thought that the warning
about closing unused text connections was dropped in
a recent release of R so neither is really needed.)


Yes, it was. The warning is there because the user may need to do
something about the 'other end' of the now-closed connection, which R
manages for textConnections.

There is however one circumstance where gc() does not close all unused
connections, and that is when gzcon() is used (because that involves two
connections and it is not clear when the inner one is 'in use': and we
used to guess wrong).

Rather than using a sledgehammer, use showConnections(all=TRUE) to see
all connections, and close the ones you want to (and its help page shows
you how).


In older versions that do give the warning, wouldn't it be sufficient to
name the textConnection, and close it explicitly? E.g.

mydata<- read.table(con <- textConnection(mystring), header=TRUE,
sep=",", row.names="id", na.strings=" ")

close(con)


Yes, but you cannot do that retrospectively.  I would say this is still 
good practice.



Duncan Murdoch





Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius
Sent: Wednesday, January 04, 2012 7:10 AM
To: Dan Abner
Cc: r-help@r-project.org
Subject: Re: [R] Warning message about closing a connection 


On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:


Hello everyone,

After running the following code, I obtain this error message.



mydata<- read.table(textConnection(mystring),

+ header=TRUE, sep=",",
+ row.names="id", na.strings=" ")

mydata

Warning message:
closing unused connection 3 (mystring)

=

However, when I attempt to run read.table() again and immediately
submit
the close() function (below), I obtain this message:


close(mystring)

Error in UseMethod("close") :
no applicable method for 'close' applied to an object of class
"character"
=

How can I avoid the warning message altogether?


?closeAllConnections

The error message occurs because "mystring was never the connection
name.

--

David Winsemius, MD
West Hartford, CT

__
R-help@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.


__
R-help@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.








--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@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.


Re: [R] Warning message about closing a connection XXXX

2012-01-04 Thread Duncan Murdoch

On 12-01-04 12:25 PM, Prof Brian Ripley wrote:

On 04/01/2012 17:12, William Dunlap wrote:

Re
>   How can I avoid the warning message altogether?

?closeAllConnections

I think of calls to closeAllConnections() in the same
way that I think of calls to rm(list=objects()):
they both can remove things that are not theirs to remove.

Calling gc() will close all unused connections, so
no damage can be done.  (I thought that the warning
about closing unused text connections was dropped in
a recent release of R so neither is really needed.)


Yes, it was.  The warning is there because the user may need to do
something about the 'other end' of the now-closed connection, which R
manages for textConnections.

There is however one circumstance where gc() does not close all unused
connections, and that is when gzcon() is used (because that involves two
connections and it is not clear when the inner one is 'in use': and we
used to guess wrong).

Rather than using a sledgehammer, use showConnections(all=TRUE) to see
all connections, and close the ones you want to (and its help page shows
you how).


In older versions that do give the warning, wouldn't it be sufficient to 
name the textConnection, and close it explicitly?  E.g.


 mydata<- read.table(con <- textConnection(mystring),  header=TRUE, 
sep=",",   row.names="id", na.strings=" ")


 close(con)

Duncan Murdoch





Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of David Winsemius
Sent: Wednesday, January 04, 2012 7:10 AM
To: Dan Abner
Cc: r-help@r-project.org
Subject: Re: [R] Warning message about closing a connection 


On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:


Hello everyone,

After running the following code, I obtain this error message.



mydata<- read.table(textConnection(mystring),

+header=TRUE, sep=",",
+row.names="id", na.strings=" ")

mydata

Warning message:
closing unused connection 3 (mystring)

=

However, when I attempt to run read.table() again and immediately
submit
the close() function (below), I obtain this message:


close(mystring)

Error in UseMethod("close") :
   no applicable method for 'close' applied to an object of class
"character"
=

How can I avoid the warning message altogether?


?closeAllConnections

The error message occurs because "mystring was never the connection
name.

--

David Winsemius, MD
West Hartford, CT

__
R-help@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.


__
R-help@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.





__
R-help@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.


Re: [R] Warning message about closing a connection XXXX

2012-01-04 Thread Prof Brian Ripley

On 04/01/2012 17:12, William Dunlap wrote:

Re
   >  How can I avoid the warning message altogether?

   ?closeAllConnections

I think of calls to closeAllConnections() in the same
way that I think of calls to rm(list=objects()):
they both can remove things that are not theirs to remove.

Calling gc() will close all unused connections, so
no damage can be done.  (I thought that the warning
about closing unused text connections was dropped in
a recent release of R so neither is really needed.)


Yes, it was.  The warning is there because the user may need to do 
something about the 'other end' of the now-closed connection, which R 
manages for textConnections.


There is however one circumstance where gc() does not close all unused 
connections, and that is when gzcon() is used (because that involves two 
connections and it is not clear when the inner one is 'in use': and we 
used to guess wrong).


Rather than using a sledgehammer, use showConnections(all=TRUE) to see 
all connections, and close the ones you want to (and its help page shows 
you how).



Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of David Winsemius
Sent: Wednesday, January 04, 2012 7:10 AM
To: Dan Abner
Cc: r-help@r-project.org
Subject: Re: [R] Warning message about closing a connection 


On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:


Hello everyone,

After running the following code, I obtain this error message.



mydata<- read.table(textConnection(mystring),

+header=TRUE, sep=",",
+row.names="id", na.strings=" ")

mydata

Warning message:
closing unused connection 3 (mystring)

=

However, when I attempt to run read.table() again and immediately
submit
the close() function (below), I obtain this message:


close(mystring)

Error in UseMethod("close") :
  no applicable method for 'close' applied to an object of class
"character"
=

How can I avoid the warning message altogether?


?closeAllConnections

The error message occurs because "mystring was never the connection
name.

--

David Winsemius, MD
West Hartford, CT

__
R-help@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.


__
R-help@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.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@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.


Re: [R] Warning message about closing a connection XXXX

2012-01-04 Thread William Dunlap
Re
  > How can I avoid the warning message altogether?
  
  ?closeAllConnections

I think of calls to closeAllConnections() in the same
way that I think of calls to rm(list=objects()):
they both can remove things that are not theirs to remove.

Calling gc() will close all unused connections, so
no damage can be done.  (I thought that the warning
about closing unused text connections was dropped in
a recent release of R so neither is really needed.)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
 
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of David Winsemius
> Sent: Wednesday, January 04, 2012 7:10 AM
> To: Dan Abner
> Cc: r-help@r-project.org
> Subject: Re: [R] Warning message about closing a connection 
> 
> 
> On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:
> 
> > Hello everyone,
> >
> > After running the following code, I obtain this error message.
> >
> >
> >> mydata <- read.table(textConnection(mystring),
> > +header=TRUE, sep=",",
> > +row.names="id", na.strings=" ")
> >> mydata
> > Warning message:
> > closing unused connection 3 (mystring)
> >
> > =
> >
> > However, when I attempt to run read.table() again and immediately
> > submit
> > the close() function (below), I obtain this message:
> >
> >> close(mystring)
> > Error in UseMethod("close") :
> >  no applicable method for 'close' applied to an object of class
> > "character"
> > =
> >
> > How can I avoid the warning message altogether?
> 
> ?closeAllConnections
> 
> The error message occurs because "mystring was never the connection
> name.
> 
> --
> 
> David Winsemius, MD
> West Hartford, CT
> 
> __
> R-help@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.

__
R-help@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.


Re: [R] Warning message about closing a connection XXXX

2012-01-04 Thread David Winsemius


On Jan 4, 2012, at 9:53 AM, Dan Abner wrote:


Hello everyone,

After running the following code, I obtain this error message.



mydata <- read.table(textConnection(mystring),

+header=TRUE, sep=",",
+row.names="id", na.strings=" ")

mydata

Warning message:
closing unused connection 3 (mystring)

=

However, when I attempt to run read.table() again and immediately  
submit

the close() function (below), I obtain this message:


close(mystring)

Error in UseMethod("close") :
 no applicable method for 'close' applied to an object of class  
"character"

=

How can I avoid the warning message altogether?


?closeAllConnections

The error message occurs because "mystring was never the connection  
name.


--

David Winsemius, MD
West Hartford, CT

__
R-help@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.