[R] Replacing backslashes with slashes

Duncan Golicher dgoliche at sclc.ecosur.mx
Thu Jan 5 19:11:27 CET 2006


It  is often convenient to quickly set the working directory to a path 
copied onto the windows clipboard. A simple trick I have been using for 
a while is along the lines given in the previous posts.

setwd.clip<-function()
{
  options(warn=-1)
  setwd(gsub("\\\\","/",readLines("clipboard")))
  options(warn=0)
  getwd()
}


I load this at the start of every session and then write setwd.clip() 
whenever I have a path I want to change to on the clipboard. You can of 
course write

setwd(gsub("\\\\","/",readLines("clipboard")))

everytime you need it. Obviously it takes longer and there is the minor 
detail that the path read from the clipboard is incomplete (no EOL 
marker) which leads to an unnecessary warning.


Dr Duncan Golicher
Ecologia y Sistematica Terrestre
Conservación de la Biodiversidad
El Colegio de la Frontera Sur
San Cristobal de Las Casas, 
Chiapas, Mexico

Email: dgoliche at sclc.ecosur.mx 

Tel: 967 674 9000 ext 1310
Fax: 967 678 2322
Celular: 044 9671041021

United Kingdom Skypein; 020 7870 6251
Skype name: duncangolicher 
Download Skype from http://www.skype.com




More information about the R-help mailing list