@@ -16,6 +16,24 @@ give_hints_project_names <- function(project_names, dbg = TRUE) {
1616}
1717
1818
19+ get_indices_multiple_authors <- function (author_names ) {
20+ which(unlist(lapply(author_names , function (x )
21+ length(stringr :: str_split(x , pattern = " ," )[[1 ]]))) > 2 )
22+ }
23+
24+ get_indices_firstname_lastname <- function (author_names ) {
25+ which(
26+ stringr :: str_detect(author_names , " ^\\ s?\\ w+\\ .?\\ s+\\ w+" ) &
27+ ! stringr :: str_detect(author_names , " ," )
28+ )}
29+
30+
31+ get_indices_ends_with_semicolon <- function (author_names ) {
32+ which(author_names %> %
33+ stringr :: str_trim() %> %
34+ stringr :: str_detect(" .*,$" ))
35+ }
36+
1937# ' Helper Function: Give Hints For Author Names
2038# '
2139# ' @param author_names vector with author names to check
@@ -30,26 +48,24 @@ give_hints_author_names <- function(author_names, dbg = TRUE) {
3048 " Generate hints for 'Author Names'" ,
3149 dbg = dbg ,
3250 expr = {
33- multiple_authors_idx <- which(unlist(lapply(author_names , function (x )
34- length(stringr :: str_split(x , pattern = " ," )[[1 ]]))) > 2 )
35-
36- firstname_lastname_idx <- which(
37- stringr :: str_detect(author_names , " ^\\ s?\\ w+\\ .?\\ s+\\ w+" ) &
38- ! stringr :: str_detect(author_names , " ," )
39- )
40-
41- if (length(multiple_authors_idx ) > 0 ) {
42- author_names [multiple_authors_idx ] <- " fix_multiple_authors_per_line"
43- }
51+ multiple_authors_idx <- get_indices_multiple_authors(author_names )
52+ firstname_lastname_idx <- get_indices_firstname_lastname(author_names )
53+ ends_with_semicolon_idx <- get_indices_ends_with_semicolon(author_names )
4454
45- if (length(firstname_lastname_idx ) > 0 ) {
46- author_names [firstname_lastname_idx ] <- paste0(
47- " fix_firstname_lastname_with_" ,
48- " lastname_semicolon_firstname"
49- )
50- }
5155
52- replace_na_with_value(author_names , " add_author_lastname_semicolon_firstname" )
56+ author_fullname $ value %> %
57+ replace_indices_with_value(multiple_authors_idx ,
58+ " fix_multiple_authors_per_line" ,
59+ dbg ) %> %
60+ replace_indices_with_value(firstname_lastname_idx ,
61+ paste0(" fix_firstname_lastname_with_" ,
62+ " lastname_semicolon_firstname" ),
63+ dbg ) %> %
64+ replace_indices_with_value(ends_with_semicolon_idx ,
65+ " fix_author_name_by_deleting_last_semicolon" ,
66+ dbg ) %> %
67+ replace_na_with_value(" add_author_lastname_semicolon_firstname" ,
68+ dbg )
5369 }
5470 )
5571}
0 commit comments