From lachmann at eva.mpg.de  Fri Aug 12 14:19:16 2011
From: lachmann at eva.mpg.de (Michael Lachmann)
Date: Fri, 12 Aug 2011 14:19:16 +0200
Subject: [Rd] gsub("\\", "\\\\", "C:\Program Files\R")
In-Reply-To: <1313139141809-3738251.post@n4.nabble.com>
References: <1313139141809-3738251.post@n4.nabble.com>
Message-ID: <F2039884-1CD7-4266-93FA-097669EFC152@eva.mpg.de>

Interesting question. It is really about how to avoid the interpretation of \ as an escape character in a string. I wonder if it is possible.

Anyway, have you tried the following:
setwd(readLines("clipboard",warn=F))

"clipboard" is a special filename that tells R to read from the clipboard.

Michael

On 12 Aug 2011, at 10:52AM, mafia88 wrote:

> Hi,
> 
> I think it is not possible in R but I rather ask before giving up:
> 
> What I have: I have copied "C:\Program Files\R" into my clipboard.
> What I want: setwd(transform("C:\Program Files\R")) where the function
> transform should change the "C:\Program Files\R" from my clipboard to
> "C:\\Program Files\\R" so that R can handle it. Is this possible?
> I've tried with gsub("\\", "\\\\", "C:\Program Files\R") but failed, then
> tried first to split the full clipboard string cause \P is reserved in R but
> with strsplit("C:\Program Files\R", "") I also failed.
> 
> Therefore the question: It is really necessary to manually add a second "\"
> in "C:\Program Files\R", so that setwd("C:\\Program Files\\R") can change my
> work directory? 
> Cause I am getting tired making this manually... yes I know I can use the
> Search&Replace function from the Editor but I thought R can do everything?
> 
> I hope someone could help me :(
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/gsub-C-Program-Files-R-tp3738251p3738251.html
> Sent from the R devel mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 
> 



[Rd] gsub("\\", "\\\\", "C:\Program Files\R")
Michael Lachmann