6161# ' data = sim_data,
6262# ' family = gaussian
6363# ' )
64- amp_acro <- function (time_col ,
65- n_components = 1 ,
66- group ,
67- period ,
68- ... ) {
64+ amp_acro <- function (time_col , n_components = 1 , group , period , ... ) {
6965 .amp_acro(time_col , n_components , group , period , .env = environment(), ... )
7066}
7167
@@ -108,30 +104,34 @@ amp_acro <- function(time_col,
108104# ' @noRd
109105# ' @return A \code{data.frame} and \code{formula} appropriate for use by
110106# ' \code{data_processor()}.
111- .amp_acro <- function (time_col ,
112- n_components ,
113- group ,
114- period ,
115- no_amp_acro = FALSE ,
116- no_amp_acro_vector ,
117- cond_period ,
118- .data ,
119- .formula ,
120- .quietly = TRUE ,
121- .amp_acro_ind = - 1 ,
122- .data_prefix = " main_" ,
123- .env ) {
107+ .amp_acro <- function (
108+ time_col ,
109+ n_components ,
110+ group ,
111+ period ,
112+ no_amp_acro = FALSE ,
113+ no_amp_acro_vector ,
114+ cond_period ,
115+ .data ,
116+ .formula ,
117+ .quietly = TRUE ,
118+ .amp_acro_ind = - 1 ,
119+ .data_prefix = " main_" ,
120+ .env
121+ ) {
124122 if (missing(no_amp_acro_vector )) {
125123 no_amp_acro_vector <- NULL
126124 }
127125 no_amp_acro_vector <- no_amp_acro_vector
128126
129127 # ensure .data argument is a dataframe, matrix, or tibble (tested)
130128 assertthat :: assert_that(
131- inherits(.data , " data.frame" ) | inherits(.data , " matrix" ) | inherits(
132- .data ,
133- " tbl"
134- ),
129+ inherits(.data , " data.frame" ) |
130+ inherits(.data , " matrix" ) |
131+ inherits(
132+ .data ,
133+ " tbl"
134+ ),
135135 msg = " 'data' must be of class 'data.frame', 'matrix', or 'tibble'"
136136 )
137137
@@ -169,14 +169,17 @@ amp_acro <- function(time_col,
169169 ranef_part <- lapply(lme4 :: findbars(.formula ), deparse1 )
170170 ranef_parts_replaced <- lapply(ranef_part , function (x ) {
171171 component_num <- regmatches(
172- x , gregexpr(" (?<=amp_acro)\\ d+" , x , perl = TRUE )
172+ x ,
173+ gregexpr(" (?<=amp_acro)\\ d+" , x , perl = TRUE )
173174 )[[1 ]]
174175 if (length(component_num ) == 0 ) {
175176 return (x )
176177 } else {
177178 for (i in seq_len(length(component_num ))) {
178179 string_match <- paste0(
179- " .*amp_acro" , component_num [i ], " \\ s([^+|]*).*"
180+ " .*amp_acro" ,
181+ component_num [i ],
182+ " \\ s([^+|]*).*"
180183 )
181184 ranef_part_addition <- gsub(string_match , " \\ 1" , x )
182185 ranef_part_group <- gsub(" .*\\ |\\ s*(.*)" , " \\ 1" , x )
@@ -217,9 +220,11 @@ amp_acro <- function(time_col,
217220 collapse = " +"
218221 )
219222
220- main_part <- paste(paste(deparse(res $ newformula ), collapse = " " ),
223+ main_part <- paste(
224+ paste(deparse(res $ newformula ), collapse = " " ),
221225 ranef_part_updated ,
222- collapse = " " , sep = " +"
226+ collapse = " " ,
227+ sep = " +"
223228 )
224229 res $ newformula <- stats :: as.formula(main_part )
225230 res $ ranef_groups <- ranef_groups
@@ -231,26 +236,27 @@ amp_acro <- function(time_col,
231236}
232237
233238
234- amp_acro_iteration <- function (time_col ,
235- n_components ,
236- group ,
237- period ,
238- no_amp_acro ,
239- no_amp_acro_vector ,
240- cond_period ,
241- .formula ,
242- .quietly = TRUE ,
243- .data ,
244- .amp_acro_ind = - 1 ,
245- .data_prefix ,
246- .env ) {
239+ amp_acro_iteration <- function (
240+ time_col ,
241+ n_components ,
242+ group ,
243+ period ,
244+ no_amp_acro ,
245+ no_amp_acro_vector ,
246+ cond_period ,
247+ .formula ,
248+ .quietly = TRUE ,
249+ .data ,
250+ .amp_acro_ind = - 1 ,
251+ .data_prefix ,
252+ .env
253+ ) {
247254 if (n_components == 0 ) {
248255 no_amp_acro <- TRUE
249256 }
250257
251258 # assess the quality of the inputs
252259
253-
254260 # Function to check if 'amp_acro' is in the formula
255261 check_amp_acro <- function (.formula ) {
256262 # Convert formula to character and check for presence of 'amp_acro'
@@ -303,16 +309,13 @@ amp_acro_iteration <- function(time_col,
303309 ttt <- eval(substitute(time_col , .env ), envir = .data )
304310 }
305311
306-
307312 # ensure ttt contains numeric values only (tested)
308313 if (! assertthat :: assert_that(is.numeric(ttt ))) {
309314 stop(" time column in dataframe must contain numeric values" )
310315 }
311316
312317 # ensure time_col is univariate (tested)
313- assertthat :: assert_that(is.vector(ttt ),
314- msg = " time_col must be univariate"
315- )
318+ assertthat :: assert_that(is.vector(ttt ), msg = " time_col must be univariate" )
316319
317320 # Check if 'group' is a non-string and convert it to a string if necessary
318321 if (all(! is.character(substitute(group , .env ))) & ! missing(group )) {
@@ -440,7 +443,10 @@ amp_acro_iteration <- function(time_col,
440443 # add a warning message that columns have been added to the dataframe
441444 if (! .quietly ) {
442445 message(paste(
443- rrr_names , " and" , sss_names , " have been added to dataframe"
446+ rrr_names ,
447+ " and" ,
448+ sss_names ,
449+ " have been added to dataframe"
444450 ))
445451 }
446452 }
@@ -462,12 +468,22 @@ amp_acro_iteration <- function(time_col,
462468 cperiod_idx <- component $ period_idx
463469
464470 if (cgroup != 0 ) {
465- acpart <- paste((rep(cgroup , 2 )), c(vec_rrr [cperiod_idx ], vec_sss [cperiod_idx ]), sep = " :" )
471+ acpart <- paste(
472+ (rep(cgroup , 2 )),
473+ c(vec_rrr [cperiod_idx ], vec_sss [cperiod_idx ]),
474+ sep = " :"
475+ )
466476 acpart_combined <- paste(acpart [1 ], acpart [2 ], sep = " + " )
467477 formula_expr <- paste(formula_expr , " +" , acpart_combined )
468478 } else {
469479 acpart_combined <- NULL
470- formula_expr <- paste(formula_expr , " +" , vec_rrr [cperiod_idx ], " +" , vec_sss [cperiod_idx ])
480+ formula_expr <- paste(
481+ formula_expr ,
482+ " +" ,
483+ vec_rrr [cperiod_idx ],
484+ " +" ,
485+ vec_sss [cperiod_idx ]
486+ )
471487 }
472488 }
473489 }
@@ -485,7 +501,8 @@ amp_acro_iteration <- function(time_col,
485501 }
486502
487503 newformula <- stats :: as.formula(
488- paste(left_part ,
504+ paste(
505+ left_part ,
489506 paste(
490507 c(
491508 attr(
0 commit comments