.old_wd <- setwd(tempdir())
file_create("foo")
is_file("foo")
# dir_create applied to the same path will fail
try(dir_create("foo"))
dir_create("bar")
is_dir("bar")
# file_create applied to the same path will fail
try(file_create("bar"))
# Cleanup
file_delete("foo")
dir_delete("bar")
setwd(.old_wd)
Run the code above in your browser using DataLab