Use showWarnings = FALSE
:
dir.create(file.path(mainDir, subDir), showWarnings = FALSE)
setwd(file.path(mainDir, subDir))
dir.create()
does not crash if the directory already exists, it just prints out a warning. So if you can live with seeing warnings, there is no problem with just doing this:
dir.create(file.path(mainDir, subDir))
setwd(file.path(mainDir, subDir))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…