Prasad, Rajiv
2002-Mar-05 00:41 UTC
[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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thomas Lumley
2002-Mar-05 00:57 UTC
[R] reading 2-byte integers using readBin and connections
On Mon, 4 Mar 2002, Prasad, Rajiv wrote:> > 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". >There is a size= option described in ?readBin size: integer. The number of bytes per element in the byte stream. The default, `NA', uses the natural size. Size changing is not supported for complex vectors. That looks as though it should help. -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Huntsinger, Reid
2002-Mar-05 14:49 UTC
[R] reading 2-byte integers using readBin and connections
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prasad, Rajiv
2002-Mar-05 17:12 UTC
[R] reading 2-byte integers using readBin and connections
Thanks, Thomas. On second (actually that number is a little higher) reading of ?readBin, the size= option hit me right between the eyes. Guess I was not sufficiently caffeinated last evening. ;-) Thanks a lot. Rajiv> On Mon, 4 Mar 2002, Prasad, Rajiv wrote: > > > > > 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". > > > > There is a size= option described in ?readBin > size: integer. The number of bytes per element in the > byte stream. > The default, `NA', uses the natural size. Size changing is > not supported for complex vectors. > > That looks as though it should help. > > -thomas >-------- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._