[BioC] no method for coercing this S4 class to a vector

Thiago Maia maia at adylnet.com.br
Mon Mar 11 15:06:52 CET 2013


Hello Martin

     You can ignore the number 1.

function () {
    print(nchar(as.character(seq2[1])))
}

to execute
fn1()


actually the function became like this
function (N) {
     for(i in as.numeric(1:N)) {
         print(substr(seq2[i],nchar(as.character(seq2[i]))-2,nchar(as.character(seq2[i]))))
     }
}


> fn1(3)
Test_4489
     "GGC"
Test_0393
     "CTC"
Test_3575
     "AAT"

with as.character started to give the right result

thanks a lot

Thiago Maia



> On 03/11/2013 06:43 AM, Thiago Maia wrote:
>> Ops... sorry I just found (after many hours), it was so simple, how  
>> could take
>> that long.. heheh
>>
>> nchar(as.character(seq2[i]))
>
> I do not think you've identified your problem correctly; please provide  
> a reproducible example -- what is 'l' ? For instance, after
>
>    library(Biostrings)
>    example(readDNAStringSet)
>
> I can
>
>  > seq2 = readDNAStringSet(filepath, format="fastq")
>  > fn1 = function(N) nchar(seq2[l])
>  > l = 2
>  > fn1(l)
> [1] 36
>
> (but the function doesn't make much sense, usually the body of the  
> function references arguments passed in to it). This is with
>
>  > sessionInfo()
> R version 2.15.2 Patched (2012-12-23 r61401)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> locale:
>   [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
>   [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
>   [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
>   [7] LC_PAPER=C                 LC_NAME=C
>   [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] BSgenome.Celegans.UCSC.ce2_1.3.19 BSgenome_1.26.1
> [3] GenomicRanges_1.10.7              Biostrings_2.26.3
> [5] IRanges_1.16.6                    BiocGenerics_0.4.0
> [7] BiocInstaller_1.8.3
>
> loaded via a namespace (and not attached):
> [1] parallel_2.15.2 stats4_2.15.2   tools_2.15.2
>
> Martin
>>
>> thanks
>>
>> Thiago Maia
>>> Hello
>>>
>>>        - Sorry if this message appear twice, before I sent from the  
>>> wrong
>>> e-mail address(not registered)
>>>
>>>         I trying to make a function in R but I couldnt figure out whats
>>> happening.
>>>
>>>         I loadded a fasta file.
>>>         seq2 <- readDNAStringSet("c:/teste/testfile.txt","fasta")
>>>
>>>         I would like to get the length.
>>>         If I execute directly all works
>>>
>>>         > nchar(seq2[1])
>>>           Test_4489
>>>                  90
>>>
>>>         But if I create a function
>>>         function (N) {
>>>            nchar(seq2[1])
>>>         }
>>>
>>>         when I execute
>>>         > fn1(1)
>>>         Error in nchar(seq2[1]) :
>>>         no method for coercing this S4 class to a vector
>>>
>>>         I tried things like as.vector(nchar(seq2[1])) but got the same
>>> message.
>>>
>>>         Does anybody have a suggestion what I have to do or read.
>>>
>>> thanks a lot
>>>
>>> Thiago Maia
>>>
>>>
>>> --
>>>
>>> _______________________________________________
>>> Bioconductor mailing list
>>> Bioconductor at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/bioconductor
>>> Search the archives:
>>> http://news.gmane.org/gmane.science.biology.informatics.conductor
>>
>>
>> --
>>
>> _______________________________________________
>> Bioconductor mailing list
>> Bioconductor at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/bioconductor
>> Search the archives:
>> http://news.gmane.org/gmane.science.biology.informatics.conductor
>
>


--



More information about the Bioconductor mailing list