0

I am trying to create some soft links with R and I am having a hard time with the single and double quotes.

Currently, I am doing this: system(paste("mklink /d '", paste0(softlink,"/input_data"),"' '", Inputfolder, "'", sep=""))

Where:

softlink = "D:/users/target" and Inputfolder = "D:/users/input_data/"

However, when I am running it, it gives an error: "Running command 'mklink... had status 127'. Thus, I would like to get the following line, as I think this way it would work.

"mklink /d "D:/users/target/input_data" "D:/users/input_data/""

Unfortunately, whatever I have tried so far could not handle these quotes inside quotes. Could someone please help me to obtain the wanted line?

Thank you in advance.

2 Answers2

2

Try something like:

path1 <- file.path(softlink, "/input_data")
path2 <- file.path(Inputfolder)
sprintf("mklink /d %s %s", normalizePath(path1), normalizePath(path2))
CPak
  • 13,260
  • 3
  • 30
  • 48
1

The standard way is to escape quotation marks:

system(paste("mklink /d \"", paste0(softlink,"/input_data"),"\" \"", Inputfolder, "\"", sep=""))
psychOle
  • 1,054
  • 9
  • 19
  • Thank you for your answer. I have tried this method already but then I will get the following thing as a result of the outer paste: "mklink /d \"D:/users/target/input_data/\" \"D:/users/input_data/\"" and if I apply a system to this it will not create the soft links. – Reider Ladislau Jun 12 '17 at 15:55
  • How could I delete these unnecessary \s?:) – Reider Ladislau Jun 12 '17 at 16:12
  • Just a thought: Your are on Windows, right? Shouldn't it be `D:\users\input_data\ ` then (mind the backward slashes)? Besides, if you don't have spaces in your directories, you don't need any `"` at all, imho. – psychOle Jun 12 '17 at 16:52
  • Yes, I am on Windows, I tried the shell command as well but still it doesn't work. It gives execution failed with error code 1. About the backward slashes, that was the first way I tried with D:\users\input_data\ as this is how I can manually create the soft links from the cmd, but it doesn't work from R. I am starting to think that is is a problem with admin privileages. DO you have any idea how I could solve this issue? – Reider Ladislau Jun 13 '17 at 06:54
  • Well, mklink need admin rights ([see here](https://superuser.com/questions/124679/how-do-i-create-a-link-in-windows-7-home-premium-as-a-regular-user)). If it's a rights problem, you'd move over to [superuser](https://superuser.com). – psychOle Jun 13 '17 at 07:34
  • Well, just to be clear, I can create the softlinks using the cmd window, so I have the admin rights to create them. My problem is that I cannot create them from R. And as I have to create around 30.000 softlinks I would like to automate the process in R:) – Reider Ladislau Jun 13 '17 at 07:49