[R] strsplit() and Windows file paths

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Thu Oct 29 20:56:58 CET 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of Robert Baer
> Sent: Thursday, October 29, 2009 12:40 PM
> To: r-help at 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
> 
> ---------------------

Hope this is helpful,

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




More information about the R-help mailing list