eric chiang
eric chiang

Reputation: 2745

Character arrays as files (Stringbuffers) in R

Is there a way to wrap a character array in a buffer object so it behaves like a file connection? For my particular use case, I happen to have an .RData file as a character array in memory (I know that sounds crazy), and would like to use the load() function without writing it to disk first.

Upvotes: 0

Views: 34

Answers (1)

digEmAll
digEmAll

Reputation: 57210

You can use rawConnection function e.g. :

# this in-memory ASCII .RData  contains: a = 123  and  b = 456
rDataInMem <-
"RDA2
A
2
134915
131840
1026
1
262153
1
a
14
1
123
1026
1
262153
1
b
14
1
456
254
"

# executing this line should appear a = 123  and  b = 456 in the workspace
load(file=rawConnection(object=charToRaw( rDataInMem ),open='r'))

Upvotes: 1

Related Questions