## delete trailing slashes dts <- function(name) gsub("/$", "", name) if(!file.exists(dts(any_name))) { ...
I don't think you want to delete the slash in "C:/" on Windows, as "C:" is not a file and "C:/" is. normalizePath() does odd things with "C:" as well. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Aug 27, 2015 at 7:02 AM, Paul Johnson <pauljoh...@gmail.com> wrote: > I'm writing to ask if R Core would make file.exists more Windows > tolerant when the argument has a trailing slash. This has been > discussed by users a few times here, I know it is not a new topic. But > it is not a solved problem, yet. I acknowledge that CRAN packages > exist which fix this by replacing file.exists(), but it seems more > elegant to me to fix the problem in R itself. > > R Core goes to great extremes to accommodate Windows users and the > refusal to make file.exists() work in a cross-platform way is > incongruous. > > I often do have slashes on the end of directory names being tested. > Now that I understand the meaning of ?file.exists, I need to wrap the > name being checked in a slash-deleter > > ## delete trailing slashes > dts <- function(name) gsub("/$", "", name) > if(!file.exists(dts(any_name))) { ... > > Can't you make file.exists do this invisibly? Maybe the argument could > be filtered through normalizePath() instead. > > If not, would you please consider putting a workaround like mine into > the file.exists documentation so Windows users can see how easy this > is to avoid? > > Respectfully yours, > > pj > > -- > Paul E. Johnson > Professor, Political Science Director > 1541 Lilac Lane, Room 504 Center for Research Methods > University of Kansas University of Kansas > http://pj.freefaculty.org http://crmda.ku.edu > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel