How to extract specific characters in R String -
i have file name string:
directorylocation<-"\users\me\dropbox\work\" how can extract "\" , replace "\"? in other languages, can loop through string , replace character character, don't think can in r.
i tried
substr(directorylocation,1,1) but highly optimized case...how can more general?
thanks
gsub general tool this, others have noted need confusing 4 slashes account escapes: need escape both r text , regexp engine simultaneously.
an alternative, if using windows, use normalizepath , setting winslash parameter:
normalizepath(directorylocation,winslash="/",mustwork=false) [1] "c:/users/me/dropbox/work/" though may perform additional work on expanding relative paths absolute ones (seen here prepending c:).
Comments
Post a Comment