With R regex patterns the "$" has special meaning as the end of a character element (and the 'dots' need to be escaped with \\
, so
shpfils <- list.files(path, pattern="\\.shp$")
题
This is probably real simple, but I can't seem to figure out how to do it.
I have an application in R (Shiny) where a user uploads to the application a *.zip file that contains all the components of an ESRI shapefile. I unpack these files into their own directory. This folder then, may or may not, contain a *.shp.xml file. At some point in my R code, I need to find the exact name of the *.shp file that has been unpacked, and distinguish it from the *.shp.xml file. How do I write the expression that will do that? I was thinking to use list.files, but I am unsure how to write the rest of the expression.
thanks!
解决方案
With R regex patterns the "$" has special meaning as the end of a character element (and the 'dots' need to be escaped with \\
, so
shpfils <- list.files(path, pattern="\\.shp$")
其他提示
This should isolate your file -
Sys.glob("*shp")
as compared to
Sys.glob("*shp*")
which should give both the files
or
Sys.glob("*shp.xml")
which should give the .shp.xml file