Skip to content

Commit e1e3328

Browse files
committed
Rename edit family
1 parent 0798cd4 commit e1e3328

File tree

5 files changed

+64
-42
lines changed

5 files changed

+64
-42
lines changed

NAMESPACE

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
export(create_package)
44
export(create_project)
5-
export(edit_environ_user)
6-
export(edit_git_config_user)
7-
export(edit_git_ignore_user)
8-
export(edit_makevars_user)
9-
export(edit_profile_user)
5+
export(edit_git_config)
6+
export(edit_git_ignore)
7+
export(edit_r_environ)
8+
export(edit_r_makevars)
9+
export(edit_r_profile)
1010
export(edit_rstudio_snippets)
1111
export(proj_get)
1212
export(proj_set)

NEWS.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ The output from all usethis commands has been reviewed to be informative but not
4242

4343
A new class of functions make it easy to edit common config files:
4444

45-
* `edit_profile_user()` opens `~/.Rprofile`
46-
* `edit_environ_user()` opens `~/.Renviron`
47-
* `edit_makevars_user()` opens `~/.R/Makevars`
48-
* `edit_git_config_user()` opens `~/.gitconfig`
49-
* `edit_git_ignore_user()` opens `~/.gitignore`
45+
* `edit_r_profile_user()` opens `.Rprofile`
46+
* `edit_r_environ_user()` opens `.Renviron`
47+
* `edit_r_makevars_user()` opens `.R/Makevars`
48+
* `edit_git_config_user()` opens `.gitconfig`
49+
* `edit_git_ignore_user()` opens `.gitignore`
5050
* `edit_rstudio_snippets(type)` opens `~/R/snippets/{type}.snippets`
5151

5252
## Updates

R/edit.R

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,63 @@
11
#' Open useful configuration files
22
#'
3-
#' * `edit_profile_user()` opens `~/.Rprofile`
4-
#' * `edit_environ_user()` opens `~/.Renviron`
5-
#' * `edit_makevars_user()` opens `~/.R/Makevars`
6-
#' * `edit_git_config_user()` opens `~/.gitconfig`
7-
#' * `edit_git_ignore_user()` opens `~/.gitignore`
3+
#' * `edit_r_profile()` opens `.Rprofile`
4+
#' * `edit_r_environ()` opens `.Renviron`
5+
#' * `edit_r_makevars()` opens `.R/Makevars`
6+
#' * `edit_git_config()` opens `.gitconfig`
7+
#' * `edit_git_ignore()` opens `.gitignore`
88
#' * `edit_rstudio_snippets(type)` opens `~/R/snippets/{type}.snippets`
99
#'
10+
#' @param scope Edit globally for the current __user__, or locally for the
11+
#' current __project__
1012
#' @name edit
1113
NULL
1214

1315
#' @export
1416
#' @rdname edit
15-
edit_profile_user <- function() {
16-
edit_file("~", ".Rprofile")
17+
edit_r_profile <- function(scope = c("user", "project")) {
18+
edit_file(scope_dir(scope), ".Rprofile")
1719
todo("Restart R for changes to take effect")
1820
invisible()
1921
}
2022

2123
#' @export
2224
#' @rdname edit
23-
edit_environ_user <- function() {
24-
edit_file("~", ".Renviron")
25+
edit_r_environ <- function(scope = c("user", "project")) {
26+
edit_file(scope_dir(scope), ".Renviron")
2527
todo("Restart R for changes to take effect")
2628
invisible()
2729
}
2830

2931
#' @export
3032
#' @rdname edit
31-
edit_makevars_user <- function() {
32-
create_directory(path.expand("~"), ".R")
33-
edit_file("~", ".R/Makevars")
33+
edit_r_makevars <- function(scope = c("user", "project")) {
34+
dir <- scope_dir(scope)
35+
create_directory(dir, ".R")
36+
edit_file(dir, ".R/Makevars")
3437
todo("Restart R for changes to take effect")
3538
invisible()
3639
}
3740

3841
#' @export
3942
#' @rdname edit
40-
edit_git_config_user <- function() {
41-
edit_file("~", ".gitconfig")
43+
edit_git_config <- function(scope = c("user", "project")) {
44+
scope <- match.arg(scope)
45+
switch(scope,
46+
user = edit_file("~", ".gitconfig"),
47+
project = edit_file(proj_get(), ".git/config")
48+
)
49+
4250
invisible()
4351
}
4452

4553
#' @export
4654
#' @rdname edit
47-
edit_git_ignore_user <- function() {
48-
edit_file("~", ".gitignore")
55+
edit_git_ignore <- function(scope = c("user", "project")) {
56+
scope <- match.arg(scope)
57+
switch(scope,
58+
user = edit_file("~", ".gitignore"),
59+
project = edit_file(proj_get(), ".git/ignore")
60+
)
4961
invisible()
5062
}
5163

@@ -57,3 +69,10 @@ edit_rstudio_snippets <- function(type = "R") {
5769
edit_file("~", paste0(".R/snippets/", tolower(type), ".snippets"))
5870
invisible()
5971
}
72+
73+
scope_dir <- function(scope = c("user", "project")) {
74+
scope <- match.arg(scope)
75+
message("Editing in ", scope, " scope")
76+
77+
switch(scope, user = path.expand("~"), project = proj_get())
78+
}

R/use_this.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#'
55
#' @export
66
use_usethis <- function() {
7-
edit_profile_user()
7+
edit_r_profile("user")
88

99
todo("Include this code to make usethis available in all interactive sessions")
1010
code_block(

man/edit.Rd

Lines changed: 18 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)