Re: [R] Non-standard characters in Ascii-Files

From: Henrik Bengtsson <hb_at_maths.lth.se>
Date: Mon 29 Aug 2005 - 23:43:23 EST

Peter Dalgaard wrote:

> "Schneider, Manuel" <Manuel.Schneider@eawag.ch> writes:
> 
> 

>>Dear R-list
>>
>>In R 2.1.1 under Win XP on a P4 with 2GB Ram when typing
>>
>>>temp<-matrix(c(1:16000000),4000,4000)
>>>write(file="temp.txt", temp)
>>>scan("temp.txt")
>>
>>I receive:
>>Error in scan("temp.txt") : scan() expected 'a real', received '414851'
>>
>>The motivation for evoquing this meassage is that I am getting the same
>>meassage with exported Ascii-Files from the GIS. The files contain very
>>few, randomly scattered non-standard Ascii-characters. This seems to be
>>a local problem on my machine but I do not have a clue on the reason
>>(OS, Memory, HD?) nor who to ask.
>>So, my apologies for misusing this list and many thanks for any
>>suggestion.
> 
> 
> I tried this on a Linux box (with a somewhat outdated R version though),
> and apart from eating up memory and disk space, nothing untoward seems
> to happen:
> 
> 

>>temp<-matrix(c(1:16000000),4000,4000)
>>write(file="/tmp/temp.txt", temp)
>>dummy <- scan("/tmp/temp.txt")
>
> Read 16000000 items

and on my R v2.1.1 patched (2005-08-25) on WinXP Pro SP2 (sic!), I get

 > temp<-matrix(c(1:16000000),4000,4000)
 > write(file="temp.txt", temp)
 > file.info("temp.txt")$size

[1] 136088897
 > rm(temp)
 > dummy <- scan("temp.txt")
Read 16000000 items

> I'd suspect your harddisk or the disk controller...

I second this, check the file with an external application or try the following ad-hoc code:

zcan <- function(filename) {

   fh <- file(filename, open="r");
   on.exit(close(fh));
   count <- 0;
   while(TRUE) {

     s <- readChar(fh, n=1024);
     if (nchar(s) == 0)
       break;
     count <- count + nchar(s);
     if (gsub("[\n 0-9]*", "", s) != "")
       stop("Error after reading ", count, " characters: ", s);
   }
}

Cheers

Henrik



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Aug 29 23:51:13 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 16:01:58 EST