Skip to content

Instantly share code, notes, and snippets.

@b-rodrigues
Last active December 17, 2021 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b-rodrigues/843011bb863f27a8fe7f299e13eb4491 to your computer and use it in GitHub Desktop.
Save b-rodrigues/843011bb863f27a8fe7f299e13eb4491 to your computer and use it in GitHub Desktop.
---
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