I'm new to tidyverse and I'm trying to read in a Matlab .mat data structure and convert it to a tidyverse data frame but get an error setting the column headers.
data = readMat('myfile.mat')
data_tb = as_tibble(data$data, .name_repair = c(data$labels))
the readMat()
call works fine but the as_tibble()
generates this error:
Error in vec_as_names(name, repair = .name_repair, quiet = quiet || !is_character(.name_repair)) :
CHAR() can only be applied to a 'CHARSXP', not a 'character'
Note that class(data$labels)
returns [1] "matrix" "array"
(ditto for data$data)
I've tried hard-wiring labels e.g.
as_tibble(data$data, .name_repair = c("a", "b", "C", "D"))
but I get the same error.
I can change the column headers individually by reading it into a tibble without specifiying .name_repair
and calling
data_tb = data_tb %>% rename(new_col_name = old_col_name)
but that's messy and I would really rather work out why the .name_repair call is failing.