How to clone a patients directory

How to clone a patients directory?

The first job, when working on multiple patients, is to make a clear separation between source files (the original database you should never change) and computation results.

Suppose your original data is stored in individual folders, all store in a given source directory “E:/db”:

First, manually create the destination directory, for instance “E:/results_on_db”.

Then execute the following code:

src.dir <- "E:/db"
dest.dir <- "E:/results_on_db"

pat.folders <- list.dirs (src.dir, recursive = FALSE)
pat.list <- basename (pat.folders)

for (p in pat.list) dir.create (file.path (dest.dir, p)) 

These lines will create a clone of your patient folders in the destination directory:

Next step consists in getting the original data, making computation on each patient, and storing results in the destination folder. For instance, suppose we want to get the patient’s original folder files content, and save it:

my.computation <- function (src.dir, dest.dir, pat.folder) {
  
  ## here, you can make what you want :-)

  ## get the directory content
  L <- list.files (file.path (src.dir, pat.folder), full.names = TRUE, recursive = TRUE)
  ## save it in the cole folder
  write.csv2 (L, file = file.path (dest.dir, pat.folder, "files_in_db.csv"))
  
}
## here, we will run my.computation on every patient
require (espadon)

src.dir <- "E:/db"
dest.dir <- "E:/results_on_db"

pat.folders <- list.dirs (src.dir, recursive = FALSE)
pat.list <- basename(pat.folders)

for (p in pat.list) my.computation (src.dir, dest.dir, p)