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

Huntsinger, Reid reid_huntsinger at merck.com
Tue Mar 5 15:49:13 CET 2002


You want to tell readBin that "size=2". 'what="integer"' only specifies the
mode of the resulting vector. You may also need the "signed=FALSE" argument
if you have unsigned quantities and/or the "endian=" argument to get the
byte order right for your platform.

Reid Huntsinger

-----Original Message-----
From: Prasad, Rajiv [mailto:Rajiv.Prasad at pnl.gov]
Sent: Monday, March 04, 2002 7:42 PM
To: R-Help (E-mail)
Subject: [R] reading 2-byte integers using readBin and connections


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     
status                  
major    1              
minor    3.1            
year     2001           
month    08             
day      31             
language R              
>

TIA.

Rajiv
--------
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._

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