Skip to content

Commit d4e3401

Browse files
authored
Merge pull request #75 from alyst/register_rdata
Register R data format
2 parents df1953b + 6e11060 commit d4e3401

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

src/registry.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
### Simple cases
2+
3+
# data formats
24
add_format(format"JLD", "Julia data file (HDF5)", ".jld", [:JLD])
35

6+
# test for RD?2 magic sequence at the beginning of R data input stream
7+
function detect_rdata(io)
8+
seekstart(io)
9+
read(io, UInt8) == UInt8('R') &&
10+
read(io, UInt8) == UInt8('D') &&
11+
(fmt = read(io, UInt8); fmt == UInt8('A') || fmt == UInt8('B') || fmt == UInt8('X')) &&
12+
read(io, UInt8) == UInt8('2') &&
13+
read(io, UInt8) == 0x0A
14+
end
15+
16+
add_format(format"RData", detect_rdata, [".rda", ".RData", ".rdata"], [:RData, LOAD])
17+
418
# Image formats
519
add_format(format"PBMBinary", b"P4", ".pbm", [:ImageMagick])
620
add_format(format"PGMBinary", b"P5", ".pgm", [:Netpbm])

test/files/minimal_ascii.rda

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
RDA2
2+
A
3+
2
4+
196866
5+
131840
6+
1026
7+
1
8+
262153
9+
2
10+
df
11+
787
12+
1
13+
14
14+
2
15+
1.1
16+
2.2
17+
1026
18+
1
19+
262153
20+
5
21+
names
22+
16
23+
1
24+
262153
25+
3
26+
num
27+
1026
28+
1
29+
262153
30+
9
31+
row.names
32+
13
33+
2
34+
NA
35+
-2
36+
1026
37+
1
38+
262153
39+
5
40+
class
41+
16
42+
1
43+
262153
44+
10
45+
data.frame
46+
254
47+
254

test/query.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,15 @@ context("AVI Detection") do
309309
q = query(joinpath(file_dir, "bees.avi"))
310310
@fact typeof(q) --> File{format"AVI"}
311311
end
312+
context("RDA detection") do
313+
q = query(joinpath(file_dir, "minimal_ascii.rda"))
314+
@fact typeof(q) --> File{format"RData"}
315+
open(q) do io
316+
@fact position(io) --> 0
317+
@fact FileIO.detect_rdata(io) --> true
318+
@fact position(io) --> 5
319+
end
320+
end
312321
context("Format with function for magic bytes") do
313322
add_format(format"FUNCTION_FOR_MAGIC_BYTES", x -> 0x00, ".wav", [:WAV])
314323
del_format(format"FUNCTION_FOR_MAGIC_BYTES")

0 commit comments

Comments
 (0)