knitr

Use a variable name with spaces inline in R markdown

纵饮孤独 提交于 2020-07-15 07:34:11
问题 How can I include inline R code that refers to a variable name that contains spaces or other unusual characters (actual use-case is Pr(>F) )? Backticks are the solution in plain R script, but they don't seem to work when the code is inline in a markdown doc. Here's an example: ```{r} df <- data.frame(mydata= 1:10, yourdata = 20:29) names(df) <- c("your data", "my data") ``` The first five values of your data are `r df$`your data`[1:5]` Which when knitted gives: Quitting from lines 7-9 (test

kable: Vertical alignment does not work with pdf output

时光毁灭记忆、已成空白 提交于 2020-07-09 06:14:59
问题 I am trying to produce a large table in pdf mixing text and figures using kable . I am trying to align every row to the top. I made an example using a figure test.jpg located inside the working directory. I am using the version 1.22 of knitr . --- output: pdf_document --- ```{r} table <- data.frame( col1 = "test", col2 = "![test](test.jpg){width=150px}") knitr::kable(table) ``` It behaves correctly and aligns the figure and the text to the top if I knit it in html but it aligns the figure and

Passing fig.width into a taglist

随声附和 提交于 2020-07-07 22:40:21
问题 The rgl widget responds to the figure width and height specified in knitr code chunk options, e.g. ```{r fig.width=2, fig.height=2} library(rgl); example(plot3d); rglwidget() ``` gives a small plot (192 x 192 on my screen). However, if I put rglwidget() in a browsable tagList, it doesn't: ```{r fig.width=2, fig.height=2} library(rgl); example(plot3d) library(htmltools) browsable(tagList(rglwidget(), rglwidget())) ``` This gives two full size widgets. Debugging the Javascript shows that each

Passing fig.width into a taglist

徘徊边缘 提交于 2020-07-07 22:39:36
问题 The rgl widget responds to the figure width and height specified in knitr code chunk options, e.g. ```{r fig.width=2, fig.height=2} library(rgl); example(plot3d); rglwidget() ``` gives a small plot (192 x 192 on my screen). However, if I put rglwidget() in a browsable tagList, it doesn't: ```{r fig.width=2, fig.height=2} library(rgl); example(plot3d) library(htmltools) browsable(tagList(rglwidget(), rglwidget())) ``` This gives two full size widgets. Debugging the Javascript shows that each

Passing fig.width into a taglist

守給你的承諾、 提交于 2020-07-07 22:38:03
问题 The rgl widget responds to the figure width and height specified in knitr code chunk options, e.g. ```{r fig.width=2, fig.height=2} library(rgl); example(plot3d); rglwidget() ``` gives a small plot (192 x 192 on my screen). However, if I put rglwidget() in a browsable tagList, it doesn't: ```{r fig.width=2, fig.height=2} library(rgl); example(plot3d) library(htmltools) browsable(tagList(rglwidget(), rglwidget())) ``` This gives two full size widgets. Debugging the Javascript shows that each

kableExtra: Dynamic add_header_above labeling

家住魔仙堡 提交于 2020-07-04 08:58:08
问题 I would like to create a pdf with rmarkdown. The PDF should contain a table. The table should have a dynamic column label. The tabhead should display the calendar week. However, the calendar week (e.g., KW29) is not displayed but the variable name "kw0". What is my error? library(knitr) library(kableExtra) library(lubridate) options(knitr.table.format = "latex") loadData <- function() {# load some data} myData<- loadData () kw0 <- paste("KW", week(Sys.Date()) - 1, sep = "") kw1 <- paste("KW",

kableExtra: Dynamic add_header_above labeling

不打扰是莪最后的温柔 提交于 2020-07-04 08:58:07
问题 I would like to create a pdf with rmarkdown. The PDF should contain a table. The table should have a dynamic column label. The tabhead should display the calendar week. However, the calendar week (e.g., KW29) is not displayed but the variable name "kw0". What is my error? library(knitr) library(kableExtra) library(lubridate) options(knitr.table.format = "latex") loadData <- function() {# load some data} myData<- loadData () kw0 <- paste("KW", week(Sys.Date()) - 1, sep = "") kw1 <- paste("KW",

HTML code inside of a R-markdown block for a single line

吃可爱长大的小学妹 提交于 2020-06-16 13:03:40
问题 I have an R-markdown document in a for loop (testing various kinds of models), and I would like to set them off with HTML Headers, as it is otherwise hard to find the models I am looking for. There is the "asis" option, but that turns off formatting for the entire block, which is not what I want. I have tried a few things I found here, but nothing really works. Here is my code: --- title: "Untitled" author: "Mike Wise - 25 Jul 2014" date: "November 2, 2015" output: html_document --- Test ```

HTML code inside of a R-markdown block for a single line

╄→尐↘猪︶ㄣ 提交于 2020-06-16 13:00:59
问题 I have an R-markdown document in a for loop (testing various kinds of models), and I would like to set them off with HTML Headers, as it is otherwise hard to find the models I am looking for. There is the "asis" option, but that turns off formatting for the entire block, which is not what I want. I have tried a few things I found here, but nothing really works. Here is my code: --- title: "Untitled" author: "Mike Wise - 25 Jul 2014" date: "November 2, 2015" output: html_document --- Test ```

How to show formatted R output with results='asis' in rmarkdown

 ̄綄美尐妖づ 提交于 2020-06-15 06:27:27
问题 Is there a way of showing formatter R output in rmarkdown/knitr when using results = 'asis'? An example would be the following function: myfun <- function() { cat("hello!\n") cat(c("one" = 1, "two" = 2)) } Then, this chunk will print the second cat on a new row: ```{r} myfun() ``` But this will ignore the formatting from myfun : ```{r, results = "asis"} myfun() ``` Is there a way of keeping results='asis' but at the same time keep the output of myfun formatted as intended? 回答1: You can use