# Globals -----------------------------------------------------------------
path <- test_path() %>% fs::path("data") %>%
fs::dir_create(recurse = TRUE)
# Create directory --------------------------------------------------------
test_that("Ask: create directory: exists = false", {
if (path %>% fs::dir_exists()) {
path %>% fs::dir_delete()
}
result <- ask_dir_create(dir = path %>% fs::path("a/b/c"))
expect_true(path %>% fs::dir_exists())
})
test_that("Ask: create directory: exists = false (pipe)", {
if (path %>% fs::dir_exists()) {
path %>% fs::dir_delete()
}
result <- path %>% fs::path("a/b/c") %>% ask_dir_create()
expect_true(path %>% fs::dir_exists())
})
test_that("Ask: create directory: exists = true", {
if (!(path %>% fs::dir_exists())) {
path %>% fs::dir_create(recurse = TRUE)
}
result <- ask_dir_create(dir = path %>% fs::path("a/b/c"))
result <- ask_dir_create(dir = path %>% fs::path("a"))
expect_true(path %>% fs::dir_exists())
})
test_that("Ask: create directory: exists = true: interactive = false", {
if (!(path %>% fs::dir_exists())) {
path %>% fs::dir_create(recurse = TRUE)
}
result <- ask_dir_create(dir = path %>% fs::path("a"), is_interactive = FALSE)
expect_true(path %>% fs::path("a") %>% fs::dir_exists())
expect_false(path %>% fs::path("a/b") %>% fs::dir_exists())
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.