[R] Reading file from remote location or network drive.
Harsh
singhalblr at gmail.com
Fri Jan 2 08:45:56 CET 2009
Hello,
I'm trying to pull data from a network drive on a windows machine. The
location is read into a string <rem> and then used later with a data
input command.
> rem<- "\\192.192.192.3\Shared\iris1.csv"
Warning messages:
1: '\S' is an unrecognized escape in a character string
2: '\i' is an unrecognized escape in a character string
3: unrecognized escapes removed from "\\192.168.16.3\Shared\iris1.csv"
When using a data input operation
datafile<- read.csv(rem,header= T, sep = ",")
Error in file(file, "r") : cannot open the connection
In addition: Warning message:
In file(file, "r") :
cannot open file '\192.192.192.3Sharediris1.csv': No such file or directory
I have tried to use strsplit to split on "\\"
> strsplit(rem,"\\")
Error in strsplit(rem, "\\") : invalid split pattern '\'
In addition: Warning message:
In strsplit(rem, "\\") : regcomp error: 'Trailing backslash'
Also, I tried to split to extract all characters and this is what I obtained.
> print(strsplit(rem,""))
[[1]]
[1] "\\" "1" "9" "2" "." "1" "6" "8" "." "1" "6" "." "3" "S" "h"
[16] "a" "r" "e" "d" "i" "r" "i" "s" "1" "." "c" "s" "v"
The problem is that, I cannot check for each character and if "\",
convert it to "/".
Ofcourse, if I were to assign
> rem<- "//192.192.192.3/Shared/iris1.csv"
Then rem can be used successfully
> datafile<- read.csv(rem,header= T, sep = ",")
Alternately, I would like to know, if the network drive were to have a
username and password,
how would I be able to pass those parameters in read.csv below
datafile<- read.csv("\\192.168.16.3\Shared\iris1.csv username:user
password:user",header= T, sep = ",")
Thank you,
Harsh Singhal
Mu Sigma Decision Systems Inc.,
Chicago, IL
USA
More information about the R-help
mailing list