R/create_artist_selection.R

create_artist_selection <- function(.edges, .artists,
                                    .max_years_between_birth_first_exh,
                                    .count_only_exh_alive = TRUE,
                                    .period_start, .period_end, #.max_year_gap_exh_in_period = NULL,
                                    .num_exh_in_period){



  # count artists' exhibitions
  exh_in_period <- igraph::as_data_frame(galsimple) %>%

    # keep artists that have been alive during exhibition
    inner_join(.artists, by = c("artist_id" = "id")) %>%

    {if(.count_only_exh_alive == TRUE)
      filter(., exh_start_Y_from <= if_else(!is.na(death), death, as.integer(birth + 95)))
      } %>%

    # keep exhibitions that took place during defined period
    filter(exh_start_Y_from >= .period_start,
           exh_start_Y_from <= .period_end)


  artist_first_last_exh_in_period <- exh_in_period %>%
    group_by(artist_id) %>%
    summarise(min_exh_yr_from = min(exh_start_Y_from),
              max_exh_yr_from = max(exh_start_Y_from))


  period_exh_count <- exh_in_period %>%

    # join first and last exhibition
    left_join(artist_first_last_exh_in_period, by = c("artist_id")) %>%
    filter(min_exh_yr_from <= birth + .max_years_between_birth_first_exh, # first exh first n years after birth
           min_exh_yr_from >= .period_start)  %>% # first exh in period of observation


    # count those exhibitions
    group_by(artist_id) %>%
    summarise(exh_during_period = n()) %>%

    # keep artists with at leat n exhibition during period
    filter(exh_during_period >= .num_exh_in_period)




  artists_lean <- .artists %>% inner_join(period_exh_count, by = c("id" = "artist_id")) %>%
    left_join(artist_first_last_exh_in_period, by = c("id" = "artist_id"))



  # if(!is(.max_year_gap_exh_in_period)){
  #
  #   # how many years are between the exhibitions?
  #   artist_exh_year_gap <- .exhibitions %>%
  #
  #     # year gap is not meaningful for artists with only 1 exhibition
  #     inner_join(period_exh_count, by = "artist_id") %>%
  #
  #     arrange(artist_id, exh_start_Y) %>%
  #     group_by(artist_id) %>%
  #     mutate(year_gap = exh_start_Y - lag(exh_start_Y)) %>%
  #     ungroup()
  #
  #   # compute average / max / min time span between exhibitions per artist
  #   artist_exh_year_gap_summary <- artist_exh_year_gap %>%
  #     group_by(artist_id) %>%
  #     summarise(avg_year_gap = mean(year_gap, na.rm = T),
  #               max_year_gap = max(year_gap, na.rm = T),
  #               min_year_gap = max(year_gap, na.rm = T)
  #     )
  #
  #   # merge clean artist df
  #   artists_lean <- .artists %>%
  #     # remove impossible birth death combinations
  #     filter(birth <= if_else(!is.na(death), death, birth), # birth later than death
  #            birth <= ifelse(!is.na(death), death - 20, birth) ) %>% # got older than at least n years (excludes groups)
  #     mutate(lifespan = death - birth) %>%
  #     # join exhibition details computed above
  #     inner_join(lifetime_exh_count, by = c("id" = "artist_id")) %>%
  #     inner_join(artist_exh_year_gap_summary, by = c("id" = "artist_id")) %>%
  #     filter(birth >= .birth,
  #            exh_total >= .exh_total,
  #            max_year_gap <= .max_year_gap)
  # }


  return(artists_lean)


}
Framus94/HierarchiesAndCareers documentation built on June 5, 2019, 8:52 a.m.