Using read.csv with a symlinked file

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-09 15:50:09

问题


What I Am Trying To Do

My source file is very large and I want to avoid copying it into other folders. I decided to create a symlink to the large file and want to use read.csv to read in the file.

Folder structure

  • project1/data/source-file.csv
  • project2/data/alias-to-source-file.csv

What Went Wrong

Reading in the source file works perfectly, but when I try to read in the symlink, I get the following error: line 1 appears to contain embedded nulls.

I know that I can just duplicate the file and put it into my second project's folder, but I want to know if there is a way to use symlinks. If not, I would like to know of a good way to avoid duplicating data files across many projects.


回答1:


Symlinks work when made correctly on my system.

> read.csv("foo.csv")
  X1 X2 X3
1  3  4  5
2  5  6  7
> system("ln -s foo.csv bar.csv")
> read.csv("bar.csv")
  X1 X2 X3
1  3  4  5
2  5  6  7

Bad symlinks can produce errors, but I can't replicate your error:

Symlink to non-existent file:

> system("ln -s nonsuch.csv baz.csv")
> read.csv("baz.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : cannot open file 'baz.csv': No such file or directory

Link to existent directory folder:

> system("ln -s / qux.csv")
> read.csv("qux.csv")
Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  no lines available in input


来源:https://stackoverflow.com/questions/39128389/using-read-csv-with-a-symlinked-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!