I am trying to knit an parameterized R markdown file using two child .Rmd files. For some reason with the second child .Rmd file, I get the following error
Error in readLines(if (is.character(input2)) { :
object 'input2' not found
I don't have a deep understanding of what is happening for within knitr::knit()
which I suspect is giving the error. Any insight would be appreciated!
The premise is that I am trying to create a dynamic markdown file where the child document cat_var2.Rmd
creates a table and plot for each categorical variable selected in a data set. The params$data
object can be any type of data set containing factor
or character
type columns.
I've included the code below:
parent.Rmd
---
title: "parent document"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r mydata, include=FALSE}
my_data <- iris
```
```{r cat_log, include=FALSE}
cat_log <- TRUE #default
if (length(names(dplyr::select_if(my_data, funs(is.character(.) | is.factor(.))))) < 1) {
cat_log <- FALSE
}
```
`r if (cat_log) {"# Categorical Variables"}`
```{r catgorical_vars-md, include=FALSE, message=FALSE}
out_catgorical <- NULL
for (v in names(dplyr::select_if(my_data, funs(is.character(.) | is.factor(.))))) {
out_catgorical <- c(out_catgorical, knitr::knit_expand('child2.Rmd'))
}
```
`r if (cat_log) paste(knit(text=out_catgorical), collapse = '\n')`
child2.Rmd
## Variable: {{v}}
```{r table-{{v}}, echo=FALSE}
var_cat <- '{{v}}'
my_table <- table(my_data[var_cat]) #make a table
```