Open seananderson opened 1 year ago
just some running notes as I get back into this, a few packages that were missing for me when rendering a FSAR were ggtext
and cowplot
moving the figure code out of the .Rmd is a good idea, that way people that only want to see the template for figures can access a script that is not dependent on rendering in csasdown
Comments from Julie about the 4-panel figure
[Yesterday 2:58 PM] Marentette, Julie (she, her / elle, la) (DFO/MPO) Right now this is the guidance for the figure
[Yesterday 2:58 PM] Marentette, Julie (she, her / elle, la) (DFO/MPO)
Figure aesthetics: The figure should be understandable in greyscale; ensure that colour is not used as the only visual means of conveying information. Use text, symbols, shapes, patterns, and / or textures to distinguish differences, and add them to the descriptions (example: say “the red dotted line” instead of “the red line”).
Figures should have as minimal text as possible and the figure caption can be used for information/descriptions as needed. Text in the figure should be easily legible when view zoom is at 100% (print view) and kept to a minimum given complexity of translating figures. Ideally any necessary text is bilingual. Font on axes should be Arial 10.
Confidence intervals should be presented graphically with shading that includes fading edges at more extreme probabilities in order to better characterize improbably but high consequence events).
Use standardized graphs templates (CSASdown) if possible.
The figure caption should be Arial font, size 10, italics, left-aligned, paragraph spacing 6 pt (0.08 in, 0.21 cm) before and 12 pt (0.17 in, 0.42 cm) after, keep lines together. The figure caption goes below the figure.
This part
Confidence intervals should be presented graphically with shading that includes fading edges
has always seemed harder to interpret to me. I'd favour multiple levels of shaded quantiles if possible. Say, 50% and 95% in darker and lighter grey.
I got pretty far down the rabbit hole of trying to get list bullet styles to work in the fsar docx. Summary: the default docx file created, e.g. by pandoc, does not have a list style applied to lists. This is a widely known pandoc limitation and there are open pandoc issues about it. A work around:
<div custom-style="fsar-bullet"> testing! </div>
and then define fsar-bullet
in the template to match the unordered list. Note it can't be a bullet itself in markdown! The style is defined as a bullet.
Alternatively
::: {custom-style="fsar-bullet"}
Mandatory bullet(s)
:::
More elegantly, do that behind the scenes, converting * text here...
to use the div style.
Then I got caught up trying to figure out how to preprocess the .Rmd as a hook in knitr/bookdown to do that...
Then I realized https://github.com/davidgohel/officedown/ carries over list styles and does a ton of other stuff that could be useful here and for res docs etc. like figure and table formatting and tables of contents.
So, maybe we should look into somehow using that with or instead of bookdown rather than trying to hack this all together ourselves? I'm not sure if they integrate. Maybe @PaulRegular has experience?
Just leaving this here so I don't lose my train of thought.
In the short term, this works:
https://github.com/pbs-assess/csasdown/commit/31f105d32f84a4f85ec38bebaab49c65bdb03c25
"Then I got caught up trying to figure out how to preprocess the .Rmd as a hook in knitr/bookdown to do that..."
If you're still interested in doing it -
Take a look at how a made a copy of the XX.rmd files as tmp_XX.rmd files in csasdown and a copy of the _bookdown.yml file and used that as the bookdown yaml file argument to render the document using bookdown. That seems to work fairly well and was the only way I could find to pre-process RMD files.
The functions are already written to do most of it.
See https://github.com/pbs-assess/csasdown/blob/f3d342dd8b4deea22d1a8bd0f9356fdb46bbf814/R/render.R#L62
and
Then I realized https://github.com/davidgohel/officedown/ carries over list styles and does a ton of other stuff that could be useful here and for res docs etc. like figure and table formatting and tables of contents.
So, maybe we should look into somehow using that with or instead of bookdown rather than trying to hack this all together ourselves? I'm not sure if they integrate. Maybe @PaulRegular has experience?
I've only contemplated making the switch from bookdown to officedown. Experience so far has been to post-process the word files produced by bookdown using officer. Indeed, the fsar branch inspired efforts to use officer to add frontmatter to a resdoc on render (see resdocx branch). e.g.:
But this is admittedly clunky and it may be more elegant to utilize officedown to impose specific formatting in the Rmd file. Just need to get around to trying it out to see what the learning curve is like / determine how difficult it might be to make the switch.
just a few ideas/notes as I am writing the draft FSAR for southern Gulf cod
copy_sty
in the ResDoc)?csasdown::csas_table
works well, so I am guessing that would be the preferred way?
- What is the best way to handle Tables? I tried making a table with markdown but it didn't produce a table in the rendered Word document. Using
csasdown::csas_table
works well, so I am guessing that would be the preferred way?
For word documents, I tend to use knitr::kable
if the tables require minimal customizations, but I resort to the flextable package when custom formatting is needed. Must admit that I've yet to use the csasdown::csas_table
function, so I don't know how flexible it is for word documents.
csasdown::csas_table()
is just a wrapper on kable()
with some defaults so that the TeX tables work for CSAS. It's not optimized for Word. Getting tables formatted correctly for FSARs is still to be determined but as @PaulRegular said, either kable() or flextable is likely the answer.
We need a better way to handle the first page so that the context text appears there appropriately and the notes existing about "Mandatory text" disappear. Perhaps copying the first page and adding an option to not overwrite when rendering would work (like we do with copy_sty in the ResDoc)?
Can you provide screenshots for this?
@seananderson this is what I mean, the part that mentions that this is a mandatory section, and the part that says to refer to the guidance document:
and my other suggestion about adding a "short title" is to avoid this where the full title is repeated in the headers and takes up too much real estate:
after using the four-panel template that was added to csasdown and that plotted simulated timeseries in a format similar to what was used in the RAM Legacy database, I had the following comments:
could the uncertainty component of the timeseries be plotted using a polygon and a line instead of three lines? if so, it should be made greyscale friendly and colorblind friendly
with ggplot, it should likely be geom_ribbon()
, with base graphics, yeah, probably polygons
should units appear on the y axis labels, or in legends, or in the figure caption?
I would think y-axis labels would be most common
in the csasdown example FASR, we should have the four-panel template in both base R and using ggplot2
yes
Also, where is that file currently? I forget. Also see: https://github.com/pbs-assess/csasdown/issues/248
@seananderson the simulated data is in R/fake-data.R and the 4-panel figure is in R/plot-timeseries.R
Then I realized https://github.com/davidgohel/officedown/ carries over list styles and does a ton of other stuff that could be useful here and for res docs etc. like figure and table formatting and tables of contents.
So, maybe we should look into somehow using that with or instead of bookdown rather than trying to hack this all together ourselves? I'm not sure if they integrate. Maybe @PaulRegular has experience?
I've continued working on experimental modifications to the resdoc_word format (resdocx branch) and I managed to utilize officedown. It's behaviour isn't always consistent with bookdown (e.g., it didn't work well with kable()
in my experimentation, but flextable()
is even more flexible). To allow both options, I worked up a resdoc_word2()
function which utilizes officedown. What do you think about trying this with the fsar function? It should help enable more fine-tune control over the formatting (e.g., list formatting, landscape sections, etc.).
By all means, go for it!
I've made some progress on tidying up the output, most of it was accomplished by pre-processing a tmp-*.Rmd file (see 74b1ffb2f0df3bffc5d08c8007515e34ba7a8aa0). However, I've yet to work out how to force the style of bullets and numbered lists. I have created a function that uses officedown in the background, and that is a hopeful path for setting default list styles.
I made some more progress (63d83725d9151daab29dfdb0e21d464cda39e6ee). The bullets and numbered lists should now follow the FSAR style by default using fsar_word2()
.
## SCIENCE ADVICE {-}
### Status {-}
- [Mandatory bullet(s)]
### Trends {-}
- [Mandatory bullet(s)]
### Environmental and Climate Change Considerations {-}
- [Mandatory bullet(s)]
Renders to:
I really appreciate all the work you have done on this new template -- it looks great! I just started setting up a FSAR for our herring stock assessment this year. I'm wondering about making a PDF instead of a Word document.. is that difficult to set up? I can try working on this if you don't mind, but I would appreciate some direction on how to start if you have time. I can start a new issue for this too if you think that's wise -- this issue may have enough in it already!
By all means give it a shot, but my thinking was we'd try to make it work with Word only output.
officedown looked promising for some of the fancier formatting stuff we might struggle with otherwise.
Thanks @seananderson, those are all good reasons.. maybe I'll leave it as is for now and tackle a PDF later if it turns out Word is not working for us.
this is on the fsar branch, which is up-to-date with main
rendering the FSAR Word document works in RStudio works when using the "Knit" button, but render()
doesn't
when we merge the fsar branch into main, this should not happen
The "Knit" button in RStudio is running csasdown::render_sar()
:
https://github.com/pbs-assess/csasdown/blob/fcfa74869e8fe06fb64b83b7c79528669119343e/inst/rmarkdown/templates/fsar/skeleton/skeleton.Rmd#L23
instead of the usual csasdown::render()
.
Update this issue as we remember what was left to do... @ricardd @jdunic @PaulRegular
If some of these require a lot of work, they can be pulled out into their own issue and broken down into steps.