Skip to content
Merged
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
52 changes: 23 additions & 29 deletions R/mergingandstackingutilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -326,39 +326,33 @@ splitByComma <- function(input.text, ignore.commas.in.parentheses = FALSE)
split.text <- trimws(strsplit(input.text, ",")[[1]])
return(split.text[split.text != ""])
}
else
split.char <- strsplit(input.text, "")[[1]]
result <- c()
start.ind <- NA_integer_
in.parentheses <- FALSE
for (i in seq_along(split.char))
{
split.char <- strsplit(input.text, "")[[1]]
result <- c()
start.ind <- NA_integer_
in.parentheses <- FALSE
for (i in seq_along(split.char))
if (is.na(start.ind))
{
if (is.na(start.ind))
{
if (split.char[i] != ",")
start.ind <- i
else
next
}
if (split.char[i] != ",")
start.ind <- i
else
next
}

if (!in.parentheses && split.char[i] == ",")
{
result <- c(result, paste0(split.char[start.ind:(i - 1)],
collapse = ""))
start.ind <- NA_integer_
}
else if (i == length(split.char))
result <- c(result, paste0(split.char[start.ind:i],
collapse = ""))
else if (!in.parentheses && split.char[i] == "(")
in.parentheses <- TRUE
else if (in.parentheses && split.char[i] == ")")
in.parentheses <- FALSE
if (!in.parentheses && split.char[i] == ",")
{
result <- c(result, paste0(split.char[start.ind:(i - 1)],
collapse = ""))
start.ind <- NA_integer_
}
result <- trimws(result)
result <- result[result != ""]
result
else if (i == length(split.char))
result <- c(result, paste0(split.char[start.ind:i],
collapse = ""))
else if (!in.parentheses && split.char[i] == "(")
in.parentheses <- TRUE
else if (in.parentheses && split.char[i] == ")")
in.parentheses <- FALSE
}
result <- trimws(result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that since the if case returns early, you can remove the else to reduce nesting and reduce the chance of these mistakes

result <- result[result != ""]
Expand Down
Loading