Create directory from R

Credit goes to this post at StackOverflow. As our genotyping and QTL mapping pipeline continue to scale up, it is helpful to automatically isolate R/qtl output for each trait into their own directories. As stated in the stackoverflow post by user robbrit, the dir.create() function creates a directory in the working directory, and throws a warning if it already exists.
dir.create("testDir")
I believe robbrit's use of file.path() is a more flexible, platform independent method to do it. "testDir" could be a traditional file path (e.g. "/home/user_name/Documents/testDir"), otherwise it creates it in the working directory.
dir.create(file.path("testDir"))
And finally set the working directory to the new path.
dir.create(file.path("testDir"))
setwd(file.path("testDir"))

Comments

Popular Posts