file.symlink("path/target.txt", "link.txt") does not translate the forward slash to a backslash causing the link to point to a non-existing target.
In help("file.symlink") there is a sentence that may cover this use case:
"User error in supplying invalid file names (and note that ‘foo/’ and ‘foo\’ are invalid on Windows) has undefined consequences."
but it would be helpful if file.symlink() also handles forward slashes like most other R I/O function.
> cat("Hello", file="target.txt")
> file.symlink("target.txt", "link1.txt")
> file.symlink(normalizePath("./target.txt"), "link2.txt")
> file.symlink("./target.txt", "link3.txt")
> bfr <- readChar("target.txt", n=9)
> bfr1 <- readChar("link1.txt", n=9)
> bfr2 <- readChar("link2.txt", n=9)
> bfr3 <- readChar("link3.txt", n=9)
Error in file(con, "rb") : cannot open the connection
In addition: Warning message:
In file(con, "rb") : cannot open file 'link3.txt': Invalid argument
> grep("link", shell('dir link*.txt', intern=TRUE), value=TRUE)
 "01/06/2014 07:07 PM <SYMLINK> link1.txt [target.txt]"
 "01/06/2014 07:07 PM <SYMLINK> link2.txt [C:\\test\target.txt]"
 "01/06/2014 07:07 PM <SYMLINK> link3.txt [./target.txt]"
Note the *forward* slash in the last target.
R Under development (unstable) (2014-01-05 r64665)
Platform: x86_64-w64-mingw32/x64 (64-bit)
 LC_COLLATE=English_United States.1252
 LC_CTYPE=English_United States.1252
 LC_MONETARY=English_United States.1252
 LC_TIME=English_United States.1252
attached base packages:
 stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
R does not translate such calls, with a single exception (mkdir fails on some versions of Windows).
So this is an inconsistency in the Windows system calls: please report to Microsoft.
Patches would most likely be considered, although few of us have systems on which Windows symlinks actually work.
Created attachment 1549 [details]
Makes file.symlink(from, to) translate forward slashes in 'from' to backward slashes
Agree, it's a Windows "feature". The following from the Windows command prompt will give the same problem:
mklink ./target.txt link3.txt
See previous comment for a minimal patch. I've rebuild R from source and verified this patch on Windows 7 Ultimate with NTFS.
The command-line tools do work differently as /A is a flag. But MSDN documents that API calls accept slashes, so the rare exceptions are Windows bugs.
Patches should have LF line endings: CRLF fails (even on the Windows patch.exe I have).
Sorry, that example should have been
mklink link3.txt "./target.txt"
and nothing else.
I never noticed that 'svn diff' (SlikSVN) on Windows outputs CRLF in the diff/patch header (=I've learned something today). For the record, I found the following workaround using only Rtools (and SlikSVN):
svn diff src\main\platform.c | grep "" > platform.c.patch