Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow recoding of sc_data objects #17

Closed
GregorDeCillia opened this issue Aug 10, 2021 · 1 comment · Fixed by #18
Closed

Allow recoding of sc_data objects #17

GregorDeCillia opened this issue Aug 10, 2021 · 1 comment · Fixed by #18
Assignees
Milestone

Comments

@GregorDeCillia
Copy link
Contributor

GregorDeCillia commented Aug 10, 2021

Add functionalities that allow modifications of labels and similar. Define a new R6 class and put an instance into x$recode.

changes to public methods

x <- od_table()

# set labels for fields
x$recode$label(code_field, new_label, language)
# set labels for measures
x$recode$label(code_measure, new_label, language)
# set labels of levels
x$recode$level(code_field, code_level, new_label, language)

# set total codes similar to x$total_codes() but for programmatic usage
x$recode$total_code(code_field, code_level)
# codes_levels is a permutation of x$field(code_field)$code
x$recode$order(code_field, codes_levels)
# define which levels are included in $tabulate(). 
x$recode$visible(code_field, code_level, visible = TRUE)

# undo all recodes
x$recode$reset()

Implementation

All modifications should directly overwrite x$meta and x$fields(i). The functionality should be bilingual, i.e. it should be possible to define german and english labels.

# in initialize()
private$recoder <- recoder_class$new(self, private)
# in active bindings
recode = function(value) {
  private$recoder
}

It would probably be useful to add extra columns visible and order in x$field(i) to store this part of the "recode state". We could also just store them in $private$p_fields[[i]] and omit them in the active field

active = list(field = function(i) {
  privae$p_fields[[i]][, -c("order", "visible)]
})

pluralization

We could also add "pluralized" versions that implement the recodes such as

x$recode$labels(code_measures, new_labels, language)
x$recode$levels(code_field, code_levels, new_labels, language)
# ...
@GregorDeCillia GregorDeCillia self-assigned this Aug 10, 2021
@GregorDeCillia
Copy link
Contributor Author

GregorDeCillia commented Aug 10, 2021

Some further options that are more specific to our internal needs

## set the color used for a level in visualizations
x$recode$color(code_field, code_level, hex_color)
## modify how time values are parsed ???
x$recode$parser(code_field, time_format = "YYYY-Q")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant