1

I got a list of files from list.files() in current directory such that:

setwd("~/Data/LUSC/unc.edu_LUSC.IlluminaHiSeq_RNASeq.Level_3.1.2.0")
exprs_files <- list.files()
exprs_files <- exprs_files[grepl('gene.quantification', exprs_files)]
exprs_files[88]
[1] "UNCID_586826.TCGA-60-2720-01A-01R-0851-07.110426_UNC12-SN629_0078_BB08WCABXX.6.trimmed.annotated.gene.quantification.txt"

But I got error when read it:

read.delim(exprs_files[88])
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'UNCID_586826.TCGA-60-2720-01A-01R-0851-07.110426_UNC12-SN629_0078_BB08WCABXX.6.trimmed.annotated.gene.quantification.txt': No such file or directory

I am using RStudio Version 1.3.959 on Windows 10.

Any suggestions?

David Z
  • 6,641
  • 11
  • 50
  • 101
  • 1
    Can you try with `file.choose()` Or may be specify the `full.names = TRUE` in `list.files()` – akrun Dec 18 '20 at 16:18
  • Yes: `full.names=TRUE`; No: `file.choose()`, it leads to vague/non-reproducible code. :-) – r2evans Dec 18 '20 at 16:21
  • 1
    FYI David, please realize that many problems are relative to the version of R and may have no relation to the version of RStudio. The two are completely different products: it is possible to use R without RStudio (I do it every day), and it is possible to upgrade one without considering the other. So when you think about providing versions (yes, good idea!), please also include the version of R you are running. Thanks! – r2evans Dec 18 '20 at 16:22
  • got same error with full.name=TRUE. – David Z Dec 18 '20 at 16:23
  • It works for some of `exprs_files` such as `exprs_files[1]` but not working for some others. – David Z Dec 18 '20 at 16:24
  • 2
    is it possible that some of these files are being locked and/or deleted by some other process running on the system? Is the pattern of success/failure based on the length of the file names? Is it possible that the full path name of your files is >250 characters https://stackoverflow.com/questions/26151365/long-path-filename-in-windows-makes-write-table-error-out-in-r ? What is `nchar(normalizePath(exprs_files[88]))` ? – Ben Bolker Dec 18 '20 at 16:47
  • I was also wondering about the long file names mentioned by @BenBolker. Don't know whether [enabling long paths in Windows 10](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation) would be helpful. – A5C1D2H2I1M1N2O1R2T1 Dec 18 '20 at 16:57
  • Does `file.exists(exprs_files[88])` return true? – r2evans Dec 18 '20 at 17:14
  • Solved by choose.files(), not an ideal way though. I think it was still due to / and \\ in Windows. – David Z Dec 18 '20 at 18:13

1 Answers1

0

Try using a double bracket:

read.delim(exprs_files[[88]])
Ben
  • 1,113
  • 10
  • 26