|
1 | | -#' Create a package from scratch |
| 1 | +#' Create a new package or project |
2 | 2 | #' |
3 | | -#' This changes the active project to the new package so that subsequent |
4 | | -#' `use_` calls will affect the project that you've just created. |
| 3 | +#' Both functions change the active project so that subsequent `use_` calls |
| 4 | +#' will affect the project that you've just created. See `proj_set()` to |
| 5 | +#' manually reset it. |
5 | 6 | #' |
6 | 7 | #' @param path A path. If it exists, it will be used. If it does not |
7 | 8 | #' exist, it will be created (providing that the parent path exists). |
@@ -46,6 +47,33 @@ create_package <- function(path = ".", |
46 | 47 | invisible(TRUE) |
47 | 48 | } |
48 | 49 |
|
| 50 | +#' @export |
| 51 | +#' @rdname create_package |
| 52 | +create_project <- function(path = ".", |
| 53 | + open = interactive()) { |
| 54 | + |
| 55 | + path <- normalizePath(path, mustWork = FALSE) |
| 56 | + |
| 57 | + name <- basename(path) |
| 58 | + check_not_nested(dirname(path)) |
| 59 | + |
| 60 | + create_directory(dirname(path), name) |
| 61 | + cat_line(crayon::bold("Changing active project to", crayon::red(name))) |
| 62 | + proj_set(path, force = TRUE) |
| 63 | + |
| 64 | + use_rstudio() |
| 65 | + use_directory("R") |
| 66 | + |
| 67 | + if (open) { |
| 68 | + done("Opening project in new session") |
| 69 | + project_path <- file.path(normalizePath(path), paste0(name, ".Rproj")) |
| 70 | + utils::browseURL(project_path) |
| 71 | + } |
| 72 | + |
| 73 | + invisible(TRUE) |
| 74 | +} |
| 75 | + |
| 76 | + |
49 | 77 | check_not_nested <- function(path) { |
50 | 78 | proj_root <- proj_find(path) |
51 | 79 |
|
|
0 commit comments