0

I am trying to read a file into R that is on my disk - list.files function sees him but file.exists and read.table do not...

What might be cause of that R doesn't see some files and in consequence can't read them?

The code and errors are below:

> list.files(x)
[1] "ACC.rnaseqv2__illuminahiseq_rnaseqv2__unc_edu__Level_3__RSEM_genes_normalized__data.data.txt"
[2] "MANIFEST.txt"                                                                                
> list.files(x)[1]
[1] "ACC.rnaseqv2__illuminahiseq_rnaseqv2__unc_edu__Level_3__RSEM_genes_normalized__data.data.txt"
> file.exists(paste0(x,list.files(x)[1]))
[1] FALSE
> x
[1] "D:/GitHub/RTCGA.data/RTCGA.rnaseq/data2/gdac.broadinstitute.org_ACC.Merge_rnaseqv2__illuminahiseq_rnaseqv2__unc_edu__Level_3__RSEM_genes_normalized__data.Level_3.2015060100.0.0/"
> read.table(paste0(x,list.files(x)[1])) -> y
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'D:/GitHub/RTCGA.data/RTCGA.rnaseq/data2/gdac.broadinstitute.org_ACC.Merge_rnaseqv2__illuminahiseq_rnaseqv2__unc_edu__Level_3__RSEM_genes_normalized__data.Level_3.2015060100.0.0/ACC.rnaseqv2__illuminahiseq_rnaseqv2__unc_edu__Level_3__RSEM_genes_normalized__data.data.txt': No such file or directory
Rob
  • 26,989
  • 16
  • 82
  • 98
Marcin
  • 7,834
  • 8
  • 52
  • 99
  • Just because you can read the directory doesn't mean you can open the file. Did you navigate to the file and determine the permissions? Make sure Everyone is allowed to read and write – FirebladeDan Jul 22 '15 at 22:09
  • Are you in linux? Perhaps change the permissions of the file: `sudo chmod 755 ACC.rnaseqv2__illuminahiseq_rnaseqv2__unc_edu__Level_3__RSEM_genes_normalized__data.data.txt` – Michal Jul 22 '15 at 22:21
  • Thanks for answer. You are right. What about that file.exists return FALSE? Can this be a matter or that the files are somehow on a different branch than I am currently working on - but why then list files works? – Marcin Jul 22 '15 at 22:21
  • Working on a windows. – Marcin Jul 22 '15 at 22:22
  • Doesn't have to. I give full directories. – Marcin Jul 22 '15 at 23:06

1 Answers1

5

There are some APIs in Windows that are limited to 255 character paths. E.g. See Has Windows 7 Fixed the 255 Character File Path Limit?

Your total path length here is 269 characters. I would have thought that was the issue. I would rename the folder, the file or both. Or I guess you could change OS, but that would seem harder work! (Note I use Windows as my main OS out of choice, but I do find some of its limitations frustrating at times, particularly for cross-platform tools like R. )

Community
  • 1
  • 1
Nick Kennedy
  • 12,510
  • 2
  • 30
  • 52