All of the read.*
functions use 'scan' under their hoods. scan
is fairly low level but does have the capacity for parsing lines of data into different classes.
> mat <- matrix(scan(), 4,4) # will paste in block of data
1: 0.5 0.1428571 0.25
4: 0.5 0.1428571 0.25
7: 0.5 0.1428571 0.25
10: 0.5 0.1428571 0.25
13: 0.5 0.1428571 0.25
16: 0.5
17: # Terminate with two <cr>'s
Read 16 items
> mat
[,1] [,2] [,3] [,4]
[1,] 0.5000000 0.1428571 0.2500000 0.5000000
[2,] 0.1428571 0.2500000 0.5000000 0.1428571
[3,] 0.2500000 0.5000000 0.1428571 0.2500000
[4,] 0.5000000 0.1428571 0.2500000 0.5000000
> lst <- scan(what=list(double(0), "a"))
1: 4 t
2: 6 h
3: 8 l
4: 8 8
5:
Read 4 records
> lst
[[1]]
[1] 4 6 8 8
[[2]]
[1] "t" "h" "l" "8"
You should also look at the ?connections
page.