brad-cannell / codebookr

Create Codebooks From Data Frames
https://brad-cannell.github.io/codebookr/
Other
25 stars 5 forks source link

Create a convenience function for printing out multiple calls to cb_add_col_attributes #34

Open mbcann01 opened 1 year ago

mbcann01 commented 1 year ago

Overview

This function works, just need to wrap it up

purrr::walk(
  .x = select(motivate, starts_with("arth")) %>% names(),
  .f = ~ cat(paste0('
    cb_add_col_attributes( \n    ',
      "  ", .x, ', \n    ',
      "  ", 'description = ""
    ) %>%
  '))
)

I want to be able to pass tidy select directly to the function and the attributes that I want to add a value for. It may also be cool to be able to provide a default value for each attribute.

# Work on the name
cb_generate_add_col_attributes(
  .cols  = select(motivate, starts_with("arth")),
  .attrs = list(
    source = "Arthritis Self-Efficacy",
    value_labels = c("Very Uncertain" = 1, "Very certain" = 10)
  )
)

But instead of printing out code, why not just make this add the attributes?

This need to be a separate issue (just writing it here before I forget), but I may also want quick add functions for each of the five special attributes.

cb_add_source(select(motivate, starts_with("arth")), "Arthritis Self-Efficacy"))

Left off

Haven't started yet

Task list