I started using the below code in my scripts to clear the environment before every run.
# Clear environment
rm(list = ls())
This works great in R scripts. However, when I Knit the below RMarkdown document in RStudio, my environment variables are not clearing.
To test, run myNewVariable <- 2
in the console, then Knit the below RMarkdown document. When I do this, myNewVariable still exists. Is this normal?
---
title: "Clear Environment"
author: "John"
date: "August 17, 2015"
output: html_document
---
```{r}
# Clear environment
rm(list = ls())
```