简体   繁体   English

通过 R 中的符号链接读取数据

[英]Reading data through symlink in R

I have a problem reading symlinks that point to data files in R, using macOS.我在使用 macOS 读取指向 R 中数据文件的符号链接时遇到问题。 I barely know the basics of Unix shell, so maybe I'm missing something about the way it works.我几乎不知道 Unix shell 的基础知识,所以也许我错过了它的工作方式。

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 :并且使用我只是在task2中创建一个指向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:但是当我尝试在 R 中加载它时,它不起作用:

> 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?有没有办法使用符号链接在 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.谢谢你。

So the solution seems to be creating the symlink using the full path pointing to the original file, eg:所以解决方案似乎是使用指向原始文件的完整路径创建符号链接,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM