Bioconductor / BiocStyle

Issues and pull requests for BiocStyle should go here.
12 stars 19 forks source link

Author unexpectedly set to "immediate" in BiocStyle::pdf_document #73

Closed csoneson closed 1 year ago

csoneson commented 4 years ago

Hello,

I'm running into an issue with BiocStyle that I can't quite track down, and I was wondering whether you might have any pointers. The issue appears in the alevinQC package (https://github.com/csoneson/alevinQC). I'm running the following code (requires the current GitHub/Bioc devel (3.11) version of alevinQC):

library(alevinQC)
alevinQCReport(baseDir = system.file("extdata/alevin_example_v0.14",
                                     package = "alevinQC"),
               sampleId = "example", outputFile = "alevinReport.pdf",
               outputFormat = "BiocStyle::pdf_document",
               outputDir = ".", forceOverwrite = TRUE)

This will read some data from the provided baseDir and subsequently call rmarkdown::render() with a template provided here. This template is intended to put the current version of alevinQC in the "author" field. However, with BiocStyle::pdf_document specified as the output format, the author field is instead set to "immediate", and I get the following warnings:

Warning messages:
1: LaTeX Warning: You have requested package `/Library/Frameworks/R.framework/Vers
ions/4.0/Resources/library/BiocStyle/resources/tex/Bioconductor',
               but the package provides `Bioconductor'.
Package geometry Warning: Over-specification in `h'-direction.
    `width' (384.1122pt) is ignored.
Package Fancyhdr Warning: \fancyhead's `E' option without twoside option is use
less on input line 162.
LaTeX Warning: No \author given. 
2: In grep(from, lines, fixed = fixed) : input string 2 is invalid UTF-8
3: In grep(from, lines, fixed = fixed) : input string 9 is invalid UTF-8
4: In grep(from, lines, fixed = fixed) : input string 10 is invalid UTF-8
5: In grep(from, lines, fixed = fixed) : input string 11 is invalid UTF-8
6: In grep(from, lines, fixed = fixed) : input string 12 is invalid UTF-8
7: LaTeX Warning: You have requested package `/Library/Frameworks/R.framework/Vers
ions/4.0/Resources/library/BiocStyle/resources/tex/Bioconductor',
               but the package provides `Bioconductor'.
Package geometry Warning: Over-specification in `h'-direction.
    `width' (384.1122pt) is ignored.
Package Fancyhdr Warning: \fancyhead's `E' option without twoside option is use
less on input line 162.
LaTeX Warning: No \author given. 

I think the first LaTeX warnings are fine (or at least not causing this particular problem), and that the issue is whatever causes the "No \author given". I'm not quite sure what's happening though - I get the expected output with BiocStyle::html_document, rmarkdown::html_document and rmarkdown::pdf_document. Things also work fine if I copy the YAML header from the template above into an empty .Rmd file and rmarkdown::render() it with the output format set to BiocStyle::pdf_document.

If you have any ideas where this might come from or how I could try to track it down, that would be super helpful. Thanks in advance!

Session info (I have also tried on other systems with similar results) ``` R Under development (unstable) (2020-03-13 r77937) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS High Sierra 10.13.6 Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] BiocStyle_2.15.8 alevinQC_1.3.3 loaded via a namespace (and not attached): [1] tximport_1.15.13 tinytex_0.22 tidyselect_1.0.0 [4] xfun_0.13 remotes_2.1.1 purrr_0.3.3 [7] colorspace_1.4-1 vctrs_0.2.4 htmltools_0.4.0 [10] yaml_2.2.1 rlang_0.4.5 pkgbuild_1.0.6 [13] pillar_1.4.3 later_1.0.0 glue_1.4.0 [16] withr_2.1.2 RColorBrewer_1.1-2 lifecycle_0.2.0 [19] plyr_1.8.6 stringr_1.4.0 munsell_0.5.0 [22] gtable_0.3.0 htmlwidgets_1.5.1 evaluate_0.14 [25] labeling_0.3 knitr_1.28 GGally_1.5.0 [28] callr_3.4.3 fastmap_1.0.1 httpuv_1.5.2 [31] ps_1.3.2 curl_4.3 fansi_0.4.1 [34] highr_0.8 Rcpp_1.0.4.6 xtable_1.8-4 [37] backports_1.1.6 scales_1.1.0 promises_1.1.0 [40] DT_0.13 BiocManager_1.30.10 magick_2.3 [43] farver_2.0.3 mime_0.9 rjson_0.2.20 [46] ggplot2_3.3.0 digest_0.6.25 stringi_1.4.6 [49] bookdown_0.18 processx_3.4.2 dplyr_0.8.5 [52] shiny_1.4.0.2 rprojroot_1.3-2 grid_4.0.0 [55] cowplot_1.0.0 cli_2.0.2 tools_4.0.0 [58] magrittr_1.5 tibble_3.0.0 crayon_1.3.4 [61] pkgconfig_2.0.3 ellipsis_0.3.0 prettyunits_1.1.1 [64] shinydashboard_0.7.1 assertthat_0.2.1 rmarkdown_2.1.2 [67] reshape_0.8.8 rstudioapi_0.11 R6_2.4.1 [70] compiler_4.0.0 ```
ycl6 commented 4 years ago

I have the same problem with BiocStyle::pdf_document when I convert Rmd using rmarkdown::render

Warning messages:
1: LaTeX Warning: You have requested package `/home/ihsuan/miniconda3/lib/R/librar
y/BiocStyle/resources/tex/Bioconductor',
               but the package provides `Bioconductor'.
Package geometry Warning: Over-specification in `h'-direction.
    `width' (384.1122pt) is ignored.
Package Fancyhdr Warning: \fancyhead's `E' option without twoside option is use
less on input line 173.
LaTeX Warning: No \author given. 
2: In grep(from, lines, fixed = fixed) : input string 2 is invalid UTF-8
3: In grep(from, lines, fixed = fixed) : input string 9 is invalid UTF-8
4: In grep(from, lines, fixed = fixed) : input string 10 is invalid UTF-8
5: In grep(from, lines, fixed = fixed) : input string 11 is invalid UTF-8
6: In grep(from, lines, fixed = fixed) : input string 12 is invalid UTF-8
7: LaTeX Warning: You have requested package `/home/ihsuan/miniconda3/lib/R/librar
y/BiocStyle/resources/tex/Bioconductor',
               but the package provides `Bioconductor'.
Package geometry Warning: Over-specification in `h'-direction.
    `width' (384.1122pt) is ignored.
Package Fancyhdr Warning: \fancyhead's `E' option without twoside option is use
less on input line 173.
LaTeX Warning: No \author given. 
R version 3.6.3
rmarkdown_2.3
BiocStyle_2.14.4
g-pires commented 2 years ago

Hi ! Did you find a solution ?

csoneson commented 2 years ago

On my side, I just tried rerunning the code I posted above and it seems I still have the same issue (with BiocStyle v2.25.0).

vjcitn commented 2 years ago

@grimbough can you take a look?

grimbough commented 2 years ago

@grimbough can you take a look?

I'm on parental leave until the end of September, but happy to take a look at this once I'm back at work.

grimbough commented 1 year ago

I think this is another example of the problem seen in https://github.com/rstudio/rmarkdown/issues/2264

Consider the following test.Rmd file:

---
title: "Vignette Title"
author: "Mike Smith"
output:
  BiocStyle::pdf_document
---

Rendering this with the defaults is fine:

rmarkdown::render("test.Rmd")
Warning: LaTeX Warning: You have requested package `/mnt/data/R-lib/4.3-bioc_3.17/BiocStyle/resources/tex/Bioconductor',
Warning:                but the package provides `Bioconductor'.

Output created: test.pdf

However, supplying an output file with an extension gives the warning about missing authors:

rmarkdown::render("test.Rmd", output_file = "test_bad.pdf")
Warning: LaTeX Warning: You have requested package `/mnt/data/R-lib/4.3-bioc_3.17/BiocStyle/resources/tex/Bioconductor',
Warning:                but the package provides `Bioconductor'.
Warning: LaTeX Warning: No \author given.

Output created: /tmp/test_bad.pdf
Warning messages:
1: In grep(from, lines, fixed = fixed) : input string 2 is invalid UTF-8
2: In grep(from, lines, fixed = fixed) : input string 9 is invalid UTF-8
...

If we try to give a file name without extension, it's all fine again. You even get the correct extension in the end.

rmarkdown::render("test.Rmd", output_file = "test_good")
Warning: LaTeX Warning: You have requested package `/mnt/data/R-lib/4.3-bioc_3.17/BiocStyle/resources/tex/Bioconductor',
Warning:                but the package provides `Bioconductor'.

Output created: /tmp/test_good.pdf

The reason this happens is that when you don't provide a file extension, the post_processor() code below gets run on the .tex file before it is rendered by Latex. However, when you do provide a file extension, rmarkdown ends up passing the PDF document to this function, which is too late and hence it fails. I consider this a bug in rmarkdown, but it doesn't look like any change has occurred after the issue at the top of this post.

An inelegant solution for alevinQC would be to remove your code checking the file extensions in the case of using BiocStyle::pdf_document, pass the output file name without extension, and assume the .pdf will be appended anyway.

https://github.com/Bioconductor/BiocStyle/blob/7150c289519d4e20c885812f6a8abc8f9cba98fb/R/pdf_document.R#L146-L163

csoneson commented 1 year ago

Ooh, nice detective work! I have implemented the workaround you suggest in alevinQC, and it seems to work just fine. Thanks!