[R] How to convert "c:\a\b" to "c:/a/b"

Spencer Graves spencer.graves at pdf.com
Wed Jun 29 05:45:36 CEST 2005


	  Close, but does not work generally with RGui 2.1.1 patched, Windows XP:

 > unback(x="n\o")
[1] "no"

	  I'm also unable to parse "echo", suggested by Ten Harding and Henrik 
Bengtsson:

 > echo D:/spencerg/statmtds/R/Rnews> tmp.txt
Error: syntax error
 > echo cat(gsub("\\\\", "/", readLines("tmp.txt"))) | R --slave
Error: syntax error

	  Earlier today, Sundar Dorai-Raj helped me with the following:

 > (File0 <- file.choose())
[1] "D:\\spencerg\\dataPOWER\\stats\\Tukey\\Boxplot_missing_Tukey2.txt"
 > strsplit(File0, "\\\\")
[[1]]
[1] "D:"                         "spencerg"
[3] "dataPOWER"                  "stats"
[5] "Tukey"                      "Boxplot_missing_Tukey2.txt"

 > fp. <- strsplit(File0, "\\\\")[[1]]
 > (path <- paste(fp.[-length(fp.)], collapse="/"))
[1] "D:/spencerg/dataPOWER/stats/Tukey"
 > setwd(path)
 > getwd()
[1] "D:/spencerg/dataPOWER/stats/Tukey"
 > File <- fp.[length(fp.)]
 > File
[1] "Boxplot_missing_Tukey2.txt"

	  Thanks to everyone who has contributed (or even read) this thread. 
I'm confident that a better method exists.

	  Best Wishes,
	  Spencer Graves
	
David Duffy wrote:

> I couldn't resist adding a more literal answer
> 
> unback <- function(x) {
>   chars <- unlist(strsplit(deparse(x),""))
>   chars <- chars[-c(1,length(chars))]
>   paste(gsub("\\\\","/",chars),collapse="")
> }
> 
> unback("\n")
> 
> 
> | David Duffy (MBBS PhD)                                         ,-_|\
> | email: davidD at qimr.edu.au  ph: INT+61+7+3362-0217 fax: -0101  /     *
> | Epidemiology Unit, Queensland Institute of Medical Research   \_,-._/
> | 300 Herston Rd, Brisbane, Queensland 4029, Australia  GPG 4D0B994A v
> 
> ______________________________________________
> 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

-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915




More information about the R-help mailing list