AlxRd AlxRd - 11 months ago 70
R Question

How to automate working directory change

I usually switch between Windows and Mac while accessing my R codes from Google Drive. One of the repetitive tasks I need to do whenever I switch between my desktop and laptop is to (un-)comment the file path to the respective directories where my google drive is located. Can anyone share an automation code on how to do this? I am already doing this in Stata.

Answer Source

That's my solution:

setwd(ifelse(.Platform$OS.type=="unix", "/Users/.../Google Drive", "C:/Users/.../Google Drive/"))