Convert Backslash File Path to Forward Slash in R

Deepanshu Bhalla 2 Comments

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") {
} else {
cat("Please enter the path:\n\n")
x <- chartr("\\", "/", y)

Follow the steps below to convert backslash FilePath to Forward slash in R.

  1. Run the above code: Once per session. Ignore if already run once.
  2. Copy the path of your file.
  3. Run FSlash().
  4. Press CTRL+V to get the name of your file path.
Related Posts
Spread the Word!
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 2 Responses to "Convert Backslash File Path to Forward Slash in R"
  1. Deepanshu, 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.

Next → ← Prev