[R] Strplit code

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Dec 5 12:20:36 CET 2008

John Fox wrote:
> Dear Wacek,
> I've thought a bit more about this problem, and recall that I originally
> wrote Strsplit() [and replacements for sub() and gsub(), which were not then
> in S-PLUS] for the version of the car package that I released for S-PLUS,
> because other functions in the package used these. The strings involved were
> small, so performance issues weren't that important, although of course it's
> better to have a more efficient solution.

right.  the speedup is not due to any substantial algorithmic
difference, but rather in that your code is r code, while mine uses
gregexpr, which is i assume is precompiled from c code or the like.

about 'wrong' and 'flawed', again:  what i meant is that as a suggestion
for how strsplit, in general, could be written, it doesn't meet the
challenge, and should at least issue a warning if the split pattern
specifies non-1-length splits.  otherwise, it could be perfectly fit for
a student's exercise.

> Although I no longer have an installed copy of S-PLUS to confirm this, I
> believe that gregexepr() is still not present in S-PLUS (though I think that
> strsplit() is in the latest version). If that's the case, then your function
> wouldn't work at all in the context of the original posting, which asked for
> a solution in S-PLUS. You could make your code work in S-PLUS, and probably
> still have it more efficient than mine, by writing a replacement for
> gregexpr().

possibly, and then it's my code that is wrong and flawed ;)
i haven't used s-plus for ages, jumping to the global frame instead of
lexical scoping scared me away.


More information about the R-help mailing list