This Blog entry is from the Getting Started in R section in Learn R.
Navigate to the end of the script and create a new line:
Type the detach() function as:
Run the line of script to the console:
The package has now been removed from the R session and the scrpt is essentially, tidying itself up.