I continue to get the following error when I work with any dataset that isn't already part of an R package (for example gapminder). I've imported the file as a csv, created the object and it appears in my global environment, but when I go to knit it continuously says. I've tried clearing the environment and other work arounds to no avail...
Error in eval(lhs, parent, parent) : object 'women_research' not found Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> %>% -> eval -> eval Execution halted.
women_research %>%
group_by(field) %>%
summarise(mean_percent_women = mean(percent_women)) -> percent_women_by_field
ggplot(data = percent_women_by_field) +
aes(x = mean_percent_women*100, y = field) +
theme(panel.grid = element_blank(),
panel.background = element_rect("cornsilk"),
text = element_text(family = "Courier"),
axis.ticks = element_blank(),
axis.text.y = element_blank()) +
theme(legend.position = "right",
legend.key = element_rect("transparent")) +
scale_x_continuous(limits = c(10,50)) +
labs(x = "% by sector", y = NULL, title = "Arcoss the world, what are the major sectors women work in?", subtitle = "Average percent of women by field of 39 leading economies", caption = "viz by Rich with ggplot, source: TidyTuesday") +
scale_color_brewer(palette = "Set1") +
geom_point(aes(color = field)) +
aes(size = mean_percent_women) +
guides(size = FALSE)
Are these step to load the women_research dataset part of your Rmarkdon file?
Rmarkdown file will be rendered in its own process and environment. Everything must be available.
It is like me if I want to reproduce your example. I can't because I don't have women_research dataset on my side. I only get your code but I don't know the libraries you are using (I can guess, rmarkdown won't), and I don't know from where women_research comes from ! So your code will error on my side too.
Having the data available in your global environment is not enough, you need to load it inside you Rmd document so that it is available to the R environment during rendering.
Please also post the full reproducible example to help us help you. As your issue is with knitting a Rmd file, you should share the example as a Rmd file too.
cderv, thank you for the feedback. First off, yes, the steps to load the dataset are part of the markdown. Also, here is the link to the dataset, it was from tidytuesday.
Also, here is the Rmd. code chunk where I use the data. The first step was a manipulation...
The knit button indeed uses a sort of separate background process. It is indeed annoying that therefore, variables from the global environment cannot be used.
As a beginner it seemed inconsistent to me that the code block runs without error, but a rather cryptic error message is thrown when trying to knit.
The simple solution is to render the document via console. You need to add some more options to choose format and such.
I think this for reproducibility. Rmarkdown file is best used if built as a reproducible document that contains the analysis. If the document depends on other variable from the Global environment, it will not be able to be rendered without knowing how to create the missing variable.
Also, this can be source of error to render from console when you have lots of object in the global environment. it requires extra care. We had some weird behavior due to that sometimes.