0

How can I join / concatenate UNC path components in R in a OS agnostic way?

I've found this answer on joining local paths using file.path(), but it seemingly doesn't work on UNC paths.

ascripter
  • 5,665
  • 12
  • 45
  • 68

1 Answers1

0

Your UNC Adress might contain \. R really hates those. If your UNC paths are shown to you as network drive use net use in the commandline (on Windows type cmd in start). There you'll find the remote adress. Then add one \ in front of every \:

like this: \\mydomain.adress.drive\projects to \\\\mydomain.adress.drive\\projects

This happens because R handles \ as marker for escape characters. like \n for new line.

ascripter
  • 5,665
  • 12
  • 45
  • 68
Sandwichnick
  • 1,379
  • 6
  • 13
  • I can't make the script rely on a network drive since the script may be accessed by other people on their system who don't have this drive-alias then. – ascripter Jul 14 '21 at 11:55
  • If your script handles data on a network drive, the unc-adress (e.g.`\\mydomain.adress.drive\projects`) always refers to the same folder. If you got a a personal folder for each user (often users got a personal network drive for their stuff mapping to a folder), you can use the normal alias (e.g`H:`). In my experience this usually works but breaks down if you want to build a package or do other stuff where `R CMD` is called. As the commandline for some reason does not use the alias, but the true unc adress and therefore throws an error. – Sandwichnick Jul 15 '21 at 08:52