Reading data through symlink in R

Viewed 336

I have a problem reading symlinks that point to data files in R, using macOS. I barely know the basics of Unix shell, so maybe I'm missing something about the way it works.

I have a folder structure like this one:

- project
  |--- task1
  |     |-- task1.R
  |     |-- output
  |           |-- data.csv
  |
  |--- task2
        |-- task2.R
        |-- input

And using I just create a symlink in task2 that points to task1/output/data.csv:

ln -s task1/output/data.csv task2/input/

But when I try to load it in R, it doesn't work:

> setwd("..../project")
> data = read.csv("task2/input/data.csv")

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'task2/input/data.csv': No such file or directory

Is there a way to use symlinks to load data in R? In this case, I know it would be much simpler to just read it directly from the original folder, but I'm trying to come up a solution to multiple projects that use the same data files without having duplicated files in the computer, and also learn how this works.

Thank you.

1 Answers

So the solution seems to be creating the symlink using the full path pointing to the original file, e.g.:

ln -s /Users/username/project/task1/output/data.csv task2/input/
Related