Learn R Programming

ctypesio (version 0.1.2)

set_integer_promotion: Tag a connection with the preferred integer promotion method for types larger that R's integer type i.e. uint32, uint64, int64

Description

Tag a connection with the preferred integer promotion method for types larger that R's integer type i.e. uint32, uint64, int64

Usage

set_integer_promotion(con, uint32 = "dbl", int64 = "dbl", uint64 = "dbl")

Value

Modified connection object

Arguments

con

Connection object or raw vector. Connection objects can be created with file(), url(), rawConnection() or any of the other many connection creation functions.

uint32, int64, uint64

specifiy separate promotion methods for these types One of: 'dbl', 'hex', 'raw' and 'bit64' (for 64-bit types only) Default: 'dbl'. This default may be over-ridden by specifying the promote argument when calling individual functions.

dbl

Read in integers as doubles. Integer values above 2^53 will lose precision.

hex

Each integer is returned as a hexadecimal string

raw

A single raw vector containing all the integers in their original form

bit64

Return an integer64 vector compatible with the bit64 package. Note. integer64 is a signed 64-bit integer

See Also

Other connection configuration functions: set_bounds_check(), set_endian(), set_eof_check(), set_na_check()

Examples

Run this code
# Open a connection and configure it so all 'uint32' values are 
# read as floating point and all all 'uint64' values are read as hexadecimal strings
con <- rawConnection(as.raw(c(1:7, 0, 1:7, 0, 1:7, 0, 1:7, 0)), "rb")
con <- set_integer_promotion(con, uint32 = "dbl", uint64 = "hex")

# Future reads of uint64 will return hex strings
read_uint64(con, n = 2)

# Unless over-ridden during the read
read_uint64(con, n = 1, promote = "dbl")

close(con)

Run the code above in your browser using DataLab