IDE configuration to work between Linux and Windows

Hello Rstudio Community!

I would like to know which is the best way to construct the script (Rmarkdown) and the paths in order to use with Rstudio across multiple devices (in my case with Rstudio Linux, Rstudio Server Linux, and Rtudio Windows 10; using dropbox as the working directory). I saw here the recommendations by Grolemund and Wickham, so creating projects would be the best solution?


1 Like

I work between Mac and PC (home and work, respectively), so I guess my pain is similar in some ways.
Although, in my case, 2 worlds rarely intersect - at work, I work on work projects, and at home - I work on home projects.

I can't offer a complete process (I don't have one, shame on me!), but I've got a few tips:

  • the segment you quoted from R for DS book, times ten. Setting up a working directory is the first step.
  • I've found that while local directories can be unique on every machine, web links are usually all the same. In my work, I frequently reference files via a web link and not via its location on the drive. So, let's say you have a folder on your local drive that syncs to the web (Dropbox, G Drive, Sharepoint etc). Using a web link for that file will make your code reproducible and scalable, while setting the path to User/your_name/some_folder/some_file will warrant @jennybryan to come to your office and set your machine on fire.
  • sometimes, when I'm lazy, I create 2 paths, path_mac and path_pc, and use them interchangeably. There is a way for R to figure out your OS, so you can make it a function with a simple if_else switch, and let your script pick the path you need. But this is definitely not the best approach. Quick and dirty, but I wouldn't use it in production.
1 Like

As well as using projects in RStudio, it might also be worth checking out the here package.

it implements a here() function which is a drop in replacement for file.path() and locates files relative to your project root.

You'll find it on CRAN here :joy:


I'm more interested in the workflow of keeping both machines updated as far as R, RStudio and installed packages go.
It is such a pain in the *** for me.

Until now I have been using the lazy solution that you pointed out. But that isn't acceptable in a long-term perspective.
First I will try to use projects, and the function referenced by @sellorm.
Although I saw that we can use the ~ signal to refer to the working directory path, it works on Linux, but it doesn't work on Windows.

Yeah, the ~ shortcut is an old Unix thing that refers to a user's home directory. Because of their lineage, it exists in Linux and Mac only I'm afraid, though I believe things like git-bash, can bring it to windows. I wouldn't rely on it though. Using RStudio projects in conjunction with here() is the thing to do :grin:

1 Like

Yes, I will try to understand how to implement the here() function with projects.