4

Is it possible to read files from a UNC-specified directory in R? I'd like to do it without using any packages beyond the base installation.

AnjaM
  • 2,941
  • 8
  • 39
  • 62
  • sorry if this is an ignorant question, but what is a UNC-specified directory? Can we have a little more context? (OK, http://compnetworking.about.com/od/windowsnetworking/g/unc-name.htm ). Can you give an example please? – Ben Bolker Sep 02 '13 at 14:21
  • @BenBolker I don't think there is a way to give an MWE. By UNC, I mean the drive names that start with "\\". Those are unique, while the drive letter might change from one computer to another within a network. I'm writing a script which is to be integrated into a software project. The `R` script is called from the command line and gets a path as an argument where further information (data files etc.) are found. However, `R` seems not to recognize the UNC name, while only UNC names are used within the software project. – AnjaM Sep 03 '13 at 07:12
  • Recognizing that this is years old, but a suitable example would just be an example filepath such as `'\\S:\directory\file.txt'`. – Gregor Thomas May 08 '15 at 19:01

3 Answers3

8

UNC names work fine, you just have to escape them correctly. This works for me:

read.csv('\\\\COMPUTER\\Directory\\file.txt')
nograpes
  • 18,623
  • 1
  • 44
  • 67
4

adding to nograpes answer ... you can avoid the escaping ugliness by using forward slashes ... this works as well

read.csv('//COMPUTER/Directory/file.txt')
DaveH
  • 191
  • 5
4

a slightly more cross-platform approach

# the two '' are required to represent the two leading slashes of the UNC path
read.csv(file.path('', '', 'COMPUTER', 'Directory' 'file.txt'))