On Tue, Sep 22, 2009 at 7:35 AM, Patrick Aboyoun <paboyoun@fhcrc.org> wrote:

> LiGang,
> The unlist command will get you what you are looking for. AtomicList
> objects should be thought of as typed lists (as.integer on a regular list
> containing integer elements will also throw an error).


Calling as.integer() works on a list where all the elements are of length
one, like with sapply(). This has always been surprising to me. Why would it
work in one case, but not in general? The list structure is implicitly
removed in both. The question is, if IRanges supported as.integer/vector etc
on atomic Lists, would this be more or less surprising to the user? To me
and apparently Li Gang as well, as.integer() sounds like "make this an
atomic integer vector", and there is one obvious way to do that. Would
introducing an inconsistency with the base R list be so bad in this case?

Michael


> Using your example I get:
>
> <<Full code given below>>
> > inter
> CompressedIntegerList: 2 elements
> names(2): chr1 chr2
> > unlist(inter)
> chr1 chr1 chr1 chr2 chr2 chr2 chr2
>  1    2    3   15   45   20    1
> > unlist(inter, use.names=FALSE)
> [1]  1  2  3 15 45 20  1
> > sessionInfo()
> R version 2.10.0 Under development (unstable) (2009-09-21 r49771)
> i386-apple-darwin9.8.0
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> other attached packages:
> [1] IRanges_1.3.78
>
> loaded via a namespace (and not attached):
> [1] tools_2.10.0
>
>
>
> Patrick
>
>
>
> LiGang wrote:
>
>> can not coerce "CompressedIntegerList" to vector or integer
>>
>>
>> #====================================
>> ranges <- IRanges(c(1,2,3),c(4,5,6))
>> filter <- c(1L, 0L, 1L)
>> score <- c(10L, 2L, NA)
>> range2 <- IRanges(start=c(15,45,20,1), end=c(15,100,80,5))
>> both <- c(ranges, range2)
>> score <- c(score, c(0L, 3L, NA, 22L))
>> filter <- c(filter, c(0L, 1L, NA, 0L)) chrom <- paste("chr", rep(c(1,2),
>> c(length(ranges), length(range2))), sep="")
>> rd <- RangedData(both, score, filter, space = chrom, universe = "hg18")
>>
>> start(ranges(rd))->inter
>> as.vector(inter)
>>
>> #Error in as.vector(inter) : # no method for coercing this S4 class to a
>> vector
>>
>> as.integer(inter)
>>
>> #Error in as.integer(inter) : #  cannot coerce type 'S4' to vector of type
>> 'integer'
>> #====================================
>>  sessionInfo()
>> R version 2.10.0 Under development (unstable) (2009-09-14 r49685)
>> i386-pc-mingw32
>> locale:
>> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
>> States.1252    LC_MONETARY=English_United States.1252
>> [4] LC_NUMERIC=C                           LC_TIME=English_United
>> States.1252
>> attached base packages:
>> [1] grid      stats     graphics  grDevices utils     datasets  methods
>> base
>> other attached packages:
>> [1] rtracklayer_1.5.14 RCurl_1.2-0        bitops_1.0-4.1
>> Rgraphviz_1.23.4   graph_1.23.4       IRanges_1.3.77
>> loaded via a namespace (and not attached):
>> [1] Biobase_2.5.6      Biostrings_2.13.40 BSgenome_1.13.12
>> Rcompression_0.6-
>> 0 tools_2.10.0       XML_2.6-0
>>
>>
>>
>> ---
>> LiGang
>>
>> _______________________________________________
>> Bioconductor mailing list
>> Bioconductor@stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/bioconductor
>> Search the archives:
>> http://news.gmane.org/gmane.science.biology.informatics.conductor
>>
>>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor@stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor
>

	[[alternative HTML version deleted]]

