epiverse-trace / linelist

R package for handling linelist data
https://epiverse-trace.github.io/linelist/
Other
8 stars 4 forks source link

evaluate the usage of `tag_names` as arguments in `make_linelist` using autocomplete #144

Open avallecam opened 3 months ago

avallecam commented 3 months ago

Is possible that having the tag_names as arguments would accelerate writing or make it less error-prone by using autocomplete. However, this may increase the complexity of the function internals.

Currently, we are using a mix of dplyr::glimpse with linelist::tags_names to tag variables when using linelist::make_linelist

library(outbreaks)
library(tidyverse)
library(linelist)

# cleaned data
ebola <- outbreaks::ebola_sim_clean %>% 
  pluck("linelist") %>% 
  as_tibble()

ebola %>% dplyr::glimpse()
linelist::tags_names()

ebola %>% 
  make_linelist(id = "case_id" ,date_onset = "date_of_onset")

from @Bisaloo

From a technical point of view, we could also do: make_linelist(x, col = "tag") instead of: make_linelist(x, tag = "col") which means we would have auto-complete for the column names.

I'm not completely sure of the implications yet. I think dplyr has thought a lot about this and rename() even changed this at some point. It may be worth digging to see if they have written up something about the rationale

TimTaylor commented 2 months ago

Could you utilise https://stat.ethz.ch/R-manual/R-devel/library/utils/html/rcompgen.html? I've never looked at it in any detail but wonder if it allows you to register custom completions which could help with ...?

Bisaloo commented 2 months ago

Could you utilise stat.ethz.ch/R-manual/R-devel/library/utils/html/rcompgen.html? I've never looked at it in any detail but wonder if it allows you to register custom completions which could help with ...?

I'm not 100% sure but I think you cannot customize a function autocomplete. Only what appears after $ and @.

Bisaloo commented 2 months ago

Also summarizing other points from the slack discussion for completeness and future reference:

TimTaylor commented 2 months ago

I'm not 100% sure but I think you cannot customize a function autocomplete. Only what appears after $ and @.

Seems like you can with utils:::.addFunctionInfo() but (a) I've seen little use of this in the wild (e.g. GitHub CRAN) and (b) I'm not sure how to get it to work with the RStudio autocompletion (I couldn't get it to work there only within a terminal R session).

That said I'm not sure it is the right thing to do anyway ...

We could potentially make the default tags explicit arguments

Explicit arguments would seem preferable.