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

Is rm(list=ls()) at the beginning of a R job that's run in batch useful or otherwise a best practice?
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) { 

Yes, you can certainly run code like this after startup to remove existing R objects from the user workspace. 
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Article ID: 3103289 - Last Review: 10/26/2015 08:22:00 - Revision: 1.0

Revolution Analytics

  • KB3103289