7
7
# ' In order to use `cpp_register()` the `cli`, `decor`, `desc`, `glue`,
8
8
# ' `tibble` and `vctrs` packages must also be installed.
9
9
# ' @param path The path to the package root directory
10
+ # ' @param quiet If `TRUE` suppresses output from this function
10
11
# ' @return The paths to the generated R and C++ source files (in that order).
11
12
# ' @export
12
- cpp_register <- function (path = " ." ) {
13
+ cpp_register <- function (path = " ." , quiet = FALSE ) {
13
14
stop_unless_installed(c(" brio" , " cli" , " decor" , " desc" , " glue" , " tibble" , " vctrs" ))
14
15
15
16
r_path <- file.path(path , " R" , " cpp11.R" )
@@ -24,13 +25,13 @@ cpp_register <- function(path = ".") {
24
25
return (invisible (character ()))
25
26
}
26
27
27
- funs <- get_registered_functions(all_decorations , " cpp11::register" )
28
+ funs <- get_registered_functions(all_decorations , " cpp11::register" , quiet )
28
29
29
30
package <- desc :: desc_get(" Package" , file = file.path(path , " DESCRIPTION" ))
30
31
31
32
cpp_functions_definitions <- generate_cpp_functions(funs , package )
32
33
33
- init <- generate_init_functions(get_registered_functions(all_decorations , " cpp11::init" ))
34
+ init <- generate_init_functions(get_registered_functions(all_decorations , " cpp11::init" , quiet ))
34
35
35
36
r_functions <- generate_r_functions(funs , package )
36
37
@@ -42,7 +43,9 @@ cpp_register <- function(path = ".") {
42
43
{r_functions}
43
44
'
44
45
))
45
- cli :: cli_alert_success(" generated file {.file {basename(r_path)}}" )
46
+ if (! quiet ) {
47
+ cli :: cli_alert_success(" generated file {.file {basename(r_path)}}" )
48
+ }
46
49
47
50
call_entries <- get_call_entries(path )
48
51
@@ -88,14 +91,16 @@ cpp_register <- function(path = ".") {
88
91
call_entries = glue :: glue_collapse(call_entries , " \n " )
89
92
))
90
93
91
- cli :: cli_alert_success(" generated file {.file {basename(cpp_path)}}" )
94
+ if (! quiet ) {
95
+ cli :: cli_alert_success(" generated file {.file {basename(cpp_path)}}" )
96
+ }
92
97
93
98
invisible (c(r_path , cpp_path ))
94
99
}
95
100
96
101
utils :: globalVariables(c(" name" , " return_type" , " line" , " decoration" , " context" , " ." , " functions" , " res" ))
97
102
98
- get_registered_functions <- function (decorations , tag ) {
103
+ get_registered_functions <- function (decorations , tag , quiet = FALSE ) {
99
104
if (NROW(decorations ) == 0 ) {
100
105
return (tibble :: tibble(file = character (), line = integer(), decoration = character (), params = list (), context = list (), name = character (), return_type = character (), args = list ()))
101
106
}
@@ -107,7 +112,9 @@ get_registered_functions <- function(decorations, tag) {
107
112
out <- out [! (names(out ) %in% " functions" )]
108
113
out $ decoration <- sub(" ::[[:alpha:]]+" , " " , out $ decoration )
109
114
110
- cli :: cli_alert_info(glue :: glue(" {n} functions decorated with [[{tag}]]" , n = nrow(out )))
115
+ if (! quiet ) {
116
+ cli :: cli_alert_info(glue :: glue(" {n} functions decorated with [[{tag}]]" , n = nrow(out )))
117
+ }
111
118
112
119
out
113
120
}
0 commit comments