As you know, when dealing with file paths in R, it's essential to keep in mind that R prefers the forward slash format ("/") for specifying file paths. However, on Windows OS, the default file path format is the backward slash format ("\"). Now, the problem is that when you have file paths with backslashes and you're working in R, it can be a real headache to deal with. But don't worry, there's a simple solution.
R Code : Converting backslash file path to forward slash
FSlash<- function(path = "clipboard") { y <- if (path == "clipboard") { readClipboard() } else { cat("Please enter the path:\n\n") readline() } x <- chartr("\\", "/", y) writeClipboard(x) return(x) }
Follow the steps below to convert backslash FilePath to Forward slash in R.
- Run the above code: Once per session. Ignore if already run once.
- Copy the path of your file.
- Run
FSlash()
. - Press CTRL+V to get the name of your file path.
thanks alot
ReplyDeleteDeepanshu, A very neat code! I used to use the 'search & replace' function in Notepad itself to convert BS into FS. Your effort is very elegant. Thanks.
ReplyDeleteThank you. Unlike all the others, this one really works, and even better than expected.
ReplyDeleteGlad you found it useful. Cheers!
Delete