> -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Nordlund, Dan (DSHS/RDA) > Sent: Thursday, October 29, 2009 12:57 PM > To: r-help@r-project.org > Subject: Re: [R] strsplit() and Windows file paths > > > -----Original Message----- > > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > > Behalf Of Robert Baer > > Sent: Thursday, October 29, 2009 12:40 PM > > To: r-help@r-project.org > > Subject: [R] strsplit() and Windows file paths > > > > There are two ways to express file paths with the Windows environment: > > > a=file.choose() > > > a > > [1] "C:\\Documents and Settings\\rbaer\\Desktop\\_VNT_Test\\coordFocused 20k > > F5 0ng Ki8751 t20.txt" > > > > and > > > > >b= paste(getwd(),"/",dir()[1],sep="") > > >b > > [1] "C:/Documents and Settings/rbaer/Desktop/_VNT_Test/coordFocused 20k F5 > > 0ng Ki8751 t20.txt" > > > > I have 2 questions: > > > > 1. Is it possible to get file.choose() to use the forward slash rather > > than the > escaped > > back slash. It would be nice > > if it were consistent with dir() and getwd() > > Sorry, don't know. > > > > > 2. If one has a path string like the escaped backslash pattern shown in 1 > > above, > > how does one do a strsplit() on these escaped backslashs? > > > > Use "\\\\" ? > > > s <- "C:\\Documents and Settings\\rbaer\\Desktop\\_VNT_Test\\coordFocused > 20k F5 0ng Ki8751 t20.txt" > > strsplit(s,"\\\\") > [[1]] > [1] "C:" > [2] "Documents and Settings" > [3] "rbaer" > [4] "Desktop" > [5] "_VNT_Test" > [6] "coordFocused 20k F5 0ng Ki8751 t20.txt" > > > Thanks, > > Rob > > > > --------------------- >
It was pointed out to me off-list that it would be easier and faster to use strsplit(s,"\\",fixed=TRUE) I will now go back and read ?strsplit more carefully :-). Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.