NewGraphEnvironment / fish_passage_elk_2022_reporting

https://newgraphenvironment.github.io/fish_passage_elk_2022_reporting/
Creative Commons Zero v1.0 Universal
0 stars 1 forks source link

use `stringr::str_detect` vs `%like%` when filtering for string match #31

Closed NewGraphEnvironment closed 1 year ago

NewGraphEnvironment commented 1 year ago

a good way to use stringr to get matched strings. We should start doing that and see if we can ditch data.table as a dependency. Used to (can't think how to spell that properly) need it to join tables that had geoms though...

https://stackoverflow.com/questions/22850026/filter-rows-which-contain-a-certain-string

Mateo9569 commented 1 year ago

Can you give me an example of this syntax? In this code block for instance: https://github.com/NewGraphEnvironment/fish_passage_elk_2022_reporting/blob/2d1e785b39af2b3516314c2ff7f6707e8e2dd52a/0800-appendix-197534-weigert.Rmd#L85-L89

I tried but couldn't get it to work.

NewGraphEnvironment commented 1 year ago

best to include best attempt in the issue as it is a bit of a headstart

No need to replace all occurances of this in this repo but in new ones let's part ways with data.table if possible

https://github.com/NewGraphEnvironment/fish_passage_elk_2022_reporting/blob/2d1e785b39af2b3516314c2ff7f6707e8e2dd52a/0400-results.Rmd#L4

Mateo9569 commented 1 year ago

Why are we parting ways with this? Are you making it into an fpr function in the future? I was getting choked up on the types because my_site is a number. This is my attempt that works now:

tab_hab_summary %>% 
  filter(str_detect(Site, as.character(my_site))) %>% 
  fpr::fpr_kable(caption_text = paste0('Summary of habitat details for electrofishing sites upstream of PSCIS crossing ', my_site, '.'),
                 scroll = F)
NewGraphEnvironment commented 1 year ago

hmm. that's really interesting and worth considering how much work it is to change type .... Pretty cool that data.table::%like% can use a number to filter a string....

Was thinking of trying to part ways with the data.table package as a dependency of our work as tidyverse packages usually can do anything data.table can....