ToonVanDaele / trias-test

test repository ofr trias
0 stars 0 forks source link

Code to create data.frame with model results #1

Closed damianooldoni closed 4 years ago

damianooldoni commented 4 years ago

Code from line 125: https://github.com/ToonVanDaele/trias-test/blob/master/R/main_FULL.R#L125 to line 150 can be written in a compact way. Please give a look here below. First lines are just to read data:

## Get data
result_dt <- readRDS(here("data", "interim", "result_dt.RDS"))
result_gam_occ <- readRDS(here("data", "interim", "result_gam_lcount.RDS"))
result_gam_aoo <- readRDS(here("data", "interim", "result_gam_lpa.RDS"))

df_n_obs_n_cells <- read_tsv(here("data", "interim", "df_n_obs_n_cells.tsv"),
                             na = "")

result_models <- list(result_dt, result_gam_occ, result_gam_aoo)

# Make a unique data.frame from evaluation models
result_models_df <- 
  map(result_models, ~ .x %>%
        map_dfr(~ .x %>% map_dfr("em")))

result_models_df <-
  map_dfr(result_models_df, ~ .x  %>% bind_rows) %>%
  spread(key = method_em, value = em)

So, by making a list of results:

result_models <- list(result_dt, result_gam_occ, result_gam_aoo)

you can process all of them easily. This will also help avoid copy-paste errors...

damianooldoni commented 4 years ago

@ToonVanDaele : has this chunk code been useful? If this step has been done, then we can close this issue. Thanks.

ToonVanDaele commented 4 years ago

Yes, thanks for the code. I'll close this issue