Meesha Meesha - 3 months ago 12
R Question

Reading a file on a network in R

I am importing a csv file in to R using the read.csv method but get the following error.

The network path is "\\shared\data\abc.csv"

read.csv("\\shared/data/abc.csv",header=T)
or
read.csv("\\shared\\data\\abc.csv",header=T)


If I use copy paste the address in the address bar in the file explorer, it opens the file but R somehow cannot read it. What's the reason? Is it because the network name starts with "//" instead of traditional drive name like C,D etc?

Answer

You need to escape each backslash, so for the double backslash you need four backslashes, i.e.

read.csv("\\\\shared\\data\\abc.csv",header=T)