Promoting the use of R in the NHS

Blog Article

Organising your work on a computer is crucial. Here is a simple, but effective, workflow that might also work for you. Think of a piece of work as a project with subfolders – eg

Project

  • Attic
  • Data
  • Plot
  • Program
  • Protocol
  • Result
  • Paper
  • Tmp
  • Log
  • Slides

You can of course add/remove folders and use names of your choosing.

For any project then, we can then store appropriate files in the relevant folders.

A neat thing with R is that you can write a script it to create your folders.

# make my project folders
mydir <- "C:/A_New_Project" # NB the / has to forward not \ backward

# Now create the subfolders
d <- NULL # create a null or empty vector


# Assign each folder to an element in the vector
d[1]  <- mydir
d[2]  <- paste(mydir,'Attic', sep='/')
d[3]  <- paste(mydir,'Data', sep='/')
d[4]  <- paste(mydir,'Plot', sep='/')
d[5]  <- paste(mydir,'Program', sep='/')
d[6]  <- paste(mydir,'Protocol',sep='/')
d[7]  <- paste(mydir,'Result', sep='/')
d[8]  <- paste(mydir,'Paper', sep='/')
d[9]  <- paste(mydir,'Tmp',sep='/')
d[10] <- paste(mydir,'Log',sep='/')
d[11] <- paste(mydir,'Slides',sep='/')


# run a loop to create each folder and subfolder
for(i in 1:length(d)) dir.create(d[i], showWarnings = FALSE)


setwd(mydir) # set the working directory to the new project folder

getwd() # check that its is the correct folder

dir() # list subfolders

 

Leave a Reply