[R] Difficulty with "\\" in string functions....

Bernard McGarvey mcg@rvey@bern@rd @end|ng |rom comc@@t@net
Mon Feb 11 21:01:16 CET 2019


I am using the file.choose() function to choose a file from the dialog box and once I get it, I want to be able to split the full name into the folder part and the file name part. So for example, when I have closed the file choose dialog, the name for the file I get is


Fname1
[1] "D:\\Data\\OneDrive\\ISTA Documents\\QT_App\\QT Analysis Input Data Example WorkBook.xlsx"


where the "\\" is used to split the folder and sub-folder and file names. R see this "\\" as a single \ backslash character.


Now I try to split it using


str_split(Fname1,"\\")


but this returns an error


Error in stri_split_regex(string, pattern, n = n, simplify = simplify, :
Unrecognized backslash escape sequence in pattern. (U_REGEX_BAD_ESCAPE_SEQUENCE)


I know its got something to do with the \\ because it is treated as a single backslash character. But replacing the str_split with


str_split(Fname1,"\")


does not work either. 


Any ideas on how I can handle the \\ and split the full name into its pieces?



Lion Bernard McGarvey

Director, Fort Myers Beach Lions Foundation, Inc.

Retired (Lilly Engineering Fellow).



	[[alternative HTML version deleted]]



More information about the R-help mailing list