Closed rossholmberg closed 6 years ago
The stringr package is an alternative to the base regex functions, and plays nice with magrittr piping.
@stillmatic true. stringr
is a very specialist package though, going beyond base
functionality, and therefore deserving of its own package. I'm just hoping for some basic base
function wrappers here, rather than redesigning the functions, as stringr
does.
This is a great idea for a new package, but I don't think these functions belong in magrittr.
Regex operators don't play nice with pipes, so I end up doing things like this a lot:
strings %>% sub( "\\.csv", "", . )
Using the
.
to specify the incoming object.I think it would be nice to wrap a few of these functions, namely
sub
,gsub
,grep
andgrepl
. I think prefixing each withstr_
would work well to differentiate. I'd also personally set the defaultreplacement
parameter insub
andgsub
to""
, since I think string removal is a common use for those functions. That turns the above into:strings %>% str_sub( "\\.csv" )
Here are the wrapper functions I'm suggesting. I'd be happy to make a pull request if you like the idea, just give me the go-ahead if so: