R tips and tricks – readClipboard

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:

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.

3 comments on “R tips and tricks – readClipboard”

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

Leave a Reply

Your email address will not be published. Required fields are marked *