-
Notifications
You must be signed in to change notification settings - Fork 1
/
stan_package_configure.R
79 lines (79 loc) · 2.33 KB
/
stan_package_configure.R
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
67
68
69
70
71
72
73
74
75
76
77
78
79
#' @title Configure an R package with built-in Stan models.
#' @export
#' @family packages
#' @description Write configuration files in an R package which
#' compile all the Stan models in `src/stan/` when the package installs.
#' @details Writes configuration scripts `configure` and `configure.win`
#' in the directory specified by the `path` argument.
#' @return `NULL` (invisibly). Called for its side effects.
#' @param path Character of length 1, file path to the package which will
#' contain Stan models in `src/stan/` at installation time.
#' @param overwrite Logical of length 1, whether to overwrite any existing
#' configuration files.
#' @examples
#' if (identical(Sys.getenv("INSTANTIATE_EXAMPLES"), "true")) {
#' path <- tempfile()
#' stan_package_create(path = path)
#' list.files(path)
#' stan_package_configure(path = path)
#' list.files(path)
#' }
stan_package_configure <- function(path = getwd(), overwrite = FALSE) {
stan_assert(
dir.exists(path),
message = paste0("package directory \"", path, "\" does not exist")
)
stan_assert(
overwrite,
isTRUE(.) || isFALSE(.),
message = "overwrite must be a logical of length 1."
)
in_cleanup <- system.file(
file.path("configuration", "cleanup"),
package = "instantiate",
mustWork = TRUE
)
in_cleanup_win <- system.file(
file.path("configuration", "cleanup.win"),
package = "instantiate",
mustWork = TRUE
)
in_install <- system.file(
file.path("configuration", "install.libs.R"),
package = "instantiate",
mustWork = TRUE
)
src <- file.path(path, "src")
out_cleanup <- file.path(path, "cleanup")
out_cleanup_win <- file.path(path, "cleanup.win")
out_install <- file.path(src, "install.libs.R")
out_makevars <- file.path(src, "Makevars")
out_makevars_win <- file.path(src, "Makevars.win")
file.copy(
from = in_cleanup,
to = out_cleanup,
overwrite = overwrite,
copy.mode = TRUE
)
file.copy(
from = in_cleanup_win,
to = out_cleanup_win,
overwrite = overwrite
)
if (!file.exists(src)) {
dir.create(src)
}
file.copy(
from = in_install,
to = out_install,
overwrite = overwrite,
copy.mode = TRUE
)
if (!file.exists(out_makevars)) {
writeLines("", out_makevars)
}
if (!file.exists(out_makevars_win)) {
writeLines("", out_makevars_win)
}
invisible()
}