Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Use of rm(list=ls()) at Start of Job


View products that this article applies to.

Question

Is rm(list=ls()) at the beginning of a R job that's run in batch useful or otherwise a best practice?

↑ Back to the top


Answer

Yes, it can be useful to start off your batch script with the command 'rm(list=ls())' just to make sure that you have a clean R environment before submitting the batch job. For example, you may have users that have their own .Rprofile files with a sequence of commands in them that create some R objects on startup of R. In that case it may be useful, to erase any existing R objects before running the R code for the batch job.

For example, here is pseudocode to do this:

x <- ls() 
if (x is not empty) { 
rm(list=ls() 
}

Yes, you can certainly run code like this after startup to remove existing R objects from the user workspace. 

↑ Back to the top


Keywords: kb

↑ Back to the top

Article Info
Article ID : 3103289
Revision : 1
Created on : 1/7/2017
Published on : 10/26/2015
Exists online : False
Views : 73