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

notes on sense barchart #4

Open
mabafaba opened this issue May 10, 2019 · 0 comments
Open

notes on sense barchart #4

mabafaba opened this issue May 10, 2019 · 0 comments

Comments

@mabafaba
Copy link
Contributor

mabafaba commented May 10, 2019

user interface

I think it's not abstracted enough for a user facing function. maybe it should have a wrapper that does something like this:

barchart_orientation<-function(.data, plot.width){
...
return(sens_barchart(...))

}

readable code

few things can be made more readable, for example:

list_size_char_label <- nchar(levels(independent.var.value[[name_var]]))  ## to change

  list_logical_size <- lapply(list_size_char_label, function(x){if(x > size_max_label) return(TRUE) else return(FALSE)} ) ##nbre de caractere difini en fonction taille output

  if(nbre_bars > max_nbr_var || TRUE %in% list_logical_size ){
    #nbre doit dependre de la taille du output par exemple
    sens_barchart <- "horizontal"
  }
  else{
    sens_barchart <- "vertical"
  }

replace with


label_length<-nchar(unique(as.character(var)))
too_long_labels<- any(  label_length > size_max_label)
too_many_bars <- nbre_bars > max_nbr_var
horizontal <- too_long_labels | too_many_bars

orientation <- ifelse(horizontal,"horizontal" ,"vertical")

  • using unique(as.character()) instead of levels() to make sure it also works with non-factors:
  • nesting (including if, for, *apply) is always difficult to think about, because it creates all those levels of code you need to keep in mind. It's good to keep them as short as possible.
  • the point of making new objects ("<-") is to give them a name; so the new object should be a meaningful "thing" in your process. in this case: length of labels; are the labels too long? are there too many bars? can the barchart be horizontal?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant