PredictiveEcology/SpaDES

inconsistent treatment of Windows paths

Closed this issue · 3 comments

When using checkPath / normPath when creating directories (e.g., when using a tempdir) on a Windows machine that has a space in the user name I will often get the short (DOS) form of the path returned.

e.g.,
short form: C:\PROGRA~1\
long form: C:\Program Files\

However, the simInit call (either via paths or related) will autoexpand this to the long form, which causes failures during tests because the initial tmpdir no longer matches the one returned by paths(mySim).

I haven't been able to track down where this is occuring, and my workaround when doing package checks/tests is to use an account with no spaces in the username.

Okay I've tracked this down a bit. The issue is with the way that normalizePath works -- although it says it expands short forms of paths, that's only true if the path exists.

> tmpdir <- file.path(tempdir(), 'test_dir')
> normalizePath(tmpdir, winslash = '/', mustWork = FALSE)
[1] "C:/Users/ALEXCH~1/AppData/Local/Temp/RtmpsbcaUe/test_dir"
> normalizePath(tempdir(), winslash = '/', mustWork = FALSE)
[1] "C:/Users/Alex Chubaty/AppData/Local/Temp/RtmpsbcaUe"
> normalizePath(file.path(tempdir(), 'test_dir'), winslash = '/', mustWork = FALSE)
[1] "C:/Users/ALEXCH~1/AppData/Local/Temp/RtmpsbcaUe/test_dir"
> dir.create(tmpdir)
> normalizePath(tmpdir, winslash = '/', mustWork = FALSE)
[1] "C:/Users/Alex Chubaty/AppData/Local/Temp/RtmpsbcaUe/test_dir"
> normalizePath(tempdir(), winslash = '/', mustWork = FALSE)
[1] "C:/Users/Alex Chubaty/AppData/Local/Temp/RtmpsbcaUe"
> normalizePath(file.path(tempdir(), 'test_dir'), winslash = '/', mustWork = FALSE)
[1] "C:/Users/Alex Chubaty/AppData/Local/Temp/RtmpsbcaUe/test_dir"

So this means that by piping the temp dir path directly into checkPath(create = TRUE) at the beginning of tests etc. we ensure that normalizePath (which is used internally) works as expected.

Converting to an absolute file path can fail for a large number of reasons. The most common are
- One of more components of the file path does not exist.

I missed this in my first pass through ?normalizePath because it's not explicit about "failing".

Marking this as closed.