dataMaid icon indicating copy to clipboard operation
dataMaid copied to clipboard

Problems rendering PDF data report from within markdown chunk

Open ekstroem opened this issue 6 years ago • 5 comments

This little bit of code will produce an error if output="html" is removed or changed to output="pdf" when calling makeDataReport().

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

```{r lalssldl}
library(dataMaid)
data(trees)
makeDataReport(trees, output = "html",  replace=TRUE)
```

ekstroem avatar Feb 14 '18 20:02 ekstroem

Have you identified the issue behind this bug? If so, is it a big hairy bug not for the faint of heart? I still get it with: dataMaid v1.2.0 [Pkg: 2018-10-03 from CRAN (R 3.5.3)] R version 3.5.3 (2019-03-11). Platform: x86_64-w64-mingw32/x64 (64-bit)(Windows >= 8 x64 (build 9200)).

Looking at the tex file, I see unbalanced \begin{minipage} \end{minipage} <<<< missing at the bottom, although the Rmd file has both \bmini and \emini \bminitwo \emini <<<<<< present

My use-case is actually more complex: generating the Rmd with render = FALSE, openResult = FALSE, then promoting headings 1 # level, then inserting that Rmd file back into my main document as an appendix via chunk options child = tmp.Rmd, which works beautifully for html but fails for pdf. I'm trying to decide whether to look in your code in case it's a relatively easy bug I might be competent to fix, or just add some form of post-processing the Rmd to my heading promotion filter.

tphilippi avatar Apr 09 '19 23:04 tphilippi

To be honest I haven't looked at this bug in quite some time. Will try to figure out exactly what is causing it

ekstroem avatar Apr 19 '19 16:04 ekstroem

Hmm. I just did a check with the most recent version on GitHub and I'm not receiving an error anymore. At least not for the MWE I listed above.

If I run

makeDataReport(trees, replace=TRUE,  render = FALSE, openResult = FALSE)

then it appears to work (at least in the sense that an error isn't thrown).

Could you provide a simple example matching your situation which faults? Oh ... and try with the GitHub version

ekstroem avatar May 01 '19 05:05 ekstroem

I just checked with R 3.6.0, dataMaid_1.2.0, pandoc 2.7.2, MiKTeX 2.9 on MSwin . Even running from the R console, omitting Rmd & R Studio, I get an Rmd intermediate file but not the pdf file, as R throws the following error after the warning to make sure the pdf file isn't open:

! LaTeX Error: \begin{minipage} on input line 545 ended by \end{document}.

Error: Failed to compile codebook_airquality.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See codebook_airquality.log for more info.

If I open that Rmd file and knit to html it works, but If I knit to pdf again it throws an error and fails. The codebook_airquality.log file has lots of Overfull \hbox messages in the log file (attached) and then an unmatched \begin{minipage}

! LaTeX Error: \begin{minipage} on input line 545 ended by \end{document}.

My simple example:

library(datasets) library(dataMaid) str(airquality) makeCodebook(airquality, output = 'pdf', replace = TRUE) sessionInfo() rmarkdown::pandoc_version()

Do you have a different LaTeX engine or version of pandoc in your toolchain? Or are you running on a different (better) OS?

codebook_airquality.log

tphilippi avatar May 20 '19 17:05 tphilippi

Just tried to run your example and got a nice pdf-file out of this. Did you use the most recent version of dataMaid from github or the CRAN version. I think the error you encounter here might be similar to #45 and that should be fixed in the newest version. I pushed a copy to CRAN yesterday (v 1.3.0) so please try that and see if it fixes something.

My session_info() output can be seen below.

> sessionInfo()
R version 3.6.0 (2019-04-26)
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/3.6/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    
[5] datasets  methods   base     

other attached packages:
[1] pander_0.6.3   ggplot2_3.1.1 
[3] dataMaid_1.2.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1        pillar_1.4.0     
 [3] compiler_3.6.0    DEoptimR_1.0-8   
 [5] plyr_1.8.4        forcats_0.4.0    
 [7] tools_3.6.0       digest_0.6.18    
 [9] evaluate_0.13     jsonlite_1.6     
[11] tibble_2.1.1      gtable_0.3.0     
[13] pkgconfig_2.0.2   rlang_0.3.4      
[15] whoami_1.3.0      rstudioapi_0.10  
[17] yaml_2.2.0        xfun_0.7         
[19] haven_2.1.0       gridExtra_2.3    
[21] withr_2.1.2       stringr_1.4.0    
[23] knitr_1.22.8      httr_1.4.0       
[25] dplyr_0.8.1.9000  hms_0.4.2        
[27] grid_3.6.0        tidyselect_0.2.5 
[29] reshape_0.8.8     glue_1.3.1       
[31] robustbase_0.93-5 R6_2.4.0         
[33] rmarkdown_1.12    purrr_0.3.2      
[35] magrittr_1.5      scales_1.0.0     
[37] htmltools_0.3.6   rsconnect_0.8.13 
[39] assertthat_0.2.1  colorspace_1.4-1 
[41] labeling_0.3      tinytex_0.13     
[43] stringi_1.4.3     lazyeval_0.2.2   
[45] munsell_0.5.0     crayon_1.3.4     
> rmarkdown::pandoc_version()
[1] ‘2.7.1’

ekstroem avatar Jun 08 '19 21:06 ekstroem