[R] Reanding a windows file
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Mon Feb 20 23:33:49 CET 2006
"Alexandra R. M. de Almeida" <alexandrarma at yahoo.com.br> writes:
> Dear R users
>
> Some one knows how to read a windows file with the adress like
"D:\CSV\Work\test.csv" without change the "\" by "/" by myself?!
> There is some function or parameter that read like the adress windows form.
> I tried to search somethig to substitute the "\" by "/", but I don't find...
Well, there's no problem with the backslashed form except if you try
copying it literally into R source code. If you do, you run into
problems with R interpreting the backslash as an escape character,
which itself needs to be escaped ("doubling the backslashes"). You
might for instance proceed as follows:
> x <- readLines(,1) # input data on next line
D:\CSV\Work\test.csv
> x
[1] "D:\\CSV\\Work\\test.csv"
> mydata <- read.csv(x)
Notice that x as such has only single backslashes, it is just the
print routine that inserts escape characters:
> cat(x,"\n")
D:\CSV\Work\test.csv
> nchar(x)
[1] 20
123456789*123456789*
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list