Entering edit mode
Hello,
I find it odd that coersion to GRanges with as
fails in the case of an empty data.frame:
This works fine:
> as(data.frame(SeqID=c('s'),start=c(1),end=c(2)),'GRanges')
GRanges object with 1 range and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] s [1, 2] *
-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths
But if the data.frame is empty and untyped, no dice:
> as(data.frame(SeqID=c(),start=c(),end=c()),'GRanges')
Error in .find_start_end_cols(df_colnames0, start.field0, end.field0) :
cannnot determine start/end columns
Taking the diagnostic literally, I type the columns in the data.frame and get a little further
as(data.frame(SeqID=character(),start=integer(),end=integer()),'GRanges')
Error in validObject(.Object) :
invalid class "GRanges" object: NROW(strand(x)) != length(x)
Almost across the line. Let's add the strand in too:
> as(data.frame(SeqID=character(),start=integer(),end=integer(),strand=character()),'GRanges')
GRanges object with 0 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
-------
seqinfo: no sequences
That works.
But, is this truely by design?
At the very least, I would hope that the 3rd example would have worked, with the strand column optional...
Or is there a "good reason" it works just as it does?
Thanks!