Friday 15 March 2013

backslash - Changing "/" into "\" in R -


I have to change "\" in my "R" code I have something like this:

  tmp & lt; - paste (getwd (), "tmp.xls", sep = "/")   

This is my tmp c: / study / tmp .xls

And I should have it: c: \ study \ tmp.xls

Is it possible to change it in R?

According to the update comments.

If this file is to be saved, as @gababb has suggested, you file.path () :

  File.path (getwd (), "tmp.xls")   

update 2: you want double back-slash

TMP is a string and if you want a real backslash that you have to save - though with a backslash, when r double slash (example For, when looking for a file with the path indicated by the string), it appears that double slash would be considered as one

what happens when you Cat ()

  cat ("c: \\ study \\ tmp" second slash "has disappeared"  

Basic Answer:

has an escape character in r , \ , if so If you really want to print it, then you need to escape the escape character: \\ This is what you want to put in your paste statement. P>

You can also use . $ $ Form.sep platform as your sep argument, which will make your code more portable

  Tmp & lt; - paste (getwd (), "tmp.xls", sep = .platform $ file.sep)   

If you already have a string that you want to change, you

  gsub ("/", "\\", tmp, fixed = TRUE ) Can use    

No comments:

Post a Comment