Reputation: 314
I recently generated a knitr HTML report in Rstudio on a Mac. I then looked into automating the generation of such a report on Ubuntu on the command line.
I was surprised to see that the formatting looks slightly different for plots and tables. Additionally, the table of contents and header (basically anything in the YAML portion of the Rmd file) didn't render in the output html document.
For example, here is a table from the Rstudio report:
And here is a table from the command line generated report:
I prefer the Rstudio table because I think it's a bit easier to read.
To compile the report on the command line, I used the following command:
Rscript -e "require(knitr); require(markdown); knit('${OUTFILE}', '${OUTFILE}.md'); markdownToHTML('${OUTFILE}.md', '${OUTFILE}.html')"
To generate the Rstudio report, I just clicked the compile button.
Does anyone have an idea how I can adjust the formatting in the command-line generated report to look more like what Rstudio does?
sessionInfo()
command shows a yaml package that was loaded by another package. I verified that it is also available on Ubuntu but it didn't get loaded there.
sessionInfo() # on Mac
## R version 3.3.1 (2016-06-21)
## Platform: x86_64-apple-darwin13.4.0 (64-bit)
## Running under: OS X 10.11.6 (El Capitan)
##
## 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] parallel stats4 stats graphics grDevices utils datasets
## [8] methods base
##
## other attached packages:
## [1] RColorBrewer_1.1-2 pheatmap_1.0.8
## [3] genefilter_1.56.0 ggplot2_2.1.0
## [5] DESeq2_1.14.0 SummarizedExperiment_1.4.0
## [7] Biobase_2.34.0 GenomicRanges_1.26.1
## [9] GenomeInfoDb_1.10.0 IRanges_2.8.0
## [11] S4Vectors_0.12.0 BiocGenerics_0.20.0
## [13] tximport_1.2.0 knitr_1.14
##
## loaded via a namespace (and not attached):
## [1] locfit_1.5-9.1 splines_3.3.1 lattice_0.20-33
## [4] colorspace_1.2-7 htmltools_0.3.5 yaml_2.1.13
## [7] chron_2.3-47 survival_2.40-1 XML_3.98-1.4
## [10] foreign_0.8-66 DBI_0.5-1 BiocParallel_1.8.1
## [13] plyr_1.8.4 stringr_1.1.0 zlibbioc_1.20.0
## [16] munsell_0.4.3 gtable_0.2.0 evaluate_0.10
## [19] labeling_0.3 latticeExtra_0.6-28 geneplotter_1.52.0
## [22] AnnotationDbi_1.36.0 highr_0.6 htmlTable_1.7
## [25] Rcpp_0.12.7 acepack_1.4.1 xtable_1.8-2
## [28] scales_0.4.0 formatR_1.4 Hmisc_4.0-0
## [31] annotate_1.52.0 XVector_0.14.0 gridExtra_2.2.1
## [34] digest_0.6.10 stringi_1.1.2 grid_3.3.1
## [37] tools_3.3.1 bitops_1.0-6 magrittr_1.5
## [40] RCurl_1.95-4.8 tibble_1.2 RSQLite_1.0.0
## [43] Formula_1.2-1 cluster_2.0.4 Matrix_1.2-6
## [46] data.table_1.9.6 assertthat_0.1 rmarkdown_1.1
## [49] rpart_4.1-10 nnet_7.3-12
sessionInfo() # on Ubuntu
## R version 3.3.2 (2016-10-31)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 16.04 LTS
##
## locale:
## [1] C
##
## attached base packages:
## [1] parallel stats4 methods stats graphics grDevices utils
## [8] datasets base
##
## other attached packages:
## [1] RColorBrewer_1.1-2 pheatmap_1.0.8
## [3] genefilter_1.56.0 ggplot2_2.2.1
## [5] DESeq2_1.14.1 SummarizedExperiment_1.4.0
## [7] Biobase_2.34.0 GenomicRanges_1.26.2
## [9] GenomeInfoDb_1.10.2 IRanges_2.8.1
## [11] S4Vectors_0.12.1 BiocGenerics_0.20.0
## [13] tximport_1.2.0 markdown_0.7.7
## [15] knitr_1.15.1
##
## loaded via a namespace (and not attached):
## [1] locfit_1.5-9.1 splines_3.3.2 lattice_0.20-34
## [4] colorspace_1.3-2 htmltools_0.3.5 base64enc_0.1-3
## [7] survival_2.40-1 XML_3.98-1.5 foreign_0.8-67
## [10] DBI_0.5-1 BiocParallel_1.8.1 plyr_1.8.4
## [13] stringr_1.1.0 zlibbioc_1.20.0 munsell_0.4.3
## [16] gtable_0.2.0 evaluate_0.10 memoise_1.0.0
## [19] labeling_0.3 latticeExtra_0.6-28 geneplotter_1.52.0
## [22] AnnotationDbi_1.36.0 highr_0.6 htmlTable_1.8
## [25] Rcpp_0.12.8 acepack_1.4.1 xtable_1.8-2
## [28] scales_0.4.1 backports_1.0.4 checkmate_1.8.2
## [31] Hmisc_4.0-2 annotate_1.52.1 XVector_0.14.0
## [34] gridExtra_2.2.1 digest_0.6.11 stringi_1.1.2
## [37] grid_3.3.2 tools_3.3.2 bitops_1.0-6
## [40] magrittr_1.5 lazyeval_0.2.0 RCurl_1.95-4.8
## [43] tibble_1.2 RSQLite_1.1-2 Formula_1.2-1
## [46] cluster_2.0.5 Matrix_1.2-7.1 data.table_1.10.0
## [49] assertthat_0.1 rpart_4.1-10 nnet_7.3-12
Upvotes: 2
Views: 421
Reputation: 20746
Is this due to the different operating systems (also my R version is slightly off on the two OSs), or am I missing some sort of formatting packages?
Not in this case. However, good insight here to check this.
I noticed the Rstudio sessionInfo() command shows a yaml package that was loaded by another package. I verified that it is also available on Ubuntu but it didn't get loaded there.
Sometimes remnants are left from preexisting work. A precursory glance indicates that markdown_0.7.7
is attached in the Ubuntu environment vs. macOS (14 vs. 15 attached packages).
Does Rstudio run a different command to generate the html file?
Yes! The main reason for the different style sheets being applied is a direct result of this. In particular, the RStudio approach generates the HTML document from Markdown via rmarkdown::render
vs. your approach that is based upon direct knitr
calls. Thus, to recreate how RStudio is generating the HTML document, use:
Rscript -e "rmarkdown::render('${OUTFILE}.md', 'html_document', output_file = '${OUTFILE}.html')"
The above assumes that you have set no internal yml
configuration that dictates the output. e.g. no output: html_document
.
If you have, you probably could get away with:
Rscript -e "rmarkdown::render('${OUTFILE}.md')"
Upvotes: 4