r-markdown

R: output a pivot-like table with subtotals

风流意气都作罢 提交于 2019-12-05 10:48:15
I'm trying to make a cross tabulation in R, and having its output resemble as much as possible what I'd get in an Excel pivot table. The objective is to replace a report made manually with Excel and Word with one automated with R Markdown; data wrangling and charts have been already taken care of but some tables are missing. So, given this code: set.seed(2) df<-data.frame("ministry"=paste("ministry ",sample(1:3,20,replace=T)),"department"=paste("department ",sample(1:3,20,replace=T)),"program"=paste("program ",sample(letters[1:20],20,replace=F)),"budget"=runif(20)*1e6) library(tables) library

Automatically number sections in RMarkdown

核能气质少年 提交于 2019-12-05 10:21:28
问题 I am trying to create a report in R markdown that has sections ordered Section 1 Header 1.1 sub section 1 1.2 sub section 3 Section 2 Header 2.1 2.2 sub section 2.2.1 another sub section Is there a way get R markdown to generate an ordered list like this? 回答1: Add the option number_sections: true to your YAML header: --- title: "My Report" output: html_document: number_sections: true --- # Main Section ## 2nd Level ### 3rd Level And voilá, your sections are numbered: 来源: https://stackoverflow

Render code for google chart in rmarkdown Rmd

喜欢而已 提交于 2019-12-05 10:16:37
Google has some nifty charts. I'm sure there's nice R wrapper packages to do what I want but I want to learn how to include a google chart myself as it will likely be more flexible than an R wrapper for including a google chart. Below is an .Rmd that has a donut function to produce the donut from Google chart gallery . The function outputs a code as expected seen below but to actually knit this results in the following pandoc conversion error. How do I include the google chart code properly in an Rmarkdown .Rmd file? Error output file: ttt.knit.md pandoc.exe: Could not fetch https://www

RMarkdown accessing parameter from bash chunk

别说谁变了你拦得住时间么 提交于 2019-12-05 09:48:30
I created an RMarkdown file file.Rmd with parameters. I know how to access parameters within a r chunk but not from a bash chunk If there is absolutely no way to do so, I will write the parameters in a file through r chunk and then read it from bash chunk ... --- output: html_document params: myParam1: label: "Choose 1st parameter" value: 20 input: slider min: 0 max: 100 myParam2: label: "Choose 2nd parameter" value: "Hello" input: text --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ```{r, echo=FALSE} print(paste("1st parameter :",params$myParam1)) print(paste("2nd

How to properly number headings in Word from a RMarkdown document

倖福魔咒の 提交于 2019-12-05 09:45:20
I'm creating a RMarkdown document that I want to export in MS Word with RStudio. I want a table of contents and numbered headings. Here is my sample markdown document: --- title: "Test" author: "Ben" date: "`r format(Sys.time(), '%d/%m/%Y')`" output: word_document: toc: yes --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` # Header 1 ## Header 2 ## Header 2 ### Header 3 This produces the following word doc: That's a good start. Following this tutorial , I edited the heading styles of the output document in Word to make them numbered. I also changed the Table of contents

RMarkdown / pandoc fails to knit Pdf with latex color commands

对着背影说爱祢 提交于 2019-12-05 07:21:21
问题 Mac Os: 10.11.6 R version: 3.3.1 MacTex: 2016 / TexLive: 6.2.2 RMarkdown: 1.0.9014 Knitr: 1.14 Pandoc: 1.17 RMarkdown fails to knit PDF when latex commands such as: \textcolor{blue}{Character String} are present in the .rmd file. The error output is: /usr/local/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template ~/R/3.3/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style

R notebook: opts_chunk has no effect

我只是一个虾纸丫 提交于 2019-12-05 06:43:26
I'm working on my first R notebook which works pretty well, except for one issue. I'd like to be the numbers that I output inline with `r realbignumber` to have commas as separator and max 2 decimal points: 123,456,789.12 In order to achieve this, I added a chunk at the beginning of my document, which contains... ```{r setup} knitr::opts_chunk$set(echo = FALSE, warning=FALSE, cache = TRUE, message = FALSE) knitr::opts_chunk$set(inline = function(x){if(!is.numeric(x)){x}else{prettyNum(round(x,1), big.mark = ",")}}) options(scipen=999) ``` The suppression of scientific numbers works like a charm

Q: Create leaflet map in for loop in rmarkdown html

Deadly 提交于 2019-12-05 06:39:47
I am trying to create a leaflet map with a for-loop in an rmarkdown file. Here is a minimal example: --- title: "Test" output: html_document --- ```{r quakes, echo=F} data(quakes) library(leaflet) for (i in c(10:20)) { leaflet(data = quakes[1:5 & quakes$stations == i,]) %>% addTiles() %>% addMarkers(~long, ~lat, popup = ~as.character(mag)) } ``` I do not get any output with this code. When running the leaflet command alone (and replacing the i with an integer) it works. I also tried the print command, but that didn't work either. Any idea how I can do this? you have complicated it a little bit

How to extend the renderTable width in Shiny flexdashboard

☆樱花仙子☆ 提交于 2019-12-05 05:42:45
I have the following self containing Shiny-Flexdashboard: --- title: "FOO" runtime: shiny output: flexdashboard::flex_dashboard: vertical_layout: scroll orientation: rows theme: default --- ```{r setup, include=FALSE} library(flexdashboard) library(tidyverse) ``` Rows ------------------------------------- ### Statistical Test Summary ```{r stat_test_table} mainPanel( renderTable( { dat <- df <- structure(list(`Sample name` = structure(1:3, .Label = c("Sample1", "Sample2", "Sample3"), class = "factor"), `FDR correction (mean)` = c(5.93070861978308e-15, 6.88632524238004e-13, 3.28339498763286e-16

References page truncated in RMarkdown ioslides presentation

落花浮王杯 提交于 2019-12-05 05:39:57
I prepare a ioslides presentation in RMarkdown via RStudio. As the presentation contains a lot of references they are truncated: With {.allowframebraks} there seems to be a quick solution for beamer presentations as this answer shows. Is there one for ioslides, too? This isn't exactly what you're asking for, but it might be the best you can do. Insert the following inline CSS at the end of your document (i.e. just before where the references will be inserted), and instead of truncating them, it will add a scroll bar (the first part) and suppress the page number (the second part). <style>