You might want to call normalizePath before passing the dirName. This helps in cases like "~/checkpoint-dir" being expanded by R to /home/shivaram/checkpoint-dir