Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
---
title: "Results of example survey"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
#rmarkdown::render("test.Rmd")
```
# Section
```{r, include = FALSE}
library(tidyverse)
library(lubridate)
library(dplyr)
library(readr)
survey_data <- read_csv(
"https://gist.githubusercontent.com/b-rodrigues/0c2249dec5a9c9477e0d1ad9964a1340/raw/873bcc7532b8bad613235f029884df1d0b947c90/survey_example.csv"
)
questions <- colnames(survey_data)
codes <- paste0("var_", seq(1, 4))
lookup <- bind_cols("codes" = codes, "questions" = questions)
colnames(survey_data) <- codes
create_table <- function(dataset, var){
dataset %>%
count(!!var) %>%
knitr::kable()
}
return_section <- function(var){
a <- knitr::knit_expand(text = c("## {{question}}", create_table(survey_data, var)),
question = lookup$questions[grepl(quo_name(var), lookup$codes)])
cat(a, sep = "\n")
}
sym_codes <- map(codes, sym)
```
```{r, results="asis"}
walk(sym_codes, return_section)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment