Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get R to follow symbolic links in Windows 10?

I have multiple RStudio projects, each in its own working directory. All of the projects draw data from the same series of CSV files.

I would like to place the CSV files in a separate "data" directory, then put a Windows shortcut inside each project directory pointing to the data directory. The directory structure would thus be:

/data
/project-1
/project-1/data = Windows shortcut pointing to /data
/project-2
/project-2/data = Windows shortcut pointing to /data
etc.

However, when I attempt to access the "data" directory via the shortcut from e.g. project-1, R generates the following error:

> write.csv(df, "data/df.csv")
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file 'data/df.csv': No such file or directory

What am I doing wrong?


1 Answers

I didn't know this, because I've spent the past 10 years using Linux instead of Windows, but:

In Windows, "shortcuts" are not symbolic links. To create an actual symbolic link, you have to open a command prompt as administrator (!?! - or activate developer mode) then create a link using mklink. RStudio does correctly follow symbolic links created that way.

Sadly, Windows Explorer does not correctly follow symbolic links created that way. And you can't create hard links to directories. So either way, it is only half functional. Bloody Windows.