Greeting R
Community, 

I am a
windows user so this problem may be specific to windows. I often want to source
files from within R 

such as:
C:\Users\Rinker\Desktop\Research & Law\Data\School Data 09-10. To source
this file I need to go 

through the
path and replace all the backslashes (\) with forward slashes (/). I usually do
this in MS Word

using the
replace option, however, I'd like to do this in R. Attempting to write a
function to do this runs into 

problems: 

When I
enter the following:

readyPath
<- function(path){

z <- gsub("\", "/", path)

return(z)

} 

I get:

>
readyPath <- function(path){

+ z <- gsub("\", "/", path)

+ return(z)

+ }

+  

...meaning
R can't close the sequence (presumably because of the backslash which has
special meaning).

So I tried
(\\):



readyPath <- function(path){

z <- gsub("\\", "/", path)

return(z)

}This allows
the function to be stored as an object but I'm not sure if this is correct.

When I try
the function the backslash gets me again: 

>
readyPath("C:\Users\Rinker\Desktop\Research & Law\Data\School Data
09-10")

Error: '\U' used without hex digits in character string starting
"C:\U" 

This is
what I'd like the function to return:

[1]
"C:/Users/Rinker/Desktop/Research & Law/Data/School Data 09-10" 

I want a
function in which I enter a path and it returns the path with backslashes 

replaced
with forward slashes. Is there a way to make a function to do this? 

Windows 7
user

R version
2.14 beta 

Thank you,

Tyler
Rinker

 

                                          
        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to