问题
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