@@ -44,7 +44,8 @@ create_package <- function(path,
4444 if (check_name ) {
4545 check_package_name(name )
4646 }
47- check_not_nested(path_dir(path ), name )
47+ challenge_nested_project(path_dir(path ), name )
48+ challenge_home_directory(path )
4849
4950 create_directory(path )
5051 local_project(path , force = TRUE )
@@ -75,7 +76,8 @@ create_project <- function(path,
7576 open = rlang :: is_interactive()) {
7677 path <- user_path_prep(path )
7778 name <- path_file(path_abs(path ))
78- check_not_nested(path_dir(path ), name )
79+ challenge_nested_project(path_dir(path ), name )
80+ challenge_home_directory(path )
7981
8082 create_directory(path )
8183 local_project(path , force = TRUE )
@@ -246,7 +248,7 @@ create_from_github <- function(repo_spec,
246248
247249 destdir <- user_path_prep(destdir %|| % conspicuous_place())
248250 check_path_is_directory(destdir )
249- check_not_nested (destdir , repo_name )
251+ challenge_nested_project (destdir , repo_name )
250252 repo_path <- path(destdir , repo_name )
251253 create_directory(repo_path )
252254 check_directory_is_empty(repo_path )
@@ -309,7 +311,7 @@ create_from_github <- function(repo_spec,
309311# creates a backdoor we can exploit in tests
310312allow_nested_project <- function () FALSE
311313
312- check_not_nested <- function (path , name ) {
314+ challenge_nested_project <- function (path , name ) {
313315 if (! possibly_in_proj(path )) {
314316 return (invisible ())
315317 }
@@ -331,3 +333,24 @@ check_not_nested <- function(path, name) {
331333 }
332334 invisible ()
333335}
336+
337+ challenge_home_directory <- function (path ) {
338+ homes <- unique(c(path_home(), path_home_r()))
339+ if (! path %in% homes ) {
340+ return (invisible ())
341+ }
342+
343+ qualification <- if (is_windows()) {
344+ glue(" a special directory, i.e. some applications regard it as " )
345+ } else {
346+ " "
347+ }
348+ ui_line("
349+ {ui_path(path)} is {qualification}your home directory.
350+ It is generally a bad idea to create a new project here.
351+ You should probably create your new project in a subdirectory." )
352+ if (ui_nope(" Do you want to create anyway?" )) {
353+ ui_stop(" Good move! Cancelling project creation." )
354+ }
355+ invisible ()
356+ }
0 commit comments