Skip to contents

Checks and creates a directory recursively automatically.

Usage

initDir(dir)

Arguments

dir

character. Directory path(s).

Value

character. Directory path(s).

Details

Useful for setting up functions that require writes to a user-specified directory.

Note

Updated 2023-05-16.

Examples

dir <- file.path(tempdir2(), c("aaa", "bbb"))
dir.exists(dir)
#> [1] FALSE FALSE
dir <- initDir(dir)
dir.exists(dir)
#> [1] TRUE TRUE
print(dir)
#> [1] "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/RtmpPc0MEq/kw0K6QfBg9-170267877321361/aaa"
#> [2] "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/RtmpPc0MEq/kw0K6QfBg9-170267877321361/bbb"
unlink2(dir)