Re: [R] newbie: closing unused connection + readline

2009-05-18 Thread Aval Sarri
 I don't understand why read.table would have a problem reading
 directly from a socket instead of a textConnection.  Is this a bug?
 Some subtlety in the semantics of socketConnection as opposed to
 textConnection?  Incorrect parameters when opening the
 socketConnection?

No problem with socketConnection and read.table. I want to read a line
at a time but when I use
read.table (socketConnection)  then it waits till client socket
connection is closed; and entire data comes in as one big chunk. I am
reading a line at a time since data will be available after every few
seconds and I can process and obtain results of already generated
data.

Should I use some (eof) character in data so that read.table returns
without client closing socket connection and I can read a line too?

Thanks for your time sir(s).

Regards
-Aval.

__
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] newbie: closing unused connection + readline

2009-05-16 Thread Aval Sarri
Hello;
I am new to R and trying to read a line from socket connection at a
time but at the end of script I am getting closing unused connection
warning. I am not able to understand how to solve this. I want to read
a line from socket and then use read.table/scan on that line but it
looks like I am opening multiple connections instead of just one.  I
think I am doing something wrong or not able to understand correct
method of doing this.

---code
# Create a socket from which to read lines - one at a time (record)
reader.socket -   socketConnection( host = 'localhost', 5000,
 server = TRUE, blocking = TRUE,
 open = r, encoding =
getOption(encoding) );
# now read each record and split/validate it using read.table
repeat {
  # here for each line I am opening new connection! how to avoid it?
  line.raw - textConnection(readLines( reader.socket, n = 1, ok = TRUE));
  line.raw - read.table(line.raw, sep=,);

  if ( length(line.raw)   1)
break;

  print (showConnections());
  print(warnings());
}

__
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] newbie: closing unused connection + readline

2009-05-16 Thread Gabor Grothendieck
Try explicitly closing it:

close(reader.socket)

or

closeAllConnections()

On Sat, May 16, 2009 at 8:34 AM, Aval Sarri aval.sa...@gmail.com wrote:
 Hello;
 I am new to R and trying to read a line from socket connection at a
 time but at the end of script I am getting closing unused connection
 warning. I am not able to understand how to solve this. I want to read
 a line from socket and then use read.table/scan on that line but it
 looks like I am opening multiple connections instead of just one.  I
 think I am doing something wrong or not able to understand correct
 method of doing this.

 ---code
 # Create a socket from which to read lines - one at a time (record)
 reader.socket -   socketConnection( host = 'localhost', 5000,
                                     server = TRUE, blocking = TRUE,
                                     open = r, encoding =
 getOption(encoding) );
 # now read each record and split/validate it using read.table
 repeat {
  # here for each line I am opening new connection! how to avoid it?
  line.raw - textConnection(readLines( reader.socket, n = 1, ok = TRUE));
  line.raw - read.table(line.raw, sep=,);

  if ( length(line.raw)   1)
    break;

  print (showConnections());
  print(warnings());
 }

 __
 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] newbie: closing unused connection + readline

2009-05-16 Thread Aval Sarri
On Sat, May 16, 2009 at 6:12 PM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 Try explicitly closing it:

 close(reader.socket)

 or

 closeAllConnections()

Thank you Sir but is there a way that it does not get open each time?
I mean following line creates a new text connection each time so how
to avoid it or reuse an open connection?

line.raw - textConnection(readLines( reader.socket, n = 1, ok = TRUE));

I tried something line this also:

mydataframe - read.table (socket, sep=,);

but does not work says no input lines.

this also.

mydataframe - read.table (readLine(socket), sep=,);

what is the best method of doing something like this? I am getting
totally lost between textConnection, socket and getConnection.  Now I
am trying to get the connection that was opened and reuse it but then
how do I get connection that was previously opened when running code -
since getConnection() requires a number and for that I need to know
the number of my previously opened connection. So how do I get the
number of textConnection that I open?

Sir any pointers would greatly help.

Thanks and regards
-Aval



 On Sat, May 16, 2009 at 8:34 AM, Aval Sarri aval.sa...@gmail.com wrote:
 Hello;
 I am new to R and trying to read a line from socket connection at a
 time but at the end of script I am getting closing unused connection
 warning. I am not able to understand how to solve this. I want to read
 a line from socket and then use read.table/scan on that line but it
 looks like I am opening multiple connections instead of just one.  I
 think I am doing something wrong or not able to understand correct
 method of doing this.

 ---code
 # Create a socket from which to read lines - one at a time (record)
 reader.socket -   socketConnection( host = 'localhost', 5000,
                                     server = TRUE, blocking = TRUE,
                                     open = r, encoding =
 getOption(encoding) );
 # now read each record and split/validate it using read.table
 repeat {
  # here for each line I am opening new connection! how to avoid it?
  line.raw - textConnection(readLines( reader.socket, n = 1, ok = TRUE));
  line.raw - read.table(line.raw, sep=,);

  if ( length(line.raw)   1)
    break;

  print (showConnections());
  print(warnings());
 }

 __
 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] newbie: closing unused connection + readline

2009-05-16 Thread Stavros Macrakis
On Sat, May 16, 2009 at 8:34 AM, Aval Sarri aval.sa...@gmail.com wrote:
 # Create a socket from which to read lines - one at a time (record)
 reader.socket -   socketConnection( host = 'localhost', 5000,
                                     server = TRUE, blocking = TRUE,
                                     open = r, encoding = 
 getOption(encoding) );
 # now read each record and split/validate it using read.table
 repeat {
  # here for each line I am opening new connection! how to avoid it?
  line.raw - textConnection(readLines( reader.socket, n = 1, ok = TRUE));

What is the function of textConnection here?  Is read.table
incompatible with socketConnection for some reason?

  line.raw - read.table(line.raw, sep=,);

 ...at the end of script I am getting closing unused connection warning

This is not a problem in itself.  For some reason, R gives a warning
when connections are garbage collected.  Of course, that can be a
symptom of poor connection management, but not necessarily.

In the present case, you are creating many unnecessary
textConnections, and R correctly garbage collects them.

-s

__
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] newbie: closing unused connection + readline

2009-05-16 Thread Stavros Macrakis
On Sat, May 16, 2009 at 9:11 AM, Aval Sarri aval.sa...@gmail.com wrote:
 ...I tried something line this also:

 mydataframe - read.table (socket, sep=,);

 but does not work says no input lines.

 this also.

 mydataframe - read.table (readLine(socket), sep=,);

Sorry, I didn't see this before my last email.  This seems to be the
real problem

I don't understand why read.table would have a problem reading
directly from a socket instead of a textConnection.  Is this a bug?
Some subtlety in the semantics of socketConnection as opposed to
textConnection?  Incorrect parameters when opening the
socketConnection?

-s

__
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.