search for: readchar

Displaying 20 results from an estimated 110 matches for "readchar".

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&...
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...
2006 Nov 07
1
reading VERY large binary files
...(),1,size=2) tran$txn_dn <- readBin(incon,integer(),1,size=2) tran$total_dollars <- readBin(incon,integer(),1,size=4) tran$total_items <- readBin(incon,integer(),1,size=4) tran$order_id <- readBin(incon,integer(),1,size=4) tran$txn_type <- readChar(incon,1) tran$gender <- readChar(incon,1) tran$zip_code <- readChar(incon,5) tran$region_code <- readChar(incon,1) tran$county_code <- readChar(incon,1) tran$state_abbrev <- readChar(incon,2) tran$channel_code <- readChar(incon...
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...
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 analysis Michael. On Fri, Jan 26, 2024 at 2:05?PM luke-tierney--- via R-devel <r-devel at r-project.org> wrote: > > On Fri, 26 Jan 2024, Michael Chirico wrote: > > > I am cur...
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 issues with the > global string cache I...
2018 May 29
1
Buffering in R 3.5 connections causes incorrect data in readChar
...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 Kalibera <tomas.kalibera at gmail.com> wrote: > On 05/26/2018 05:15 AM, Aaron Goodman wrote: > >> 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....
2018 May 29
0
Buffering in R 3.5 connections causes incorrect data in readChar
On 05/26/2018 05:15 AM, Aaron Goodman wrote: > 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 c...
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)...
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 fil...
2009 Sep 04
0
passing character vectors to FORTRAN
..., although I'm no FORTRAN expert, and I would like to hear your thoughts about it. The basic idea is to convert the strings to integers, transfer the resulting integer vector to FORTRAN, and then convert back to characters. Here's an example: ####### start of fortran code subroutine readchar(intstring,stringlengths,totalnchar,nstrings) implicit none C global variables integer totalnchar,nstrings integer intstring(totalnchar),stringlengths(nstrings) C local variables integer j,count, stringLength, i1, i2 parameter(stringLength = 1000) ch...
2007 Dec 09
1
Problems working with large matrix (using package R.huge)
...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 = len) 2: Reached total allocation of 447Mb: see help(memory.size) in: readChar(con = con, nchar = len) 3: Reached total allocation of 447Mb: see help(memory.size) in: readChar(con = con, nchar = len) 4: Reached total allocation of 447Mb: see help(memory.size) in: readChar(con =...
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 demonstrates the problem. As-is, it...
2012 Apr 01
1
scan() vs readChar() speed
...rm(nr*nc),3),nr=nr) write.table(m, file = "a.txt", append=FALSE, row.names = FALSE, col.names = FALSE) scan() is faster than read.table(), as expected, but still quite slow compared to Matlab for example. Based on archived discussions on this list and Stack Overflow, I tried readChar(); it's really fast. However, it returns a long character string, where I really want numeric values. I can use as.numeric(strsplit()), but to my complete surprise it is faster to run scan() on this text string. Consider the following comparison (I use the command line wc to optimize the memory...
2010 Sep 22
1
help with sockets in R
...UT requests. I'm able to make the request and that goes well enough, but I'm having trouble properly consuming the HTTP response. The problem comes in when I'm trying to parse out the response body. I get the length of the response body from the Content-Length header. I then try to use readChar(con, nchars=content.length). The result I'm seeing is that the first few characters of the response body are cut off. My code looks like this: http.request <- function(host, path, request, port=80) { con <- socketConnection(host=host, port=port, open="w+", blocking=TRUE, e...
2017 Sep 12
3
Load R data files
...4-Entering_Data") datahs0csv <- read.table("hs0.csv", header=T, sep=",") attach(datahs0csv) detach(datahs0csv) rm(list=ls()) Then I tried to reload the data, but I got this error message. I am not sure what was wrong. *> load("datahs0csv.rda")* Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection In addition: Warning message: In readChar(con, 5L, useBytes = TRUE) : cannot open compressed file 'datahs0csv.rda', probable reason 'No such file or directory' Any help will be appreciated. with thanks abou ______________...
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 not what R is designed to do, but maybe there is some way I am miss...
2024 Feb 17
1
certain pipe() use cases not working in r-devel
...ic. > > > > In 4.3.2 on macOS, I can successfully roundtrip with the clipboard: > > > >> pb_write <- pipe("pbcopy") > >> writeChar("hello clipboard!", pb_write, eos = NULL) > >> pb_read <- pipe("pbpaste") > >> readChar(pb_read, 16) > > [1] "hello clipboard!" > > > > In r-devel, it appears that the write operation silently does nothing: > > > >> pb_write <- pipe("pbcopy") > >> writeChar("hello clipboard!", pb_write, eos = NULL) > >&gt...
2007 Aug 23
3
RData File Specification?
...#39;,'b','c')) # save into an uncompressed binary R dataset save(ds,file="ds.rdata",compress=FALSE) rm(ds) # Then load() can be simulated like this: # create and open a file connection con <- file("ds.rdata",open="rb") # read the first 5 characters readChar(con,5) # unserialize the remainder and restore to the environment ds <- unserialize(con,NULL)[["ds"]] close(con) But this takes up too much memory if the data set is too big. I can read in the file character-by-character, i.e. using readChar(), but it's obvious that the file form...
2024 Feb 14
2
certain pipe() use cases not working in r-devel
...in the "Clipboard" section of the connections help topic. In 4.3.2 on macOS, I can successfully roundtrip with the clipboard: > pb_write <- pipe("pbcopy") > writeChar("hello clipboard!", pb_write, eos = NULL) > pb_read <- pipe("pbpaste") > readChar(pb_read, 16) [1] "hello clipboard!" In r-devel, it appears that the write operation silently does nothing: > pb_write <- pipe("pbcopy") > writeChar("hello clipboard!", pb_write, eos = NULL) > pb_read <- pipe("pbpaste") > readChar(pb_read,...