Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow digit grouping in coercion from character #17

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions R/IRanges-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,14 @@ setAs("numeric", "NormalIRanges",
error_msg <- wmsg(
"The character vector to convert to an IRanges object must ",
"contain strings of the form \"start-end\" or \"start..end\", ",
"with end >= start - 1, or just \"pos\". For example: \"2501-2900\", ",
"\"2501..2900\", or \"740\"."
"with end >= start - 1, or just \"pos\". pos and end can have ",
"digit group separators in form of a space or a comma. ",
"For example: \"2501-2900\", \"2,501..2,900\", or \"740\"."
)
## We want to split on the first occurence of "-" that is preceeded by
## a digit (ignoring and removing the spaces in between if any).
from <- sub("([[:digit:]])[[:space:]]*-", "\\1..", from)
from <- gsub("[,[:space:]]", "", from)
## We want to split on the first occurence of "-" that is preceeded by
## a digit.
from <- sub("([[:digit:]])-", "\\1..", from)
split2 <- CharacterList(strsplit(from, "..", fixed=TRUE))
split2_eltNROWS <- elementNROWS(split2)
if (!all(split2_eltNROWS <= 2L))
Expand Down