davidgohel / ReporteRs

Note that ReporteRs has been removed from CRAN the 16th of July 2018 and is not maintained anymore. please migrate to officer.
244 stars 44 forks source link

ReporteRs-default-font changed since 0.8.6 #169

Closed gilleschapron closed 7 years ago

gilleschapron commented 7 years ago

Hi David,

I have recently updated to ReporteRs 0.8.8 and I saw a change about the way that styles are written in word document. I'm on Windows.

Just running:

library(ReporteRs)
doc <- docx()
styles( doc )
doc <- addTitle(doc, 'titre', level = 1)
doc <- addTitle(doc, 'titre', level = 2)
doc <- addTitle(doc, 'titre', level = 3)
writeDoc(doc, "test.docx")

with version 0.8.6 : all is fine. On my computer, with Calibri font by default, the titles are printed correctly in calibri with the correct font size (18, then 14, then 11).

But if I run the same code using version 0.8.7 and 0.8.8 of ReporteRs, the font type and size of titles are not respected, and are printed in Times new Roman size 11. Same problem with every style if defined in addParagraph etc...:choosen font type and size is repaced by the default one.

Did you know that problem? Can I do something to correct the behavior using 0.8.8 version?

Thank by advance for your answer, and for your job on this package.

Gilles

davidgohel commented 7 years ago

Hi Gilles

I can't reproduce the issue. Did you try to close R session and reopen it? If ReporteRs is loaded and then updated, the new jar is ignored until a fresh new session is started (the java vm do not know it has to forgot about the old jar file).

David

gilleschapron commented 7 years ago

Thank you for your quick answer.

Yes of course. In fact, I have updated the package a few days ago, but notice the problem only today. I use your package in my own that create automated report with use of templates and style definition. Since I saw no reason in my package that behavior change, I downgrade version of ReporteRs first to 0.8.7 with same problem then to 0.8.6 with no problem anymore. I have quit R between each downgrade.

Do you have tested my exemple with the 3 versions? I will send you further the results produce on my computer for each.

gilleschapron commented 7 years ago

As promised, three files produce with code:

library(ReporteRs)
doc <- docx()
doc <- addTitle(doc, "Titre 1", level = 1)
doc <- addTitle(doc, "Titre 2", level = 2)
doc <- addTitle(doc, "Titre 3", level = 3)
doc <- addParagraph(doc, paste0("ReporteRs version : ",
                                packageVersion("ReporteRs")))
writeDoc(doc, paste0("test_", packageVersion("ReporteRs"), ".docx"))

test_0.8.8.docx test_0.8.6.docx test_0.8.7.docx

Done with my mac, with the same result than on my pc.

As you can see (I hope):

davidgohel commented 7 years ago

Hi,

OK, you are talking about that change: https://github.com/davidgohel/ReporteRs/commit/8e929e654397df2b42517ae68ddbd5345a4f5e22#diff-735ba9810a9e32e2462b2c1a2ec1fe4d

What changed is this default options options("ReporteRs-default-font" = "Times New Roman").

library(ReporteRs)

options("ReporteRs-default-font" = "Times New Roman") # This is the default option, use Calibri if necessary

doc <- docx()
doc <- addTitle(doc, "Titre 1", level = 1)
doc <- addTitle(doc, "Titre 2", level = 2)
doc <- addTitle(doc, "Titre 3", level = 3)
doc <- addParagraph(doc, value = "No style associated, usage of default 'ReporteRs-default-font'")
doc <- addParagraph(doc, value = "Normal style is associated", style = "Normal")
writeDoc(doc, paste0("test_", packageVersion("ReporteRs"), ".docx"))

To use default style Normal, it needs to be specified when calling addParagraph with argument style (style = "Normal"). If not, you will use default arguments of addParagraph:

David

gilleschapron commented 7 years ago

Your right, don't understand now what's wrong... In fact, with 0.8.7, every styles are broken when lauching my function of reporting, but with 0.8.8, titles and normal style are ok, but legends of graphs and tables (defined as ordered list in my template, similar to your examples in your site) are printed in "Normal"...

I search further and I let you know if I found something.

gilleschapron commented 7 years ago

Ok, I have found what the problem is, and that's in my package.

Don't know why (perhaps because that's practical with the use of +), I have used the pot() function to concatenate string rather than the paste() one. No difference with ReporteRs versions anterior to 0.8.6, but since 0.8.7, I suppose that styles have to be define inside the pot()function...

library(ReporteRs)

doc <- docx()
styles(doc)

textpast <- paste("hello", "world")

textpot <- pot("hello")+ pot("world")

doc <- addParagraph(doc, textpast, stylename = "Lgende")
doc <- addParagraph(doc, textpot, stylename = "Lgende")

writeDoc(doc, file = "test.docx")

Some work to do to correct that in my package !

Just a question to finish, do you have, or do you plan to add the possibility to add a SEQ field for numbering legend for exemple ? I use legends as lists, but when my automated report has several hundred figures, Word goes often slower...

Many thanks again for your quick answers.

Gilles

davidgohel commented 7 years ago

Hi Gilles,

Yes, when using stylename, only use text values.

Sorry you have to change something in your code.

I made ReporteRs with two many options (trying to satisfy everybody) and documentation and maintenance became nightmare... To answer the last question, it unlikely to be implemented, I have started a new package (simpler, faster and with no java dependency) to reboot ReporteRs package. ReporteRs is maintained but new features will go into the new package (named officer for now).