KWB-R / kwb.qmra

QMRA (quantitative microbial risk assessment) for water supply systems
http://kwb-r.github.io/kwb.qmra
MIT License
4 stars 2 forks source link

code-refactoring: new "input" structure (due to new columns in "default") #37

Open mrustl opened 3 years ago

mrustl commented 3 years ago

As now @chsprenger introduced new columns (partly based on qmra.db, i.e.:

This currently leads to parsing errors when kwb.qmra::config_read() is executed. Fixing requires refactoring input structure!

install.packages("remotes")
remotes::install_github("kwb-r/kwb.qmra@patch-christoph")

kwb.qmra::config_read(system.file("extdata/configs/default", 
    package = "kwb.qmra"))
#> 
#> -- Column specification --------------------------------------------------------
#> cols(
#>   name = col_character(),
#>   type = col_character(),
#>   value = col_double(),
#>   min = col_double(),
#>   max = col_double(),
#>   mode = col_double(),
#>   mean = col_logical(),
#>   sd = col_logical(),
#>   meanlog = col_logical(),
#>   sdlog = col_logical()
#> )
#> 
#> -- Column specification --------------------------------------------------------
#> cols(
#>   PathogenID = col_double(),
#>   PathogenName = col_character(),
#>   PathogenGroup = col_character(),
#>   simulate = col_double(),
#>   type = col_character(),
#>   value = col_logical(),
#>   min = col_double(),
#>   max = col_double(),
#>   mode = col_logical(),
#>   mean = col_logical(),
#>   sd = col_logical(),
#>   meanlog = col_logical(),
#>   sdlog = col_character(),
#>   Notes = col_character(),
#>   ReferenceName = col_character(),
#>   ReferenceLink = col_character()
#> )
#> Warning: 1 parsing failure.
#> row col   expected     actual                                                                                      file
#>  34  -- 16 columns 15 columns 'C:/Users/mrustl/Documents/R/win-library/4.0/kwb.qmra/extdata/configs/default/inflow.csv'
#> 
#> -- Column specification --------------------------------------------------------
#> cols(
#>   TreatmentID = col_double(),
#>   TreatmentName = col_character(),
#>   TreatmentGroup = col_character(),
#>   PathogenGroup = col_character(),
#>   type = col_character(),
#>   value = col_double(),
#>   min = col_double(),
#>   max = col_double(),
#>   mode = col_logical(),
#>   mean = col_double(),
#>   sd = col_logical(),
#>   meanlog = col_logical(),
#>   sdlog = col_character(),
#>   ReferenceName = col_character(),
#>   ReferenceLink = col_character()
#> )
#> Warning: 3 parsing failures.
#> row col   expected     actual                                                                                                   file
#>  33  -- 15 columns 14 columns 'C:/Users/mrustl/Documents/R/win-library/4.0/kwb.qmra/extdata/configs/default/treatment_processes.csv'
#>  34  -- 15 columns 14 columns 'C:/Users/mrustl/Documents/R/win-library/4.0/kwb.qmra/extdata/configs/default/treatment_processes.csv'
#>  35  -- 15 columns 14 columns 'C:/Users/mrustl/Documents/R/win-library/4.0/kwb.qmra/extdata/configs/default/treatment_processes.csv'
#> 
#> -- Column specification --------------------------------------------------------
#> cols(
#>   TreatmentSchemeID = col_double(),
#>   TreatmentSchemeName = col_character(),
#>   TreatmentID = col_double(),
#>   TreatmentName = col_character()
#> )
#> 
#> -- Column specification --------------------------------------------------------
#> cols(
#>   PathogenID = col_double(),
#>   PathogenName = col_character(),
#>   PathogenGroup = col_character(),
#>   `Best fit model*` = col_character(),
#>   k = col_double(),
#>   alpha = col_double(),
#>   N50 = col_double(),
#>   `Host type` = col_character(),
#>   `Dose units` = col_character(),
#>   Route = col_character(),
#>   Response = col_character(),
#>   Reference = col_character(),
#>   Link = col_character()
#> )
#> 
#> -- Column specification --------------------------------------------------------
#> cols(
#>   PathogenID = col_double(),
#>   PathogenName = col_character(),
#>   infection_to_illness = col_double(),
#>   dalys_per_case = col_double(),
#>   ReferenceNameInfection = col_character(),
#>   ReferenceNameDalys = col_character()
#> )
#> Warning: 1 parsing failure.
#> row col  expected    actual                                                                                      file
#>  34  -- 6 columns 4 columns 'C:/Users/mrustl/Documents/R/win-library/4.0/kwb.qmra/extdata/configs/default/health.csv'
#> $exposure
#> # A tibble: 3 x 10
#>   name               type    value    min   max   mode mean  sd    meanlog sdlog
#>   <chr>              <chr>   <dbl>  <dbl> <dbl>  <dbl> <lgl> <lgl> <lgl>   <lgl>
#> 1 number_of_repeati~ value    1000 NA     NA    NA     NA    NA    NA      NA   
#> 2 number_of_exposur~ value     100 NA     NA    NA     NA    NA    NA      NA   
#> 3 volume_perEvent    triang~    NA  0.001  0.01  0.005 NA    NA    NA      NA   
#> 
#> $inflow
#> # A tibble: 37 x 16
#>    PathogenID PathogenName PathogenGroup simulate type  value    min    max
#>         <dbl> <chr>        <chr>            <dbl> <chr> <lgl>  <dbl>  <dbl>
#>  1          1 Bacillus an~ Bacteria             0 log1~ NA        10 1.00e4
#>  2          2 Burkholderi~ Bacteria             0 log1~ NA        10 1.00e4
#>  3          3 Campylobact~ Bacteria             0 log1~ NA       100 1.00e6
#>  4          4 Coxiella bu~ Bacteria             0 log1~ NA        10 1.00e4
#>  5          5 Escherichia~ Bacteria             0 log1~ NA        10 1.00e4
#>  6          6 Escherichia~ Bacteria             1 log1~ NA    170000 1.70e9
#>  7          7 Francisella~ Bacteria             0 log1~ NA        10 1.00e4
#>  8          8 Legionella ~ Bacteria             0 log1~ NA        10 1.00e4
#>  9          9 Listeria mo~ Bacteria             0 log1~ NA        10 1.00e4
#> 10         10 Listeria mo~ Bacteria             0 log1~ NA        10 1.00e4
#> # ... with 27 more rows, and 8 more variables: mode <lgl>, mean <lgl>,
#> #   sd <lgl>, meanlog <lgl>, sdlog <chr>, Notes <chr>, ReferenceName <chr>,
#> #   ReferenceLink <chr>
#> 
#> $treatment
#> $treatment$processes
#> # A tibble: 72 x 15
#>    TreatmentID TreatmentName TreatmentGroup PathogenGroup type  value   min
#>          <dbl> <chr>         <chr>          <chr>         <chr> <dbl> <dbl>
#>  1           1 Conventional~ Coagulation, ~ Bacteria      unif~    NA   0.2
#>  2           1 Conventional~ Coagulation, ~ Protozoa      unif~    NA   1  
#>  3           1 Conventional~ Coagulation, ~ Viruses       unif~    NA   0.1
#>  4           2 Dissolved ai~ Coagulation, ~ Protozoa      unif~    NA   0.6
#>  5           3 High-rate cl~ Coagulation, ~ Protozoa      unif~    NA   2  
#>  6           4 Lime softeni~ Coagulation, ~ Bacteria      unif~    NA   1  
#>  7           4 Lime softeni~ Coagulation, ~ Protozoa      unif~    NA   0  
#>  8           4 Lime softeni~ Coagulation, ~ Viruses       unif~    NA   2  
#>  9           5 Granular hig~ Filtration     Bacteria      unif~    NA   0.2
#> 10           5 Granular hig~ Filtration     Protozoa      unif~    NA   0.4
#> # ... with 62 more rows, and 8 more variables: max <dbl>, mode <lgl>,
#> #   mean <dbl>, sd <lgl>, meanlog <lgl>, sdlog <chr>, ReferenceName <chr>,
#> #   ReferenceLink <chr>
#> 
#> $treatment$schemes
#> # A tibble: 5 x 4
#>   TreatmentSchemeID TreatmentSchemeName TreatmentID TreatmentName       
#>               <dbl> <chr>                     <dbl> <chr>               
#> 1                 1 default                      16 Primary treatment   
#> 2                 1 default                      17 Secondary treatment 
#> 3                 1 default                      13 Chlorine dioxide    
#> 4                 1 default                      18 Soil-Aquifer passage
#> 5                 1 default                      24 Filtration          
#> 
#> 
#> $doseresponse
#> # A tibble: 37 x 13
#>    PathogenID PathogenName PathogenGroup `Best fit model~        k  alpha
#>         <dbl> <chr>        <chr>         <chr>               <dbl>  <dbl>
#>  1          1 Bacillus an~ Bacteria      exponential       1.65e-5 NA    
#>  2          2 Burkholderi~ Bacteria      beta-Poisson     NA        0.328
#>  3          3 Campylobact~ Bacteria      beta-Poisson     NA        0.144
#>  4          4 Coxiella bu~ Bacteria      beta-Poisson     NA        0.357
#>  5          5 Escherichia~ Bacteria      exponential       2.18e-4 NA    
#>  6          6 Escherichia~ Bacteria      beta-Poisson     NA        0.155
#>  7          7 Francisella~ Bacteria      exponential       4.73e-2 NA    
#>  8          8 Legionella ~ Bacteria      exponential       5.99e-2 NA    
#>  9          9 Listeria mo~ Bacteria      exponential       1.15e-5 NA    
#> 10         10 Listeria mo~ Bacteria      beta-Poisson     NA        0.253
#> # ... with 27 more rows, and 7 more variables: N50 <dbl>, `Host type` <chr>,
#> #   `Dose units` <chr>, Route <chr>, Response <chr>, Reference <chr>,
#> #   Link <chr>
#> 
#> $health
#> # A tibble: 37 x 6
#>    PathogenID PathogenName infection_to_il~ dalys_per_case ReferenceNameIn~
#>         <dbl> <chr>                   <dbl>          <dbl> <chr>           
#>  1          1 Bacillus an~            NA           NA      <NA>            
#>  2          2 Burkholderi~            NA           NA      <NA>            
#>  3          3 Campylobact~            NA           NA      <NA>            
#>  4          4 Coxiella bu~            NA           NA      <NA>            
#>  5          5 Escherichia~            NA           NA      <NA>            
#>  6          6 Escherichia~             0.25         0.0547 Bartak et al. (~
#>  7          7 Francisella~            NA           NA      <NA>            
#>  8          8 Legionella ~            NA           NA      <NA>            
#>  9          9 Listeria mo~            NA           NA      <NA>            
#> 10         10 Listeria mo~            NA           NA      <NA>            
#> # ... with 27 more rows, and 1 more variable: ReferenceNameDalys <chr>

Created on 2021-02-05 by the reprex package (v0.3.0)

mrustl commented 3 years ago

Was not handled in #39