Last active
December 17, 2021 13:53
-
-
Save b-rodrigues/843011bb863f27a8fe7f299e13eb4491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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