r - Can't get read.table to work with stdin without closing buffer -
after googling few days , not finding answer thought i'd post here:
i've got tricky r problem can't seem solve when reading stdin using read.table. unfortunately, due model/process i'm using, readlines , strsplit inefficient - i'd stick read.table if possible gives me 100 times speedup.
anyways, here's situation looks like:
instream = file("stdin","r") while(true){ data_chunk = trycatch(read.table(file=instream,header=false,sep="\t"), error=function(e) null) if(is.null(data_chunk)) break <do r modeling chunk of data...> }
i'm using trycatch check error when hits end of stream , stop loop.
according documentation of read.table, if supply new line or eof stdin stream, should signal read.table stop, , move on - if try continuous stream (even new lines or eofs in stream) hangs waiting stdout buffer close.
is there way read.table - or more efficient way use readlines or something? need able process stdin stream in big chunks without huge performance hit. appreciated!
Comments
Post a Comment