[R] Reading file from remote location or network drive.

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Fri Jan 2 09:22:38 CET 2009


Dear Harsh,

You have to replace each "\" with "\\" or try to use "/" instead.

HTH,

Thierry 


------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be 
www.inbo.be 

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
Namens Harsh
Verzonden: vrijdag 2 januari 2009 8:46
Aan: r-help at r-project.org
Onderwerp: [R] Reading file from remote location or network drive.

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

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.




More information about the R-help mailing list