Displaying 20 results from an estimated 4000 matches similar to: "help with sockets in R"
2024 Jan 26
1
readChar() could read the whole file by default?
I am curious why readLines() has a default (n=-1L) to read the full
file while readChar() has no default for nchars= (i.e., readChar(file)
is an error). Is there a technical reason for this?
I often[1] see code like paste(readLines(f), collapse="\n") which
would be better served by readChar(), especially given issues with the
global string cache I've come across[2]. But lacking the
2024 Jan 26
1
[External] readChar() could read the whole file by default?
On Fri, 26 Jan 2024, Michael Chirico wrote:
> I am curious why readLines() has a default (n=-1L) to read the full
> file while readChar() has no default for nchars= (i.e., readChar(file)
> is an error). Is there a technical reason for this?
>
> I often[1] see code like paste(readLines(f), collapse="\n") which
> would be better served by readChar(), especially given
2024 Jan 29
1
[External] readChar() could read the whole file by default?
My opinion is that the proposed feature would be greatly appreciated by users.
I had always wondered if I was the only one doing paste(readLines(f),
collapse="\n") all the time.
It would be great to have the proposed, more straightforward way to
read the whole file as a string: readChar("my_file.txt", -1) or even
better readChar("my_file.txt")
Thanks for your detailed
2007 Jun 14
1
Clarification for readChar man page
Hi,
Here's a patch to the readChar manual page (R-trunk as of today) that
better clarifies readChar's return value. It could use some work as I'd
also like to add some text about using nchar() to find the length of the
string that readchar() returns, but I'm unsure which of type="bytes" or
type="chars" to mention. Is it type="chars"?
Index:
2002 Apr 26
4
Memory "leak" in readChar (PR#1483)
Full_Name: Hugh C. Pumphrey
Version: 1.4.1
OS: Linux (Debian Woody)
Submission from: (NULL) (129.215.133.170)
The function readChar() appears to have some type of problem with memory
allocation.
I don't know if "memory leak" is the correct term but if one uses readChar()
many
times, the R binary grows in size until it eats all your memory and swap space.
The code enclosed below
2018 May 26
2
Buffering in R 3.5 connections causes incorrect data in readChar
I noticed an issue where readChar does not return the correct value after a
call to readline. It appears that readChar is not aware of the buffering,
so it reads from the end of the buffer, rather than the current position in
the file. This is a significant change of behavior from R-3.4.4.
Below is a test case that I used to home in on the problem.
---
p<-"test2.txt"
2018 May 29
1
Buffering in R 3.5 connections causes incorrect data in readChar
Tomas,
Thank you for the explanation. I see in the documentation: "These functions
are intended to be used with binary-mode connections." So I see how using
it on a text connection is undefined, and not a bug. An error or warning
when attempting to use a it on a text connection would be helpful
considering how the behavior has changed in R-3.5.
On Tue, May 29, 2018 at 3:09 AM, Tomas
2010 May 05
1
handling nulls while reading mainframe file
Hi,
I am trying to read in records from an old main frame file. Each record is
640 bytes. I had some success using the following statement:
iconv(readChar(con, nchars=640, useBytes =
TRUE),from="IBM037",to="",sub="#")
What I have found, however, is that ocassionally a record will contain a
Null halfway through, which causes readChar() not to read the rest of the
2014 Nov 24
0
How to read variable nr of chars from a Server Socket?
Hi,
I am trying to implement messaging protocol that doesn't pre-specify the
length of the message in the message header. In other words, I don't
know in advance when I will reach the end of the message.
I wrote C level parser for strings but when it came to reading from
connections I got stuck. API in Connections.h doesn't provide a pointer
to an existing connection and there seems
2003 Nov 14
2
writeChar potential buffer overrun (PR#5090)
Trying to copy the (binary) header of a input file directly
to an output file, I've had repeatable seg faults. The call:
writeChar(hdr, outfh, nchars=6144)
when hdr just contains one empty string seems to be the
culprit. The stack traces weren't all that illuminating,
with sig 11 in memory-related functions following this. But
in src/main/connections.c it looks like do_writechar
2001 Dec 07
2
Memory problem
Dear all,
I have written a little R program to convert images. See below. Within the
loop over j (the filenames) memory consumption grows constantly. rm( ... )
inside the loop did not help. Memory does not grow if I remove the writeBin
statements between the two #-------- marks. But obviously this is not
solution I want...
Thanks for any advice.
Manfred Baumstark
P.S. As I'm new to R:
2003 Nov 06
2
Summary: How to represent pure linefeeds chr(10) under R for Windows
Thanks to all who have responded.
My concern was to be able to write a csv file that can have line feeds in
string columns chr(10).
Why? Excel allows line feeds chr(10) within cells and line breaks
chr(13)+chr(10) at line ending,
but the windows version of R automatically replaces \n by \r\n in writing
and \r\n by \n in reading (text mode).
The clues for a solution came from Brian Ripley and
2006 Jul 16
1
Generating valid R code using R
Hi,
I'm trying to generate valid R code using R. Parts of the task is to
read a sequence of characters from file and escape them such that they
can be put in quotation marks to form a valid R code string. Example:
Let the input file be (four rows containing ASCII 0-255 characters):
abcdef<tab>ghijk\nlmno
second row\t\a\\
fourth and so on...
<EOF>
Now, find escapeString() such
2006 Jul 16
1
Generating valid R code using R
Hi,
I'm trying to generate valid R code using R. Parts of the task is to
read a sequence of characters from file and escape them such that they
can be put in quotation marks to form a valid R code string. Example:
Let the input file be (four rows containing ASCII 0-255 characters):
abcdef<tab>ghijk\nlmno
second row\t\a\\
fourth and so on...
<EOF>
Now, find escapeString() such
2012 Jan 13
0
WISHLIST: Be able to timeout readline()/stdin via setTimeLimit in all consoles
Hi.
WISHLIST:
Regardless on console, I'd like to be able to timeout a call to
readline()/file("stdin", blocking=TRUE) via setTimeLimit.
OBSERVATION:
On Windows Rterm as well as plain R on Linux, setTimeLimit() does not
momentarily interrupt from stdin, but only after hitting RETURN. A
few examples:
timeout00 <- function() {
setTimeLimit(elapsed=5);
Sys.sleep(10);
}
2006 Nov 07
1
reading VERY large binary files
Hello,
I am trying to read in elements out of a very large binary file ... the
total file is 4 gigs. I want to select rows out of the file, and the
current procedure I run works but is prohibitively slow (takes more than
a day to run and still won't complete). Is there any faster way to
accomplish this?
My current procedure looks like this:
readHH <- function(file_name,
2005 Nov 03
3
Search within a file
Hi,
I am looking for a way to search a file for position of some expression,
from within R. My current code:
sha1Pos = gregexpr("<sha1>", readChar(filename,
file.info(filename)$size))[[1]]
Works fine for small files, but text files I will be working with might get
up to Gb range, so I was trying to accomplish the same without loading the
whole file into R.
I realize this is
2006 Apr 27
1
Error in readChar(): invalid UTF-8 input
I have R code to read a binary header file, consisting of several
readBin() and readChar() statements. I am currently using version R-2.2.1
(on x86_64, RH EL4) and have received the following error
Error in readChar(fid, n = 1) : invalid UTF-8 input in readChar()
This is strange because (a) I was able to read in this file successfully
in previous versions of R (circa 2005) and (b) it
2007 Dec 09
1
Problems working with large matrix (using package R.huge)
Hi all,
Since I was having several problems trying to work with a large matrix I started to use the package R.huge but I'm having the following problem
> x<-FileByteMatrix("covtype.data",nrow=581012,ncol=55)
Error: cannot allocate vector of size 770.8 Mb
In addition: Warning messages:
1: Reached total allocation of 447Mb: see help(memory.size) in: readChar(con = con, nchar =
2011 Aug 04
1
slightly speeding up readChar()
Hi,
I was trying to have R read files faster with readChar(). That was before I noticed that readChar() is not that bad! In any case, below I suggest a few simple changes that will make readChar slightly faster.
I followed readChar(useBytes=T), and tried to identify all O(N) operations, where N is the size of the file. The assumption is that for LARGE files we want to avoid any O(N) operations,