I can't claim how generalizable my code is. It certainly isn't pretty. But hope it helps. You may have to edit the line that says "
row2 = (1:n())[str_detect(x, 'CONFIDENCE INTERVALS OF MODEL RESULTS')" to whatever text follows the R3STEP section in your output.
```
parse_predictors <- function(x){
x <- x %>%
str_replace('^[\\s]+', '') %>%
str_replace('[\\s]+$', '') %>%
str_split('[\\s]+') %>%
unlist()
if(length(x) < 5){
x <- c(x, rep('', times = 5 - length(x)))
}
tibble(colnames = c('predictor', 'estimate', 'se', 'tval', 'pval'),
value = x) %>%
spread(colnames, value) %>%
select(predictor, estimate, se, tval, pval)
}
extract_r3step <- function(model_path){
tibble(x = read_lines(model_path)) %>%
mutate(row1 = (1:n())[str_detect(x, 'TESTS OF CATEGORICAL LATENT VARIABLE')],
row2 = (1:n())[str_detect(x, 'CONFIDENCE INTERVALS OF MODEL RESULTS')]) %>%
slice((.$row1[1] + 2):(.$row2[1] - 1)) %>%
mutate(type_comparison = str_detect(x, 'Parameterization using Reference'),
type_colname = str_detect(x, 'Estimate'),
type_classnum = str_detect(x, 'C#[0-9]+'),
type_predictor = str_detect(x, '[\\.\\-0-9]+[\\s]+[\\.\\-0-9]+')) %>%
mutate(class = ifelse(type_classnum, parse_number(x), NA),
predictors = ifelse(type_predictor, map(x, parse_predictors), list()),
comparison_group = cumsum(type_comparison)) %>%
group_by(comparison_group) %>%
mutate(class_group = cumsum(type_classnum)) %>%
ungroup() %>%
mutate(comparison_group = ifelse(comparison_group == 0, max(class, na.rm = TRUE), comparison_group)) %>%
group_by(comparison_group, class_group) %>%
filter(class_group != 0) %>%
mutate(class_group2 = class[!
is.na(class)]) %>%
ungroup() %>%
filter(type_predictor) %>%
select(comparison_group, class_group2, predictors) %>%
unnest() %>%
rename(comparison_class = comparison_group,
class = class_group2) %>%
mutate(estimate = as.numeric(estimate),
se = as.numeric(se),
tval = as.numeric(tval),
pval = as.numeric(pval))
}
```