-2

I have found similar issues resolved with NA omit, however I can't seem to have any luck with it though. could anyone advise me how why pathF might have zero rows? I'm new to R

library(tidyverse)

data_path <- paste (setwd ("Data"))
SamplesF <- list.files(path = data_path, pattern = "*.R1.fastq.gz", all.files = FALSE,
       full.names = FALSE, recursive = FALSE,
       ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)

TabF <- as.data.frame(SamplesF)

PathF <- data.frame(lapply(TabF, function(TabF) {gsub("Data/", "$PWD/N/", TabF)}))
PathF <- data.frame(lapply(PathF, function(PathF) {gsub("fastq.gz", "fastq.gip", PathF)}))

names(PathF)[names(PathF)=="SamplesF"] <- "absolute-filepath" 

PathF['direction']='forward'

PathF['sample-id']= SamplesF

Heres the error:

Error in `[<-.data.frame`(`*tmp*`, "direction", value = "forward") : 
replacement has 1 row, data has 0
Calls: [<- -> [<-.data.frame
Execution halted
Gus Bishop
  • 23
  • 6
  • 3
    Please provide a minimal example and at a minimum note the line on which this error occurs. – lmo Oct 01 '18 at 12:56
  • Related to https://stackoverflow.com/questions/52496914/tidyverse-conflicts-with-automatic-manifest-maker?noredirect=1&lq=1 – nghauran Oct 01 '18 at 12:57
  • Hi lmo I totally agree this needs to be more concise but at this moment in time, I don't know which line the error occurred on but I will absolutely edit this down as soon as I can. – Gus Bishop Oct 01 '18 at 12:58
  • ANG, you are correct! That was me last week, I've been working on this every day and still cant work out what is going on, if you read that thread you'll see it was never resolved – Gus Bishop Oct 01 '18 at 13:00
  • What I'd do is to run each line separately and see where it fails. You could do this in terminal or in RGUI (for windows) by opening R and copy/pasting each line. It is easier to use Rstudio and select blocks of code and use `ctrl+Enter` to execute it. – lmo Oct 01 '18 at 13:16
  • The error is thrown by this line `PathF['direction']='forward'`. You'll have to investigate why `PathF` has zero rows at this point. – Roland Oct 01 '18 at 13:48

1 Answers1

0

In the function list.files the argument pattern is expecting a regex expression (type ?regex into R), it looks like you are using a command line type expression where * would be a wildcard.

It is likely there are no matches to your string when interpreted as regex. So you are working with length(0) data from the start.

Instead try: the pattern as ".R1.fastq.gz$"

SamplesF <- list.files(path = data_path, pattern = ".R1.fastq.gz$", all.files = FALSE,
       full.names = FALSE, recursive = FALSE,
       ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)

and see how that goes.

Aaron Hayman
  • 525
  • 3
  • 11
  • Thanks for the answer but I'm afraid that didn't change the output – Gus Bishop Oct 02 '18 at 09:30
  • Can you check what is in `SamplesF`? Also you need to check that where you are looking the files is where your think. `data_path <- paste (setwd ("Data"))` sets `data_path` to the folderpath prior to changing the working directory. so it is not searching the "Data" folder, but is searching the parent folder. – Aaron Hayman Oct 02 '18 at 09:40
  • There is a subdirectory `Data` to the working directory, it contains any number of `fastq.gz` files – Gus Bishop Oct 02 '18 at 09:52
  • in the `list.files` function try `path = ""`, this will mean it looks in the working directory, which in the previous line you have changed to `Data` – Aaron Hayman Oct 02 '18 at 10:00
  • I got this error when i changed to `path = ""` `Error in `[<-.data.frame`(`*tmp*`, "direction", value = "forward") : replacement has 1 row, data has 0 Calls: [<- -> [<-.data.frame Execution halted` – Gus Bishop Oct 02 '18 at 10:07
  • The problem is still caused by `list.files` not finding any files that match the string. I cannot say why it does not find them since I do not know the contents of your drives. I would suggest you to try `pattern = ""` and see it you can make any sense of what it returns, to make sure you are searching in the right place. – Aaron Hayman Oct 02 '18 at 10:22
  • It dosn't have a problem finding the files, the manifest.csv it produces has got the details of the files in it, the issue is that it keeps printing the filepath before the sample ID. But just to clarify, I have got several files ending in the string `R1.fastq.gz` in the subdirectory `Data` – Gus Bishop Oct 02 '18 at 10:27