# Ken Kompass. Provided AS IS with absolutely no warranty expressed or implied. # # This is an R program for randomizing files. Copy all of your image files from one experiment into a folder # named "RandomizeFiles". Files can have any name EXCEPT a simple numeric name like "1", "2", "10", etc. # The program will rename your files randomly as "1", "2", "3", etc., and provide you with a text file # containing the code, which you can use to unblind your files after quantification. # R can be downloaded for free: https://www.r-project.org/ # After downloading this program and R onto your computer, do the following steps to randomize your files: # launch terminal (eg applications/utilities) # type in: R --vanilla # type in: source('InsertPathForWhereProgramIsLocatedHere/randomize.filenames.r') # eg for TIF files, type in: rename.files.randomly('InsertPathForWhereFolderContainingFilesIsLocatedHere/RandomizeFiles/', '.tif') # eg for JPG files, type in: rename.files.randomly('InsertPathForWhereFolderContainingFilesIsLocatedHere/RandomizeFiles/', '.jpg') # type in: q() # created 9.11.12(?) # modified 10.28.12, rename.files.randomly <- function(wdir=NA, file.ext=NA) # specify directory with files to randomize # specify the extension (only one permitted) for the files { if( is.na(wdir) | is.na(file.ext) ) { stop("Missing parameter(s)") } all.files <- list.files(wdir, pattern=paste(file.ext, "$", sep="")) af.df <- data.frame(all.files, stringsAsFactors=FALSE) file.ext <- gsub("^.", "", file.ext) # for consistency (replaced in next line) af.df["new.ID"] <- paste( sample(1:nrow(af.df), replace=FALSE), file.ext, sep="." ) # use 'sample' w/o replace to shuffle write.table(af.df, file=paste(wdir, "/", unlist(strsplit(wdir, "/"))[length(unlist(strsplit(wdir, "/")))], "_key.txt", sep=""), row.names=FALSE) for(i in 1:nrow(af.df)) { file.rename(from=paste(wdir, "/", af.df$all.files[i], sep=""), to=paste(wdir, "/", af.df$new.ID[i], sep="")) } }