Skip to content
Prev 360884 / 398506 Next

break string at specified possitions

Hi,

Here is the Biostrings solution in case you need to chop a long
string into hundreds or thousands of fragments (a situation where
base::substring() is very inefficient):

   library(Biostrings)

   ## Call as.character() on the result if you want it back as
   ## a character vector.
   fast_chop_string <- function(x, ends)
   {
     if (!is(x, "XString"))
         x <- as(x, "XString")
     extractAt(x, at=PartitioningByEnd(ends))
   }

Will be much faster than substring (e.g. 100x or 1000x) when
chopping a string like a Human chromosome into hundreds or
thousands of fragments.

Biostrings is a Bioconductor package:

   https://bioconductor.org/packages/Biostrings

Cheers,
H.
On 05/12/2016 01:18 AM, Jan Kacaba wrote: