Skip to content

Commit 411a02a

Browse files
committed
Improve nesting error message
1 parent 82f3e2e commit 411a02a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

R/create.R

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ create_package <- function(path = ".",
1919

2020
name <- basename(path)
2121
check_package_name(name)
22-
check_not_nested(dirname(path))
22+
check_not_nested(dirname(path), name)
2323

2424
create_directory(dirname(path), name)
2525
cat_line(crayon::bold("Changing active project to", crayon::red(name)))
@@ -55,7 +55,7 @@ create_project <- function(path = ".",
5555
path <- normalizePath(path, mustWork = FALSE)
5656

5757
name <- basename(path)
58-
check_not_nested(dirname(path))
58+
check_not_nested(dirname(path), name)
5959

6060
create_directory(dirname(path), name)
6161
cat_line(crayon::bold("Changing active project to", crayon::red(name)))
@@ -74,24 +74,22 @@ create_project <- function(path = ".",
7474
}
7575

7676

77-
check_not_nested <- function(path) {
77+
check_not_nested <- function(path, name) {
7878
proj_root <- proj_find(path)
7979

8080
if (is.null(proj_root))
8181
return()
8282

8383
message <- paste0(
84-
"Project is nested inside an existing project (", value(proj_root), ")"
84+
"New project ", value(name), " is nested inside an existing project ",
85+
value(proj_root), "."
8586
)
8687
if (!interactive()) {
8788
stop(message, call. = FALSE)
8889
}
8990

90-
cat_line(message)
91-
cat_line("Creating a project inside another project is usually ill-advised.")
92-
93-
if (yesno("Do you wish to create anyway?")) {
94-
stop(message, call. = FALSE)
91+
if (yesno(message, " This is rarely a good idea. Do you wish to create anyway?")) {
92+
stop("Aborting project creation", call. = FALSE)
9593
}
9694

9795
}

0 commit comments

Comments
 (0)