Paul Johnson
2015-Aug-27 14:02 UTC
[Rd] Proposed change in file.exists() to tolerate Windows
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
William Dunlap
2015-Aug-27 14:16 UTC
[Rd] Proposed change in file.exists() to tolerate Windows
## 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 <pauljohn32 at 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 at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
[[alternative HTML version deleted]]
Richard Cotton
2015-Sep-10 11:15 UTC
[Rd] Proposed change in file.exists() to tolerate Windows
Two solutions: 1. Use the wrapper function is_existing_file in assertive. 2. Use standardize_path in pathological before you call file.exists. On 27 August 2015 at 17:02, Paul Johnson <pauljohn32 at 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 at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Regards, Richie Learning R 4dpiecharts.com