@@ -2347,7 +2347,7 @@ get_nth_release <- function(df, n = 0, diagonal = FALSE) {
23472347 dplyr :: summarise(max_time = max(.data $ time ), .groups = " drop" ),
23482348 by = c(" id" , " min_pub_date" = " pub_date" )
23492349 ) %> %
2350- dplyr :: select(.data $ id , .data $ max_time )
2350+ dplyr :: select(" id " , " max_time" )
23512351
23522352 nth_release <- nth_release %> %
23532353 dplyr :: left_join(diagonal_thresholds , by = " id" ) %> %
@@ -2456,10 +2456,28 @@ get_first_release <- function(df, diagonal = FALSE) {
24562456 }
24572457
24582458 if (diagonal ) {
2459- df <- df %> %
2460- dplyr :: filter(
2461- ! dplyr :: lead(.data $ pub_date ) == (.data $ pub_date )
2462- )
2459+ if (" id" %in% colnames(df )) {
2460+ diagonal_thresholds <- df %> %
2461+ dplyr :: group_by(.data $ id ) %> %
2462+ dplyr :: summarise(min_pub_date = min(.data $ pub_date ), .groups = " drop" ) %> %
2463+ dplyr :: left_join(
2464+ df %> %
2465+ dplyr :: group_by(.data $ id , .data $ pub_date ) %> %
2466+ dplyr :: summarise(max_time = max(.data $ time ), .groups = " drop" ),
2467+ by = c(" id" , " min_pub_date" = " pub_date" )
2468+ ) %> %
2469+ dplyr :: select(" id" , " max_time" )
2470+
2471+ df <- df %> %
2472+ dplyr :: left_join(diagonal_thresholds , by = " id" ) %> %
2473+ dplyr :: filter(.data $ time > = .data $ max_time ) %> %
2474+ dplyr :: select(- " max_time" )
2475+ } else {
2476+ min_pub_date <- min(df $ pub_date )
2477+ max_time <- max(df $ time [df $ pub_date == min_pub_date ])
2478+ df <- df %> %
2479+ dplyr :: filter(.data $ time > = max_time )
2480+ }
24632481 }
24642482
24652483 # Add the class only if it is not already present
0 commit comments