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.
When you knit an Rmd document the code gets executed in a clean environment other than the one you are currently working on so the mentioned data frame doesn't exist there and any non-base function has been loaded. You need to include the necessary code to import the data frame into memory and to load packages, in your Rmd document itself, for example, if the data frame comes from a csv file you would include something like this: your_data_frame <- read.csv("path_to_file.csv")and to load the tidyverse you wood need to add library(tidyverse)
bookings_df is loaded into the environment via the hotel_bookings.csv file. I can view a tibble of the columns if I comment out any of the code lines relating to 'stays_weekend_in_nights'
It doesn't do it directly in the RM but i have the same issue when I try and execute the code directly in the console. Based on @andresrcs' comment I'll add it to the RM, but i'm pretty sure that's not the issue.
I only put the code in the RM, trying to post the comment here, after I was getting the error running in a Rstuido script.
In any case in RM when I comment out the 'sum' line II get the tibble from the 'head()' showing the column name. Everything seems OK until I try and execute the 'sum' line. I can see the column in the tibble in RM, so I'm sure the column is available, that's the frustrating part. I can see it, but after the %>% call to run the sum is when I get the error. This is why I think I have an environment issue excluding RM.
Be patient , thanks.
To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
It is not clear what you are trying to do but you are mixing dplyr and base R syntax in a way that is impossible.
Is this what you are trying to achieve?
It does with the Iris data, but not in my original script.
More studying on dplyr, and I know what to watch out for. Thanks
How did you print the total?
I'm now getting a different error, but I've made so many edits I need to start fresh.
Problem while computing total = sum(stays_weekend_in_nights, na.rm = TRUE).
Caused by error in mask$eval_all_summarise():
! object 'stays_weekend_in_nights' not found