knitr

Insert HTML tables in knitr documents in R

末鹿安然 提交于 2019-12-08 17:25:36
I have a number of different HTML files that contain formatted tables which I would like to combine in a knitr report in R. Unfortunately, I have some issues in loading the HTML files into R and including the tables in my knitr report. The HTML files were created using the "save as htm" function in MS Excel and the stargazer library. They display flawlessly in any browser. My code is: ```{r, echo=FALSE, return='asis'} library(XML) overview.html <- htmlParse("overview.htm") print(overview.html) ``` When printing "overview html" in the console I get the correct html code. However, when kniting

How to move the bibliography in markdown/pandoc

时间秒杀一切 提交于 2019-12-08 16:21:24
问题 I'm currently writing my bachelor thesis and my instructor wants me to put my appendix after the bibliography but markdown/pandoc puts the references at the end by default. I read the instructions at http://yihui.name/knitr/demo/pandoc/ and tried to use the include-after-body=FILE command to put a separate .rmd file at the end of the document My code looks like this: ```{r, echo=FALSE, warning=FALSE, message=FALSE} library(knitr) pandoc('thesis.rmd', format="latex") ``` and for the options: <

R dummies package weird column names when knitted via .Rmd

▼魔方 西西 提交于 2019-12-08 14:44:42
I've just noticed a very weird behavior in the dummies package of R when knitted in .Rmd . Here's the reproducible example. --- title: "Dummies Package Behavior" author: "Kim" date: '`r Sys.Date()`' output: pdf_document: toc: yes toc_depth: '3' --- Load the libraries ```{r} library(tidyverse) library(dummies) ``` Main data wrangling ```{r} df <- data_frame(year = c(2016, 2017, 2018)) temp <- dummy(df$year) temp <- as_data_frame(temp) df <- bind_cols(df, temp) ``` View output ```{r} df ``` What I'm expecting to see when I view the df are nice 0-1 columns of year2016 , year2017 , and year2018 ,

R dummies package weird column names when knitted via .Rmd

隐身守侯 提交于 2019-12-08 08:34:41
问题 I've just noticed a very weird behavior in the dummies package of R when knitted in .Rmd . Here's the reproducible example. --- title: "Dummies Package Behavior" author: "Kim" date: '`r Sys.Date()`' output: pdf_document: toc: yes toc_depth: '3' --- Load the libraries ```{r} library(tidyverse) library(dummies) ``` Main data wrangling ```{r} df <- data_frame(year = c(2016, 2017, 2018)) temp <- dummy(df$year) temp <- as_data_frame(temp) df <- bind_cols(df, temp) ``` View output ```{r} df ```

Using apaTables or apaStyles packages with knitr

若如初见. 提交于 2019-12-08 08:03:45
问题 Problem Social scientists format tables and documents with APA style. There are packages like stargazer and xtable (here is an extensive list) that provide clean table formatting for those using latex and knitr . However , these packages do not conform to APA style rules in all cases. Building and formatting tables from scratch is time consuming. Fortunately, there are two R packages for creating tables and documents compliant with APA style guidelines: apaStyle and apaTables . Unfortunately,

knitr::include_graphics in bookdown, is not rendering the image

百般思念 提交于 2019-12-08 07:34:06
问题 I am trying to include a .png file in a file that I am rendering using bookdown. knitr::include_graphics() should be the way to go. The code: ```{r fig1, fig.cap='My Caption', echo=FALSE, message=FALSE, warning=FALSE} knitr::include_graphics("./Figures/My Figure.png") ``` In the .Rmd file, I can run my r block, and it renders the image below. So, the path should be correct. However, when I knit the chapter, or render the entire book, the figure is not rendered. Could it be that some of my

How to set the width/height of a plot in knitr?

被刻印的时光 ゝ 提交于 2019-12-08 07:33:49
问题 I have some R code, where I open a png() device to write a plot to, but I want this plot to also show in the PDF that I generate from the code using Knit-R. So far, I have done this: png(file="filename.png", width=5, height=5, units="in", res=300) dev.control(displaylist="enable") # Do the plotting here dev.off() This creates the filename.png with the plot in it, and it will also show me the plot in the Knit-R generated PDF, because of the dev.control() call. However, the size of the plot in

Insert HTML tables in knitr documents in R

邮差的信 提交于 2019-12-08 07:07:12
问题 I have a number of different HTML files that contain formatted tables which I would like to combine in a knitr report in R. Unfortunately, I have some issues in loading the HTML files into R and including the tables in my knitr report. The HTML files were created using the "save as htm" function in MS Excel and the stargazer library. They display flawlessly in any browser. My code is: ```{r, echo=FALSE, return='asis'} library(XML) overview.html <- htmlParse("overview.htm") print(overview.html

How to knit_print flextable with loop in a rmd file

左心房为你撑大大i 提交于 2019-12-08 06:58:22
问题 I am trying to produce mutltiple tables using the flextable and kable packages. When I want to output some table iteratively, I found knit_print of flextable is not working in loop. Below is a minimal example: --- output: word_document --- ```{r} library(flextable) library(knitr) ``` ```{r} data(cars) speed<-unique(cars$speed) for (v in 1:length(speed)) { carspd<-cars[which(cars$speed==speed[v]),] tb<-regulartable(carspd) knit_print(tb) } knit_print(tb) ``` Just the last knit_print can print

Rotate stargazer table in knitr

此生再无相见时 提交于 2019-12-08 06:44:37
问题 I am using knitr to write a .Rnw file and the stargazer packages to build tables for regression outputs. For the most part it is working quite well but I would like to rotate a table 90 degrees like I would easily be able to do in LaTeX using \usepackage{sidewaystable} outside of .Rnw \documentclass{article} \begin{document} <<table1, echo=FALSE, message=F, warning=F, results="asis">>= library(stargazer) lm1 <- lm(mpg ~ wt, data = mtcars) lm2 <- lm(mpg ~ hp, data = mtcars) lm3 <- lm(mpg ~ cyl