1+ # colbind: Wrapper around dplyr::bind_cols(). Makes sure that no rows get lost
2+ # if the data frame to add has no rows.
3+ colbind <- function (df , df_2 ) {
4+ if (nrow(df_2 ) == 0L ) {
5+ # Return the original data frame if the data frame to add has no columns
6+ if (ncol(df_2 ) == 0L ) {
7+ return (df )
8+ }
9+ # Give the data frame to add one empty row (full of NA)
10+ df_2 <- df_2 [1L , ]
11+ }
12+ dplyr :: bind_cols(df , df_2 )
13+ }
14+
115# ' @noRd
216# ' @keywords internal
317null_to_na <- function (x , na_fill = NA_character_ ) {
@@ -154,6 +168,11 @@ record_list_to_df <- function(record_list, collapse = FALSE) {
154168 collapse_val = " " ,
155169 element = 1 )
156170 }
171+
172+ replace_newline_with_semicolon <- function (text ) {
173+ gsub(" \r " , " , " , text )
174+ }
175+
157176 get_titles_style <- function (path ) get_style(c(" titles" , path ))
158177 get_period_style <- function (path ) get_style(c(" periodical" , path ))
159178 get_dates_style <- function (path ) get_style(c(" dates" , path ))
@@ -164,11 +183,11 @@ record_list_to_df <- function(record_list, collapse = FALSE) {
164183 ref_type_name = attr(get_record_entry(" ref-type" ), which = " name" ),
165184 abstract = get_abstract(record_list , collapse )
166185 ) %> %
167- dplyr :: bind_cols (get_keywords(record_list , collapse = collapse )) %> %
168- dplyr :: bind_cols (get_authors(record_list , collapse = collapse )) %> %
169- dplyr :: bind_cols (get_secondary_authors(record_list , collapse = collapse )) %> %
170- dplyr :: bind_cols (get_tertiary_authors(record_list , collapse = collapse )) %> %
171- dplyr :: bind_cols (
186+ colbind (get_keywords(record_list , collapse = collapse )) %> %
187+ colbind (get_authors(record_list , collapse = collapse )) %> %
188+ colbind (get_secondary_authors(record_list , collapse = collapse )) %> %
189+ colbind (get_tertiary_authors(record_list , collapse = collapse )) %> %
190+ colbind (
172191 tibble :: tibble(
173192 database_name = get_record_entry(" database" )[[1 ]],
174193 database_path = attr(get_record_entry(" database" ), which = " path" ),
@@ -191,13 +210,13 @@ record_list_to_df <- function(record_list, collapse = FALSE) {
191210 authaddress = get_style(" auth-address" ),
192211 edition = get_style(" edition" ),
193212 worktype = get_style(" work-type" ),
194- label = get_style(" label" ),
213+ label = replace_newline_with_semicolon( get_style(" label" ) ),
195214 isbn = get_style(" isbn" ),
196- language = get_style(" language" )
215+ language = replace_newline_with_semicolon( get_style(" language" ) )
197216 )
198217 ) %> %
199- dplyr :: bind_cols (get_pdfurls(record_list , collapse = collapse )) %> %
200- dplyr :: bind_cols (tibble :: tibble(
218+ colbind (get_pdfurls(record_list , collapse = collapse )) %> %
219+ colbind (tibble :: tibble(
201220 urls_related = get_style(c(" urls" , " related-urls" , " url" )),
202221 electronic_resource_num = get_style(" electronic-resource-num" ),
203222 custom1 = get_style(" custom1" ),
0 commit comments