diff --git a/src/R/PCA.R b/src/R/PCA.R
index cefb47311d3b4980ae4d13bc38a884fd8634cbaf..4ec4a37bb04a660a07b174d7f0b855eeda93fb54 100755
--- a/src/R/PCA.R
+++ b/src/R/PCA.R
@@ -192,6 +192,9 @@ for (i in seq_len(length(par.l$files_rawCounts))) {
     # Correlation plot #
     ####################
     
+    if (!dir.exists(unique(dirname(par.l$files_output_cor_plot[i])))) {
+        dir.create(unique(dirname(par.l$files_output_cor_plot[i])))
+    }
     pdf(par.l$files_output_cor_plot[i], height = pdf_height, width = pdf_width)
     
     titleCur = paste0("\nSample correlation for file ", basename(dirname(listname)), "/", basename(listname))
@@ -207,11 +210,7 @@ for (i in seq_len(length(par.l$files_rawCounts))) {
         
         cor.data[[listname]] = countsCur.m.cor
         
-        if (!dir.exists(unique(dirname(par.l$files_output_cor_plot[i])))) {
-            dir.create(unique(dirname(par.l$files_output_cor_plot[i])))
-        }
 
-        
         nTerms = nrow(countsCur.m.cor)
         textSize = dplyr::case_when(
             nTerms <= 20  ~ 1.2,