I already saw this one, but it is not quite what I need:
Situation: Using gsub
, I want to clean up strings. These are my conditions:
- Keep words only (no digits nor "weird" symbols)
- Keep those words separated with one of (just one)
' - _ $ .
as one. For example:don't
,re-loading
,come_home
,something$col
- keep specific names, such as
package::function
orpackage::function()
So, I have the following:
[^A-Za-z]
([a-z]+)(-|'|_|$)([a-z]+)
([a-z]+(_*)[a-z]+)(::)([a-z]+(_*)[a-z]+)(\(\))*
Examples:
If I have the following:
# Re-loading pkgdown while it's running causes weird behaviour with # the context cache don't
# Needs to handle NA for desc::desc_get()
# Update href of toc anchors , use "-" instead "."
# Keep something$col or here_you::must_stay
I would like to have
Re-loading pkgdown while it's running causes weird behaviour with the context cache don't
Needs to handle NA for desc::desc_get()
Update href of toc anchors use instead
Keep something$col or here_you::must_stay
Problems: I have several:
A. The second expression is not working properly. Right now, it only works with -
or '
B. How do I combine all of these in a single gsub
in R? I want to do something like gsub(myPatterns, myText)
, but don't know how to fix and combine all of this.