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(){
x <- readClipboard(raw= F)
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.









See also CRAN package “clipr” , which works on all platforms and doesn’t require Rstudio to be involved.
Nice..