[Rd] Suggestion/opinions: add a `absolute` param to `normalizePath()` to force returning an absolute path

Dean Attali d@@tt@|| @end|ng |rom gm@||@com
Wed Apr 15 18:59:06 CEST 2020


Thanks Tomas - I can easily believe that other systems have much less
documentation on this issue! Thanks for you work on this.

I try to stick with base packages when possible, but if the `fs` package
provides this functionality then I'm happy to use that in this case, thanks
Jim.

On Wed, 15 Apr 2020 at 10:06, Jim Hester <james.f.hester using gmail.com> wrote:

> The fs[1] function `fs::path_abs()` does what I believe you were
> expecting `normalizePath()` to do in this case. e.g.
>
>     setwd("~")
>     normalizePath("foo/bar")
>     #> Warning in normalizePath("foo/bar") :
>     #> path[1]="foo/bar": No such file or directory
>     #> [1] "foo/bar"
>
>     fs::path_abs("foo/bar")
>     #> /Users/jhester/foo/bar
>
> [1]: https://CRAN.R-project.org/package=fs
>
>
> On Tue, Apr 14, 2020 at 1:03 PM Dean Attali <daattali using gmail.com> wrote:
> >
> > This request stems off a bug report I posted
> > https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17757 where it was
> > determined the current behaviour is as expected.
> >
> > To recap: when given a real file, normalizePath() always* returns the
> full
> > absolute path. When given a non-existent file, normalizePath() returns a
> > full path on Windows but it returns the input on other systems*. I'd
> argue
> > that there are benefits to being able to reliably and consistently get a
> > full path, regardless of whether the file exists or not. In order to not
> > break existing behaviour, I propose adding an argument `absolute = FALSE`
> > that will attempt to return an absolute path when the argument is set to
> > TRUE. I don't have any evidence for this claim, but I believe that others
> > who use this function would expect, like I did, that an absolute path is
> > returned regardless of the file state. I understand the documentation is
> > correct because it warns the absolute path may not be returned, but I
> > believe it would be a useful feature to support.
> >
> >
> > * I've tested this on Win7, Win10, two versions of MacOS, ubuntu. This
> > behaviour may not be true in other OSes
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-devel using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



More information about the R-devel mailing list