[R] reading 2-byte integers using readBin and connections

Prasad, Rajiv Rajiv.Prasad at pnl.gov
Tue Mar 5 01:41:43 CET 2002

Hi folks:

This may be a stupid question, but I cannot seem to find a way to tell
readBin that I want to read 2-byte integers from the connection.  The input
file is 150,720 bytes long containing 75,360 short (2-byte) integers.  But
specifying "integer" or "int" for what in readBin only returns me a vector
of length 37680, leading me to believe that sizeof(integer) or sizeof(int)
is 4.

> lg.con <- file("../Gridded Data/data_47.3125_-121.3125.bin","rb")
> lg.data <- readBin(lg.con, what="integer", n=75360)
> close(lg.con)
> length(lg.data)
[1] 37680
> lg.con <- file("../Gridded Data/data_47.3125_-121.3125.bin","rb")
> lg.data <- readBin(lg.con, what="int", n=75360)
> close(lg.con)
> length(lg.data)
[1] 37680

What is the data type corresponding to short int?  ?readBin lists "numeric",
"double", "integer", "int", "logical", "complex", and "character" as the
data types -- nothing that seems like a "short".

> version
platform i386-pc-mingw32
arch     x86            
os       Win32          
system   x86, Win32     
major    1              
minor    3.1            
year     2001           
month    08             
day      31             
language R              


Rajiv Prasad
Postdoctoral Research Associate, Hydrology Group
Pacific Northwest National Laboratory, P.O. Box 999, MSIN K9-33
Richland, WA 99352
Voice: (509) 375-2096  Fax: (509) 372-6089  Email: rajiv.prasad at pnl.gov

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list