I'd like to create a soft symbolic link to a file from within R on Windows (with Mklink). It fails because I cannot tell R to "run it as administrator". Is there any way I can do this?
I did manage to create hard symbolic file links, however:
path_src <- file.path(tempdir(), "test.txt")
write("Hello World!", file = path_src)
path_tgt <- file.path(tempdir(), "test_symlink.txt")
shell(sprintf("mklink /H %s %s",
normalizePath(path_tgt, mustWork = FALSE),
normalizePath(path_src)
))
Note how the file at path_tgt
reflects the changes made to path_src
:
write("HELLO WORLD!", file = path_src, append = TRUE)
Yet, this fails:
path_tgt_2 <- file.path(tempdir(), "test_symlink_2.txt")
> shell(sprintf("mklink /D %s %s",
normalizePath(path_tgt_2, mustWork = FALSE),
normalizePath(path_src)
))
Ihre Berechtigungen reichen nicht aus, um diesen Vorgang auszufhren.
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c mklink /D C:\Users\Thyson\AppData\Local\Temp\Rtmpum73ZU\test_symlink_2.txt C:\Users\Thyson\AppData\Local\Temp\Rtmpum73ZU\test.txt' had status 1
2: In shell(sprintf("mklink /D %s %s", normalizePath(path_tgt_2, mustWork = FALSE), :
'mklink /D C:\Users\Thyson\AppData\Local\Temp\Rtmpum73ZU\test_symlink_2.txt C:\Users\Thyson\AppData\Local\Temp\Rtmpum73ZU\test.txt' Ausführung mit Fehlerkode 1 fehlgeschlagen
Note
Due to a German version of Windows I can't seem to get the errors in English. The first line translates to somewhat along the lines of "You don't have enough authorization in order to carry out this process"
Sys.setenv(LANGUAGE='en')
– Hagertyshell()
command seems to delegate everything to the basic OS level somehow. – Kanara