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
1113NULL
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+ }
0 commit comments