Debian Codegraph @

R/scaffold.R

raw
1 #' Generate project infrastructure
2 #'
3 #' @description
4 #' Create the renv project infrastructure. This will:
5 #'
6 #' - Create a project library, `renv/library`.
7 #'
8 #' - Install renv into the project library.
9 #'
10 #' - Update the project `.Rprofile` to call `source("renv/activate.R")` so
11 #' that renv is automatically loaded for new \R sessions launched in
12 #' this project.
13 #'
14 #' - Create `renv/.gitignore`, which tells git to ignore the project library.
15 #'
16 #' - Create `.Rbuildignore`, if the project is also a package. This tells
17 #' `R CMD build` to ignore the renv infrastructure,
18 #'
19 #' - Write a (bare) [lockfile], `renv.lock`.
20 #'
21 #' @inheritParams renv-params
22 #'
23 #' @param version The version of renv to associate with this project. By
24 #' default, the version of renv currently installed is used.
25 #'
26 #' @param repos The \R repositories to associate with this project.
27 #'
28 #' @param settings A list of renv settings, to be applied to the project
29 #' after creation. These should map setting names to the desired values.
30 #' See [settings] for more details.
31 #'
32 #' @examples
33 #'
34 #' \dontrun{
35 #' # create scaffolding with 'devtools' ignored
36 #' renv::scaffold(settings = list(ignored.packages = "devtools"))
37 #' }
38 #'
39 #' @export
40 scaffold <- function(project = NULL,
41 version = NULL,
42 repos = getOption("repos"),
43 settings = NULL)
44 {
45 renv_scope_error_handler()
46 renv_scope_options(repos = repos)
47
48 project <- renv_project_resolve(project)
49 renv_project_lock(project = project)
50
51 # install renv into project library
52 renv_imbue_impl(project, version)
53
54 # write out project infrastructure
55 renv_infrastructure_write(project, version)
56
57 # update project settings
58 if (is.list(settings))
59 renv_settings_persist(project, settings)
60
61 # generate a lockfile
62 lockfile <- renv_lockfile_create(
63 project = project,
64 libpaths = renv_paths_library(project = project),
65 type = "implicit"
66 )
67
68 renv_lockfile_write(lockfile, file = renv_lockfile_path(project))
69
70 # notify user
71 fmt <- "- renv infrastructure has been generated for project %s."
72 writef(fmt, renv_path_pretty(project))
73
74 # return project invisibly
75 invisible(project)
76 }