File: rprofile.R

package info (click to toggle)
r-cran-usethis 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,228 kB
  • sloc: sh: 26; makefile: 17; cpp: 6; ansic: 3
file content (66 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#' Helpers to make useful changes to `.Rprofile`
#'
#' @description
#' All functions open your `.Rprofile` and give you the code you need to
#' paste in.
#'
#' * `use_devtools()`: makes devtools available in interactive sessions.
#' * `use_usethis()`: makes usethis available in interactive sessions.
#' * `use_reprex()`: makes reprex available in interactive sessions.
#' * `use_conflicted()`:  makes conflicted available in interactive sessions.
#' * `use_partial_warnings()`: warns on partial matches.
#'
#' @name rprofile-helper
NULL

#' @rdname rprofile-helper
#' @export
use_conflicted <- function() {
  use_rprofile_package("conflicted")
}

#' @rdname rprofile-helper
#' @export
use_reprex <- function() {
  use_rprofile_package("reprex")
}

#' @rdname rprofile-helper
#' @export
use_usethis <- function() {
  use_rprofile_package("usethis")
}

#' @rdname rprofile-helper
#' @export
use_devtools <- function() {
  use_rprofile_package("devtools")
}

use_rprofile_package <- function(package) {
  check_installed(package)
  ui_bullets(c(
    "_" = "Include this code in {.path .Rprofile} to make {.pkg {package}}
           available in all interactive sessions:"
  ))
  ui_code_snippet("
    if (interactive()) {{
      suppressMessages(require({package}))
    }}")
  edit_r_profile("user")
}

#' @rdname rprofile-helper
#' @export
use_partial_warnings <- function() {
  ui_bullets(c(
    "_" = "Include this code in {.path .Rprofile} to warn on partial matches:"
  ))
  ui_code_snippet("
    options(
      warnPartialMatchArgs = TRUE,
      warnPartialMatchDollar = TRUE,
      warnPartialMatchAttr = TRUE
    )")
  edit_r_profile("user")
}