@@ -45,11 +45,11 @@ vec_to_value <- function(int_vec){
45
45
sprintf(" [%s]" , paste(int_vec , collapse = " ," ))
46
46
}
47
47
48
- add_overlaps <- function (data , type = c(" all" , " pre" , " post" )) {
48
+ add_overlaps <- function (data , type = c(" all" , " pre" , " post" )) {
49
49
data <- data %> %
50
- mutate(pre_over = data.table :: shift (data $ end , type = " lag " )- data $ start + 1 )
50
+ mutate(pre_over = dplyr :: lag (data $ end )- data $ start + 1 )
51
51
data <- data %> %
52
- mutate(post_over = data.table :: shift (data $ pre_over , type = " lead " ))
52
+ mutate(post_over = dplyr :: lead (data $ pre_over ))
53
53
if (type [1 ] == " all" ){
54
54
return (data )
55
55
}
@@ -156,7 +156,7 @@ make_rle_df <- function(data, var){
156
156
values_from_positions <- function (int_vector , data ){
157
157
values <- purrrlyr :: by_row(data ,
158
158
function (x ) vec_to_value(int_vector [x $ start : x $ end ])) %> %
159
- unnest(cols = c(.out )) %> %
159
+ tidyr :: unnest(cols = c(.out )) %> %
160
160
as.data.frame()
161
161
162
162
values [, " .out" ]
@@ -165,7 +165,7 @@ values_from_positions <- function(int_vector, data){
165
165
directions_from_positions <- function (int_vector , data ){
166
166
values <- purrrlyr :: by_row(data ,
167
167
function (x ) sign(sum(int_vector [x $ start : x $ end ]))) %> %
168
- unnest(cols = c(.out )) %> %
168
+ tidyr :: unnest(cols = c(.out )) %> %
169
169
as.data.frame()
170
170
171
171
values [, " .out" ]
@@ -279,7 +279,7 @@ find_scales <- function(int_vector){
279
279
# ##### second approach#######
280
280
# types <- purrrlyr::by_row(scales,
281
281
# function(x) classify_scale(int_vector[x$start:x$end])) %>%
282
- # unnest(cols = c(.out)) %>%
282
+ # tidyr:: unnest(cols = c(.out)) %>%
283
283
# as.data.frame()
284
284
# scales$type <- types[, ".out"]
285
285
@@ -315,9 +315,6 @@ find_arpeggios <- function(int_vector){
315
315
tmp
316
316
}
317
317
318
- by_row_result_to_vec <- function (by_row_result_tbl ){
319
- by_row_result_tbl %> % select(cols = c(.out )) %> % unlist()
320
- }
321
318
322
319
find_chords <- function (int_vector ){
323
320
arp_int_vector <- sign(int_vector )* get_arp_int_from_int(int_vector )
@@ -344,11 +341,11 @@ find_chords <- function(int_vector){
344
341
}
345
342
346
343
find_trills <- function (int_vector ){
347
- sum_vector <- int_vector + data.table :: shift (int_vector , 1 , type = " lead " )
344
+ sum_vector <- int_vector + dplyr :: lead (int_vector , 1 )
348
345
zero_crossings <- intersect(which(sum_vector == 0 ),
349
- which(abs(int_vector ) %in% c(1 ,2 )))
346
+ which(abs(int_vector ) %in% c(1 , 2 )))
350
347
# print(zero_crossings)
351
- trills <- get_rle_df(sum_vector ) %> % filter(value == 0 , length > 0 , start %in% zero_crossings )
348
+ trills <- get_rle_df(sum_vector ) %> % filter(value == 0 , length > 0 , start %in% zero_crossings )
352
349
if (nrow(trills ) == 0 ){
353
350
return (NULL )
354
351
}
@@ -373,22 +370,22 @@ find_trills <- function(int_vector){
373
370
stringsAsFactors = F )
374
371
}
375
372
376
- find_bigram <- function (int_vector , bigram , value = " F" ){
377
- bigrams <- paste(int_vector , data.table :: shift (int_vector , 1 , type = " lead " ), sep = " " )
373
+ find_bigram <- function (int_vector , bigram , value = " F" ){
374
+ bigrams <- paste(int_vector , dplyr :: lead (int_vector , 1 ), sep = " " )
378
375
bigram <- paste(bigram , collapse = " " )
379
376
pos <- which(bigrams == bigram )
380
377
if (length(pos ) == 0 ){
381
378
return (NULL )
382
379
}
383
- values <- values_from_positions(int_vector , data.frame (start = pos , end = pos + 1 ))
384
- directions <- directions_from_positions(int_vector , data.frame (start = pos , end = pos + 1 ))
380
+ values <- values_from_positions(int_vector , data.frame (start = pos , end = pos + 1 ))
381
+ directions <- directions_from_positions(int_vector , data.frame (start = pos , end = pos + 1 ))
385
382
data.frame (length = 2 ,
386
383
type = " F" ,
387
384
value = values ,
388
385
direction = directions ,
389
386
start = pos ,
390
387
end = pos + 1 ,
391
- stringsAsFactors = F )
388
+ stringsAsFactors = F )
392
389
}
393
390
394
391
find_approaches <- function (int_vector ){
@@ -546,7 +543,7 @@ remove_rows <- function(data, rows){
546
543
data [left_over ,]
547
544
}
548
545
549
- remove_redundants <- function (data , debug = F ){
546
+ remove_redundants <- function (data , debug = F ){
550
547
to_remove <- which(data $ length == 2 &
551
548
data $ pre_over == 1 &
552
549
data $ post_over == 1 & data $ type %in% c(" F" , " T" ))
@@ -883,8 +880,9 @@ get_class_code_raw <- function(data, type = c("full", "reduced", "short", "exten
883
880
}
884
881
885
882
compare_freq <- function (data1 , data2 , type = " F" ){
886
- tt <- bind_rows(tibble(source = 1 , value = data1 [data1 $ type == type ,]$ value ),
887
- tibble(source = 2 , value = data2 [data2 $ type == type ,]$ value ))
883
+ tt <- bind_rows(
884
+ tibble(source = 1 , value = data1 [data1 $ type == type ,]$ value ),
885
+ tibble(source = 2 , value = data2 [data2 $ type == type ,]$ value ))
888
886
# print(tt)
889
887
tt $ value <- factor (tt $ value )
890
888
tt1 <- table(tt [tt $ source == 1 ,]$ value )
@@ -902,7 +900,7 @@ hash_wba_dataframe <- function(data){
902
900
too_long <- TRUE
903
901
print(sprintf(" Too long by %d" , tl ))
904
902
}
905
- hashes <- by_row(data , function (x ){
903
+ hashes <- purrrlyr :: by_row(data , function (x ){
906
904
hash_wba(x $ type , x $ direction , x $ length )}) %> %
907
905
select(cols = c(.out )) %> %
908
906
unlist() %> %
@@ -932,8 +930,8 @@ find_wba <- function(x, debug = F){
932
930
resolve_overlaps(debug = debug )
933
931
}
934
932
935
- recalc_pattern_classes <- function (){
936
- patterns <- lapply(unique(master $ value ), pattern_to_vec )
933
+ recalc_pattern_classes <- function (data ){
934
+ patterns <- lapply(unique(data $ value ), pattern_to_vec )
937
935
patterns_classes <- purrr :: map(patterns ,
938
936
function (x ) data.frame (pattern = vec_to_value(x ),
939
937
find_wba(x )))
0 commit comments