I'm trying to create a very simple R markdown and cannot get through sorting the environments. But before I even get to knitting the document I have a problem when running the operative code chunk. I read a file into input_df, filter it and put the result in output_df. It appears in my global environment when I run the chunk. Then I have View(output_df) as the next line in the chunk. It works. I see output_df.
Next line is to write output_df using the write_xlsx function. Error in is.data.frame(x) : object 'ouput_df' not found. Why can I see output_df in my global environment and why did the program see it in the immediately preceding line of code, but not in the code beginning with write_xlsx?
Here's the code for the example:
---
title: "attempt to create a reproduceable example"
author: "Don Fogel"
date: "`r Sys.Date()`"
output:
prettydoc::html_pretty:
theme: architect
highlight: github
toc: true
editor_options:
chunk_output_type: console
params:
inspector_name: "Joe"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(cache = TRUE, warning = TRUE, message = FALSE)
library(rmarkdown)
library(tidyverse)
library(readxl)
library(writexl)
library(shiny)
```
```{r main, echo=FALSE}
input_df <- read_excel("/Users/home/Dropbox/R/test_project_2/test_data_2.xlsx")
output_df <- input_df %>%
filter(PayrollName == params$inspector_name)
View(output_file)
write_xlsx(ouput_df,"/Users/home/Dropbox/R/test_project_2/test_output_2.xlsx" )
```