readAsRaw.Rd
readAsRaw
takes a connection or file name and reads it into
a raw type.
readAsRaw(con, n, nmax, fileEncoding="")
A connection object or a character string naming a file from which to save the output.
Expected number of bytes to read. Set to 65536L
by
default when con
is a connection, and set to the file size
by default when con
is a character string.
Maximum number of bytes to read; missing of Inf
to read in the entire connection.
When con
is a connection, the file encoding
to use to open the connection.
readAsRaw
returns a raw
type which can then be consumed
by functions like mstrsplit
and dstrsplit
.
mm <- model.matrix(~., iris)
f <- file("iris_mm.io", "wb")
writeBin(as.output(mm), f)
close(f)
m <- mstrsplit(readAsRaw("iris_mm.io"), type="numeric", nsep="\t")
head(mm)
#> (Intercept) Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1 1 5.1 3.5 1.4 0.2
#> 2 1 4.9 3.0 1.4 0.2
#> 3 1 4.7 3.2 1.3 0.2
#> 4 1 4.6 3.1 1.5 0.2
#> 5 1 5.0 3.6 1.4 0.2
#> 6 1 5.4 3.9 1.7 0.4
#> Speciesversicolor Speciesvirginica
#> 1 0 0
#> 2 0 0
#> 3 0 0
#> 4 0 0
#> 5 0 0
#> 6 0 0
head(m)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> 1 1 5.1 3.5 1.4 0.2 0 0
#> 2 1 4.9 3.0 1.4 0.2 0 0
#> 3 1 4.7 3.2 1.3 0.2 0 0
#> 4 1 4.6 3.1 1.5 0.2 0 0
#> 5 1 5.0 3.6 1.4 0.2 0 0
#> 6 1 5.4 3.9 1.7 0.4 0 0
unlink("iris_mm.io")