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?
If we want to check the current directory of the R script, we can use getwd( ) function. For getwd( ), no need to pass any parameters. If we run this function we will get the current working directory or current path of the R script.
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)
in addition, the below also works and should be OS agnostic:
read.csv("//shared/data/abc.csv",header=T)
when running getwd() note how the separator between folders is forward slash (/), as it is on Linux and Mac systems.
If you use the Windows operating system, the forward slash will look odd, because you’re familiar with the backslash (\) of Windows folders. When working in Windows, you need to either use the forward slash or escape your backslashes using a double backslash (\\).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With