teamwork

R set working directory using copy and paste

After using Windows Explorer to navigate to a directory, I just want to copy and paste the directory in R, but I get this error:

> setwd("C:\Program Files")
Error: 'P' is an unrecognized escape in character string starting ""C:\P"

I used the setwd() function and pasted the directory, but there is an answer!

By using readline(), you can paste the directory in with no issues:

> setwd(readline())
C:\Program Files # This is where you paste

After hitting enter, you’ll be prompted for the directory. Paste the directory that you copied from Windows Explorer and voila!

You’ve changed your working directory with no path mucking.


About the Author
Avatar

Ray Li

Ray is a software engineer and data enthusiast who has been blogging for over a decade. He loves to learn, teach and grow. You’ll usually find him wrangling data, programming and lifehacking.

Leave a Reply

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

14 + 14 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.