mrdwab / splitstackshape

R functions to split concatenated data, conveniently stack columns of data.frames, and conveniently reshape data.frames.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using concat.split on data containing an apostrophe causes error

IrwinKwan opened this issue · comments

concat.split doesn't appear to like apostrophes in the data column.

> df <- data.frame(experience=c("Did Use, Didn't like"))
> df
            experience
1 Did Use, Didn't like
> concat.split(df, 1)
Error in FUN(NA_integer_[[1L]], ...) : 
  argument must be coercible to non-negative integer

If you try it without, it works fine.

I installed it from the package manager, appears to be v1.2.0.

Mac OS X x64, Mavericks

R 3.0.2

@IrwinKwan, thanks for the reproducible report. It seems to be because of the use of read.table without the "quote" argument.

read.table(text = as.character(df$experience), header = FALSE, sep = ",")
# [1] V1 V2
# <0 rows> (or 0-length row.names)

But:

read.table(text = as.character(df$experience), header = FALSE, sep = ",", quote="")
#        V1           V2
# 1 Did Use  Didn't like

I'll see what can be done to fix this quickly. It may be that just adding the quote = "" to the functions would be sufficient, but I will need to test it on a few more cases.

Resolved by converting concat.split to use cSplit instead of read.concat in 45cd5f8