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"
using paste and "\" to create a valid filename
9 messages · Uwe Ligges, Dirk Eddelbuettel, Bert Gunter +3 more
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
roger bos <roger.bos <at> gmail.com> writes:
Sometimes even the easy stuff is difficult (for me)... I want to get input from different places to paste together an excel filename (so
Have you considered a) the file.path() function, b) the fact that forward slashes also work on Windoze? Your first example, with an outer paste() for the suffix:
paste(file.path("R:", "New Ranks", "SMC", "SMC", "20050819"), ".xls", sep="")
[1] "R:/New Ranks/SMC/SMC/20050819.xls"
Hth, Dirk
... and you can see that the "\\" is correct by cat(rankFile) instead of print(rankFile), which is what entering the variable at the prompt actually does. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box
-----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Uwe Ligges Sent: Friday, August 19, 2005 8:04 AM To: roger bos Cc: r-help at stat.math.ethz.ch Subject: Re: [R] using paste and "\" to create a valid filename 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 ______________________________________________ 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
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
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 file.path() might be an easier solution for this (and it will allow your code to work in a cross-platform manner)
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
Thanks Uwe for the forward slash suggestion, that worked. I believe something has changed inside the RODBC package, because I ran the following code this morning to update my packages: x <- packageStatus(repositories="http://cran.r-project.org/src/contrib") st <- x$avai["Status"] install.packages(rownames(st)[which(st$Status=="not installed")]) I don't know if RODBC was updated and I am not even sure how to find out, but my old code works on my machine I didn't update and doesn't work on the machine I did update. I am not confident enough to file a bug report, but I know something has changed. I will use the forward slash as a workaround for now. Thanks again to everyone, Roger
On 8/19/05, Uwe Ligges <ligges at statistik.uni-dortmund.de> wrote:
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
On Fri, 19 Aug 2005, 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.
Works for me:
odbcConnectExcel("c:\\bdr\\hills.xls")
RODB Connection 1
Details:
case=nochange
DBQ=c:\bdr\hills.xls
DefaultDir=c:\bdr
Driver={Microsoft Excel Driver (*.xls)}
DriverId=790
MaxBufferSize=2048
PageTimeout=5
odbcConnectExcel("c:\bdr\hills.xls")
[1] -1 Warning messages: 1: [RODBC] ERROR: Could not SQLDriverConnect 2: ODBC connection failed in: odbcDriverConnect(con) Please use / as the path separator and become less confused.
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
______________________________________________ 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
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595