R , Excel and RTF output with blank line

by user3370470   Last Updated January 14, 2018 12:26 PM

I have a small excel dataset with cells in text format. My code R is a modification of herblabel function (found in https://github.com/helixcn) where each row and cells excel data are taken by the function and finally put in an RTF output for making printed labels. In my R code, the columns are under the format "DetNov1_XXXXX" or "DetNov1_XXXXX_XXXXX" with XXXX are other specific words (for example: locality, day, determinator, ...).

For one line of RTF output, my code is :

    ifelse((is.na(herbdat$DetNov1_Determinateur_Lieu)), 
            paste("{\\pard\\keep\\keepn\\fi0\\li0\\qc",
                  "\\sb180", "\\sb20",
                  "\\sa20\\fs18 ",
                  ifelse(((is.na(herbdat$DetNov1_Determinateur_Date_Jour) )&
                          (is.na(herbdat$DetNov1_Determinateur_Date_Mois) )&
                          (is.na(herbdat$DetNov1_Determinateur_Date_Annee))),
                           "",
                           ifelse(((is.na(herbdat$DetNov1_Determinateur_Date_Jour))&
                                   (is.na(herbdat$DetNov1_Determinateur_Date_Mois))),
                                    paste("{\\pard\\keep\\keepn\\fi0\\li0\\qc",
                                          "\\sb180", "\\sb20",
                                          "\\sa20\\fs18 ",
                                          ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Annee), "", as.character(herbdat$DetNov1_Determinateur_Date_Annee)),
                                          "", 
                                          "\\par }",sep = "")
                                          ,
                                    ifelse((is.na(herbdat$DetNov1_Determinateur_Date_Jour)),
                                            paste("{\\pard\\keep\\keepn\\fi0\\li0\\qc",
                                                  "\\sb180", "\\sb20",
                                                  "\\sa20\\fs18 ",
                                                  ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Mois), "", firstletteruppercase(as.character(herbdat$DetNov1_Determinateur_Date_Mois))),
                                                  " ",
                                                  ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Annee), "", as.character(herbdat$DetNov1_Determinateur_Date_Annee)),
                                                  "", 
                                                  "\\par }",sep = "")
                                                  ,
                                            paste("{\\pard\\keep\\keepn\\fi0\\li0\\qc",
                                                  "\\sb180", "\\sb20",
                                                  "\\sa20\\fs18 ",
                                                  ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Jour), "", as.character(herbdat$DetNov1_Determinateur_Date_Jour)),
                                                  " ",
                                                  ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Mois), "", as.character(herbdat$DetNov1_Determinateur_Date_Mois)),
                                                  " ",
                                                  ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Annee), "", as.character(herbdat$DetNov1_Determinateur_Date_Annee)),
                                                  "", 
                                                  "\\par }",sep = "")
                                          )
                                 )
                        ),
                  "\\par }", sep = "")
            ,
            paste("{\\pard\\keep\\keepn\\fi0\\li0\\qc",
                  "\\sb180", "\\sb20",
                  "\\sa20\\fs18 ",
                  ifelse(is.na(herbdat$DetNov1_Determinateur_Lieu), "", as.character(herbdat$DetNov1_Determinateur_Lieu)),
                  ifelse(((is.na(herbdat$DetNov1_Determinateur_Date_Jour) )&
                          (is.na(herbdat$DetNov1_Determinateur_Date_Mois) )&
                          (is.na(herbdat$DetNov1_Determinateur_Date_Annee))),
                           "",
                           ifelse(((is.na(herbdat$DetNov1_Determinateur_Date_Jour))&
                                   (is.na(herbdat$DetNov1_Determinateur_Date_Mois))),
                                    paste("{\\pard\\keep\\keepn\\fi0\\li0\\qc",
                                          "\\sb180", "\\sb20",
                                          "\\sa20\\fs18 ",
                                          ", ",
                                          ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Annee), "", as.character(herbdat$DetNov1_Determinateur_Date_Annee)),
                                          "", 
                                          "\\par }",sep = "")
                                          ,                              
                                    ifelse((is.na(herbdat$DetNov1_Determinateur_Date_Jour)),
                                            paste("{\\pard\\keep\\keepn\\fi0\\li0\\qc",
                                                  "\\sb180", "\\sb20",
                                                  "\\sa20\\fs18 ",
                                                  ", ",
                                                  ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Mois), "", as.character(herbdat$DetNov1_Determinateur_Date_Mois)),
                                                  " ",
                                                  ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Annee), "", as.character(herbdat$DetNov1_Determinateur_Date_Annee)),
                                                  "", 
                                                  "\\par }",sep = "")
                                                  ,
                                            paste("{\\pard\\keep\\keepn\\fi0\\li0\\qc",
                                                  "\\sb180", "\\sb20",
                                                  "\\sa20\\fs18 ",
                                                  ", ",
                                                  ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Jour), "", as.character(herbdat$DetNov1_Determinateur_Date_Jour)),
                                                  " ",
                                                  ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Mois), "", as.character(herbdat$DetNov1_Determinateur_Date_Mois)),
                                                  " ",
                                                  ifelse(is.na(herbdat$DetNov1_Determinateur_Date_Annee), "", as.character(herbdat$DetNov1_Determinateur_Date_Annee)),
                                                  "", 
                                                  "\\par }",sep = "")
                                         )
                                 )
                        ),
                  "\\par }", sep = "")
          ),

What I don't understand is why this code put an additional blank line under my output. For example the output is :

enter image description here

When I want :

enter image description here

What or where is the error ?

I don't have this blank line when the code is smaller. For example theses two below lines of code don't put the additionnal blank line.

    ifelse(is.na(herbdat$DetNov1_Note), 
           "",        
           paste("{\\pard\\fs1\\sl0 {\\*\\do\\dobxcolumn\\dobypara\\dodhgt\\dpline\\dpxsize5386\\dplinesolid\\dplinew5\\dplinedot} \\par}",
                 "{\\pard\\keep\\keepn\\fi0\\li0\\qj\\brsp20\\sb100\\sa50\\fs18 Note complémentaire : ", 
                  ifelse(is.na(herbdat$DetNov1_Note), "", as.character(herbdat$DetNov1_Note)), "\\par}", sep = "")
          ),
    ifelse(is.na(herbdat$DetNov1_Projet), 
           "", 
           paste("{\\pard\\keep\\keepn\\fi0\\li0\\qc\\brsp20\\sb100\\sa50\\fs18 ", as.character(herbdat$DetNov1_Projet), "\\par }", sep = "")
          ),

As an advance, thank you for any help.

Tags : r excel rtf


Related Questions


Median/average does not return the right values

Updated April 20, 2015 01:11 AM


Remove texts between two symbol, including identifiers

Updated November 07, 2017 12:26 PM

Solver.xlam is missing?

Updated December 04, 2017 02:26 AM

Excel List Data Validation

Updated July 11, 2018 20:26 PM