[R] using paste and "\" to create a valid filename
Uwe Ligges
ligges at statistik.uni-dortmund.de
Fri Aug 19 17:22:13 CEST 2005
Don't know about the details with RODBC here, why not just use forward
slashes as in (used it in all of my courses and never tried "\\"
before....):
rankFile <- paste("R:/New Ranks/SMC/SMC/", rankDate, ".xls", sep="")
Uwe Ligges
roger bos wrote:
> I was surprise myself that I was having problems, because I have been
> doing this for ahile, but I get erros with the RODBC connection. For
> example,
>
> rankFile <- paste("R:\\New Ranks\\SMC\\SMC\\",rankDate,".xls", sep="")
> rankFile
> xls <- odbcConnectExcel(rankFile)
> xls
> rankFile <- "R:\New Ranks\SMC\SMC\20050818.xls"
> rankFile
> xls <- odbcConnectExcel(rankFile)
> xls
>
>
> You won't have my filename, but feel free to try it with any excel
> file you may have. Here is the R output.
>
>
>
>>rankFile <- paste("R:\\New Ranks\\SMC\\SMC\\",rankDate,".xls", sep="")
>>rankFile
>
> [1] "R:\\New Ranks\\SMC\\SMC\\20050819.xls"
>
>>xls <- odbcConnectExcel(rankFile)
>
> Warning messages:
> 1: [RODBC] ERROR: Could not SQLDriverConnect
> 2: ODBC connection failed in: odbcDriverConnect(con)
>
>>xls
>
> [1] -1
>
>>rankFile <- "R:\New Ranks\SMC\SMC\20050818.xls"
>>rankFile
>
> [1] "R:New RanksSMCSMC€50818.xls"
>
>>xls <- odbcConnectExcel(rankFile)
>>xls
>
> RODB Connection 15
> Details:
> case=nochange
> DBQ=R:New RanksSMCSMC€50818.xls
> DefaultDir=R:\NEW RANKS\SMC
> Driver={Microsoft Excel Driver (*.xls)}
> DriverId=790
> MaxBufferSize=2048
> PageTimeout=5
>
>
> On 8/19/05, Uwe Ligges <ligges at statistik.uni-dortmund.de> wrote:
>
>>roger bos wrote:
>>
>>
>>>Sometimes even the easy stuff is difficult (for me)... I want to get
>>>input from different places to paste together an excel filename (so
>>>you know I'm using windows) that I can open with RODBC. I know about
>>>using double "\" since its an escape character, but I get either 2 or
>>>none, I can't get just one "\" where I need it. See example code
>>>below. I am using R 2.1.0, but plan to upgrade soon. Thanks in
>>>advance to anyone who can help.
>>>
>>>Roger
>>>
>>>
>>>rankPath <- "R:\New Ranks\SMC\SMC"
>>>rankDate <- "20050819"
>>>rankFile <- paste(rankPath,rankDate,".xls", sep="")
>>>rankFile
>>>[1] "R:New RanksSMCSMC20050819.xls"
>>>
>>>
>>>rankPath <- "R:\\New Ranks\\SMC\\SMC"
>>>rankDate <- "20050819"
>>>rankFile <- paste(rankPath,rankDate,".xls", sep="")
>>>rankFile
>>>[1] "R:\\New Ranks\\SMC\\SMC20050819.xls"
>>
>>
>>This is perfect, "\" is *printed* escaped, hence for file access you can
>>perfectly use this character vector.
>>
>>Uwe Ligges
>>
>>
>>
>>>______________________________________________
>>>R-help at stat.math.ethz.ch mailing list
>>>https://stat.ethz.ch/mailman/listinfo/r-help
>>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>>
>>
More information about the R-help
mailing list