11# colbind: Wrapper around dplyr::bind_cols(). Makes sure that no rows get lost
22# if the data frame to add has no rows.
3- colbind <- function (df , df_2 ) {
3+ colbind <- function (df , df_2 )
4+ {
45 if (nrow(df_2 ) == 0L ) {
6+
57 # Return the original data frame if the data frame to add has no columns
68 if (ncol(df_2 ) == 0L ) {
79 return (df )
810 }
11+
912 # Give the data frame to add one empty row (full of NA)
1013 df_2 <- df_2 [1L , ]
1114 }
15+
1216 dplyr :: bind_cols(df , df_2 )
1317}
1418
1519# ' @noRd
1620# ' @keywords internal
17- null_to_na <- function (x , na_fill = NA_character_ ) {
21+ null_to_na <- function (x , na_fill = NA_character_ )
22+ {
1823 if (is.null(x [[1 ]])) na_fill else x [[1 ]]
1924}
2025
@@ -26,14 +31,15 @@ null_to_na <- function(x, na_fill = NA_character_) {
2631# ' @return one row abstract data frame
2732# ' @export
2833# ' @importFrom dplyr bind_cols
29- get_abstract <- function (record_list , collapse = FALSE ) {
34+ get_abstract <- function (record_list , collapse = FALSE )
35+ {
3036 abstract <- record_list $ record $ abstract
3137
3238 if (is.null(abstract )) {
3339 return (NA_character_ )
3440 }
3541
36- collapse_fields(abstract , collapse , collapse_val = " " , element = 1 )
42+ collapse_fields(abstract , collapse , collapse_val = " " , element = 1L )
3743}
3844
3945# ' Helper function: get keywords from list for a reference
@@ -47,8 +53,12 @@ get_abstract <- function(record_list, collapse = FALSE) {
4753# ' @export
4854# ' @importFrom dplyr bind_cols
4955get_keywords <- function (
50- record_list , col_name = " keyword" , extract_value = " keywords" ,
51- collapse = FALSE ) {
56+ record_list ,
57+ col_name = " keyword" ,
58+ extract_value = " keywords" ,
59+ collapse = FALSE
60+ )
61+ {
5262 get_multi_entry(
5363 entries = record_list $ record [[extract_value ]],
5464 col_name = col_name ,
@@ -68,7 +78,12 @@ get_keywords <- function(
6878# ' @export
6979# ' @importFrom dplyr bind_cols
7080get_authors <- function (
71- record_list , col_name = " author" , extract_value = " authors" , collapse = FALSE ) {
81+ record_list ,
82+ col_name = " author" ,
83+ extract_value = " authors" ,
84+ collapse = FALSE
85+ )
86+ {
7287 get_multi_entry(
7388 entries = record_list $ record $ contributors [[extract_value ]],
7489 col_name = col_name ,
@@ -78,8 +93,8 @@ get_authors <- function(
7893}
7994
8095# get_multi_entry --------------------------------------------------------------
81- get_multi_entry <- function (
82- entries , col_name , element = NULL , collapse = FALSE ) {
96+ get_multi_entry <- function (entries , col_name , element = NULL , collapse = FALSE )
97+ {
8398 if (is.null(entries )) {
8499 return (stats :: setNames(nm = colname_i(col_name , 1 ), tibble :: tibble(
85100 value = NA_character_
@@ -100,15 +115,21 @@ get_multi_entry <- function(
100115}
101116
102117# collapse_fields --------------------------------------------------------------
103- collapse_fields <- function (entries ,
104- collapse = TRUE ,
105- collapse_val = " " ,
106- element ) {
118+ collapse_fields <- function (
119+ entries ,
120+ collapse = TRUE ,
121+ collapse_val = " " ,
122+ element
123+ )
124+ {
107125 if (is.list(entries ) && collapse ) {
126+
108127 paste(collapse = collapse_val , lapply(seq_along(entries ), function (i ) {
109128 null_to_na(entries [[i ]][[element ]])
110129 }))
130+
111131 } else {
132+
112133 null_to_na(entries [[element ]])
113134 }
114135}
@@ -119,8 +140,11 @@ collapse_fields <- function(entries,
119140# ' @return one row authors data frame
120141# ' @export
121142# ' @inheritParams get_authors
122- get_secondary_authors <- function (record_list , collapse = FALSE ) {
123- get_authors(record_list , " author_secondary" , " secondary-authors" , collapse )
143+ get_secondary_authors <- function (record_list , collapse = FALSE )
144+ {
145+ get_authors(
146+ record_list , " author_secondary" , " secondary-authors" , collapse
147+ )
124148}
125149
126150# ' Helper function: get tertiary authors from list for a reference
@@ -129,8 +153,11 @@ get_secondary_authors <- function(record_list, collapse = FALSE) {
129153# ' @return one row authors data frame
130154# ' @export
131155# ' @inheritParams get_authors
132- get_tertiary_authors <- function (record_list , collapse = FALSE ) {
133- get_authors(record_list , " author_tertiary" , " tertiary-authors" , collapse )
156+ get_tertiary_authors <- function (record_list , collapse = FALSE )
157+ {
158+ get_authors(
159+ record_list , " author_tertiary" , " tertiary-authors" , collapse
160+ )
134161}
135162
136163# ' Helper function: get pdfurls from list for a reference
@@ -143,7 +170,8 @@ get_tertiary_authors <- function(record_list, collapse = FALSE) {
143170# ' @export
144171# ' @importFrom dplyr bind_cols
145172# ' @importFrom tibble tibble
146- get_pdfurls <- function (record_list , col_name = " urls_pdf" , collapse = FALSE ) {
173+ get_pdfurls <- function (record_list , col_name = " urls_pdf" , collapse = FALSE )
174+ {
147175 get_multi_entry(
148176 entries = record_list $ record $ urls $ `pdf-urls` ,
149177 col_name = col_name ,
@@ -160,13 +188,17 @@ get_pdfurls <- function(record_list, col_name = "urls_pdf", collapse = FALSE) {
160188# ' @export
161189# ' @importFrom dplyr bind_cols
162190# ' @importFrom tibble tibble
163- record_list_to_df <- function (record_list , collapse = FALSE ) {
191+ record_list_to_df <- function (record_list , collapse = FALSE )
192+ {
164193 get_record_entry <- function (path ) get_list_entry(record_list $ record , path )
194+
165195 get_style <- function (path ) {
166- collapse_fields(get_record_entry(path ),
167- collapse = collapse ,
168- collapse_val = " " ,
169- element = 1 )
196+ collapse_fields(
197+ get_record_entry(path ),
198+ collapse = collapse ,
199+ collapse_val = " " ,
200+ element = 1L
201+ )
170202 }
171203
172204 replace_newline_with_semicolon <- function (text ) {
@@ -239,7 +271,8 @@ record_list_to_df <- function(record_list, collapse = FALSE) {
239271# ' refs_df <- create_references_df(endnote_list)
240272# ' head(refs_df)
241273# '
242- create_references_df <- function (endnote_list , collapse = FALSE ) {
274+ create_references_df <- function (endnote_list , collapse = FALSE )
275+ {
243276 extract_values_from_list <- lapply(seq_along(endnote_list ), function (rec_id ) {
244277 record_list_to_df(record_list = endnote_list [rec_id ], collapse )
245278 })
0 commit comments