how do i loop through folders and apply a function on a file in these folders?

Make the path to read csv dynamic in your function

  image<-read.csv(paste0(x, '/image.csv'), header=T, sep=",") 
  #header = T and sep = ',' is default in read.csv so this should 
  #work without specifying them as well.
  cells<-read.csv(paste0(x, '/cells.csv'))

and then apply the function to each folder.

dirs <- list.dirs(recursive=FALSE)
dirs <- grep('output', dirs, value = TRUE)
result <- lapply(dirs, object_extraction)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top