Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
csoneson opened this issue Apr 21, 2020 · 7 comments
Closed

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

csoneson opened this issue Apr 21, 2020 · 7 comments
Assignees

Comments

@csoneson
Copy link

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
Copy link

ycl6 commented Sep 20, 2020

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
Copy link

g-pires commented Aug 23, 2022

Hi ! Did you find a solution ?

@csoneson
Copy link
Author

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
Copy link

vjcitn commented Aug 25, 2022

@grimbough can you take a look?

@grimbough
Copy link
Collaborator

@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 grimbough self-assigned this Aug 25, 2022
@grimbough
Copy link
Collaborator

grimbough commented Nov 4, 2022

I think this is another example of the problem seen in rstudio/rmarkdown#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.

BiocStyle/R/pdf_document.R

Lines 146 to 163 in 7150c28

post_processor = function(metadata, input, output, clean, verbose) {
lines = readUTF8(output)
## insert author affiliations
lines <- modifyLines(lines, from='%% AUTH AFFIL %%', insert=auth_affil_latex(metadata))
## LaTeX soul hacks
r = "(?<=\\\\texttt{)((?:\\\\{|\\\\}|[^{}]|{(?1)})*)(?=})"
m <- gregexpr(r, lines, perl=TRUE)
regmatches(lines, m) <- lapply(regmatches(lines, m), function(x) {
# substitute all control spaces "\ " in \texttt by regular spaces
x <- gsub("\\ ", " ", x, fixed=TRUE)
})
writeUTF8(lines, output)
output
}

@csoneson
Copy link
Author

csoneson commented Nov 4, 2022

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

@csoneson csoneson closed this as completed Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants