Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Here is a small utility function to save you some boring work.

Say you have a file to read into R. The file path is C:\Users\folder1\folder2\folder3\mydata.csv. So what do you do? you copy the path, paste it to the editor, and start reversing the backslash into a forward slash so that R can read your file.

With the help of the rstudioapi package, the readClipboard function and the following function:

get_path <- function(){
rstudioapi::insertText( paste("#",x, "\n") )
x
}

You can
1. Simply copy the path C:\Users\folder1\folder2\folder3\mydata.csv
2. execute pathh <- get_path()
3. use pathh which is now R-ready.

No more reversing or escaping backslash.