I'm just learning programming so I'd appreciate some help with a solution to my problem but also a source to help better understand the underlying issue. I'm sure I have an environment issue, and in second code chunk I've tried to address it, based on Karlijn Willems' article https://www.datacamp.com/tutorial/pipe-r-tutorial, but still get the same error.
I'm also getting an environment error when I try and knit the R markdown document: "Quitting from lines 10-17 (child_stays_markdown.Rmd) Error in eval(expr, envir, enclos) : object 'stays_weekend_in_nights' not found"
Insights on how to get the R markdown document format passed an error in a code chunk moved also appreciated.
Thanks
title: "hotel_bookings_pipe"
output: html_document
date: "2022-11-03"
trim1_df <- bookings_df %>%
select(children, stays_in_weekend_nights) %>%
subset(children > 0) %>%
total <- sum(stays_weekend_in_nights, na.rm = TRUE)
total
head(trim1_df)
## Error: object 'stays_weekend_in_nights' not found
```{r}
env <- environment()
trim1_df <- bookings_df %>%
select(children, stays_in_weekend_nights, envir = env) %>%
subset(children > 0) %>%
total <- sum(stays_weekend_in_nights, na.rm = TRUE)
total
head(trim1_df)
## Error: object 'stays_weekend_in_nights' not found